By Gokhan Sari


2016-03-11 08:02:10 8 Comments

I've built my app, I can run it on my local simulator (and also on my android device within the same network by changing debug server).

However, I want to build an apk that I can send to someone without access to development server and I want them to be able to test application.

I see there is a section Using offline bundle on iOS section of the documentation. But I couldn't figure out how to accomplish same for android. Is this possible? If so, how?

UPDATE: On the answer to this question (react native android failed to load JS bundle) it is said that offline bundle can be downloaded from development server. But when I obtain the bundle from development server the image files can't be loaded.

16 comments

@Akash Golui 2019-08-03 04:14:51

If any one want to build without playstore keys then this command would be very helpful.

# react-native run-android --variant=release

After build complete you can find the apk in release build file.

@bro 2019-05-17 08:51:10

Try below, it will generate an app-debug.apk on your root/android/app/build/outputs/apk/debug folder

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

then go to android folder and run

./gradlew assembleDebug

@Phani Sai 2019-05-07 05:19:05

For latest react native versions to bundle the project

Android

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

iOS

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

@Codemaker 2019-05-06 06:53:44

Refer the react-native official documentation on Generating Signed APK

React-Native Generating Signed APK

@David Hudman 2018-11-24 00:31:11

The GUI way in Android Studio

  • Have the Android app part of the React Native app open in Android Studio (this just means opening the android folder of your react-native project with Android Studio)
  • Go to the "Build" tab at the top
  • Go down to "Build Bundle(s) / APK(s)"
  • Then select "Build APK(s)"
  • This will walk you through a process of locating your keys to sign the APK or creating your keys if you don't have them already which is all very straightforward. If you're just practicing, you can generate these keys and save them to your desktop.
  • Once that process is complete and if the build was successful, there will be a popup down below in Android Studio. Click the link within it that says "locate" (the APK)
  • That will take you to the apk file, move that over to your android device. Then navigate to that file on the Android device and install it.

@Usman Kazmi 2018-10-23 13:00:42

If you get an error involving index.android.js. This is because you are using the new React-native version (I am using 0.55.4) Just replace the "index.android.js" to "index.js"

react-native bundle --platform android --dev false --entry-file index.js   --bundle-output android/app/src/main/assets/index.android.bundle   --assets-dest android/app/src/main/res/

@Dalvtor 2019-04-28 21:15:21

This is the right answer for react-native > 0.55.0

@Ahmad Sadiq 2018-10-11 19:41:11

Using android studio to generate signed apk for react's android project is also a good and easy option , open react's android project in android studio and generate keystroke and signed apk.

@Yasin Ugurlu 2017-11-09 11:44:11

for React Native 0.49 and over

you should go to project directory on terminal and run that command

1 - mkdir android/app/src/main/assets
2 - react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

if under 0.49

  1 - mkdir android/app/src/main/assets
  2 - react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Then Use android studio to open the 'android' folder in you react native app directory, it will ask to upgrade gradle and some other stuff. go to build-> Generate signed APK and follow the instructions from there. That okey.

@SuperManEver 2017-11-11 16:42:10

thanks. it worked well in my case.

@leosok 2018-10-31 00:05:50

This is an easy way to do it if you have Android Studio installed (which will take care of using or creating the Keystore). Thanks.

@pravin 2019-02-02 18:48:58

Hey.. have a quick question.. are the above steps required ? The react native doc does not mention it anywhere..

@Yasin Ugurlu 2019-02-03 21:07:54

@pravin it is not required, it is one of the method of the generate apk.

@Abhishek Garg 2018-09-08 10:53:43

Hopefully it will help new beginners

Official doc here

If you dont have keystore than use before command else skip

Generating a signing key / Keystore file You can generate a private signing key using keytool. On Windows keytool must be run from C:\Program Files\Java\jdkx.x.x_x\bin.

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

you will get a file like my-release-key.keystore

Setting up gradle variables Place the my-release-key.keystore file under the android/app directory in your project folder. Edit the file android/gradle.properties and add the following (replace ***** with the correct keystore password, alias and key password), enableAapt2 set false is workaround , as android gradle version 3.0 problem

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****

android.enableAapt2=false

then add these app/buid.gradle (app)

below default config

signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }

and Inside Build type release { }

 signingConfig signingConfigs.release

then simply run this command in android studio terminal Below commands will automate above all answers

if windows

cd android
gradlew assembleRelease

if linux / mac

$ cd android
$ ./gradlew assembleRelease

if you got any error delete all build folder and run command

gradlew clean

than again

gradlew assembleRelease

@Aditya Singh 2016-03-11 08:25:53

You will have to create a key to sign the apk. Use below to create your key:

 keytool -genkey -v -keystore my-app-key.keystore -alias my-app-alias -keyalg RSA -keysize 2048 -validity 10000

Use a password when prompted

Once the key is generated, use it to generate the installable build:

 react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

Generate the build using gradle

 cd android && ./gradlew assembleRelease

Upload the APK to your phone. The -r flag will replace the existing app (if it exists)

adb install -r ./app/build/outputs/apk/app-release-unsigned.apk

A more detailed description is mentioned here: https://facebook.github.io/react-native/docs/signed-apk-android.html

UPDATE: Based on comments by @shashuec and @Fallen

if you get error

ENOENT: no such file or directory, open 'android/app/src/main/assets/index.android.bundle'

run mkdir android/app/src/main/assets

@guinunez 2016-06-16 13:47:52

Thanks a lot for this, it worked for me. The only issue I got was this message: "Missing required arguments: bundle-output" en the react-native-bundle part, but is solved by deleting the 2 "\" symbols

@Rushabh Bhatt 2016-07-11 12:16:47

Thank You @Aditya. It worked for me.

@technophyle 2016-08-03 20:57:30

I am amazed by the poor documentation of Facebook where they totally omitted the react-native bundle part. Thanks for your answer!

@Tabares 2016-09-09 20:40:59

I am working with windows, works with this gradlew.bat assembleRelease as well.

@developernaren 2016-11-16 15:21:59

I get this error Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES] . when I try to install the apk.

@Daniel Barde 2016-11-22 15:32:49

@developernaren were you able to find a solution?

@developernaren 2016-11-23 05:20:30

@DanielBarde I had a test build installed on my mobile before, it worked after I uninstalled that.

@Joshua Pinter 2017-03-14 03:32:56

Also getting Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]. I have uninstalled the existing app. Any solution?

@Sofiane Belhadj Kacem 2017-03-14 20:18:39

adb install -r ./app/build/outputs/apk/app-release-unsigned.apk 5663 KB/s (8971275 bytes in 1.546s) pkg: /data/local/tmp/app-release-unsigned.apk Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

@Sofiane Belhadj Kacem 2017-03-14 20:28:19

@JoshPinter were you able to find a solution?

@sfratini 2017-03-14 21:29:34

They didn't skip the bundle process...they just forgot to tell you to uncomment the lines in the gradle file! Wow...

@Joshua Pinter 2017-03-14 22:22:43

@SofianeBelhadjKacem I did, yes. Thankfully. I actually used a Signed APK file and installed that instead, which I generated from Android Studio. Here were my steps: 1) Generate React Native bundle: react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/<your-package-name>/src/main/assets/index.android.bu‌​ndle --assets-dest android/<your-package-name>/src/main/res/ 2) Generate a Signed APK file from Android Studio. 3) Install Signed APK File to USB device: adb -d install -r <path_to_signed_apk> 4) Profit!

@Sofiane Belhadj Kacem 2017-03-15 10:41:14

@Sofiane Belhadj Kacem 2017-03-15 10:56:48

How can i generate a signed APK file from Android Studio !

@shashuec 2017-03-22 15:04:30

if you get error ENOENT: no such file or directory, open 'android/app/src/main/assets/index.android.bundle' run mkdir android/app/src/main/assets

@Trip 2017-04-12 10:47:03

Yep.. none of these work. Signing from ReactNative's official website or @JoshPinter 's lovely advice. I keep getting java.lang.RuntimeException: com.facebook.react.devsupport.JSException: Could not get BatchedBridge, make sure your bundle is packaged correctly .

@Pedram 2017-09-12 22:00:01

These steps only gave me an unsigned APK, which didn't install on my phone. I've added the steps that worked for me (to generate a signed APK) as a separate answer below.

@inferus-vv 2018-04-06 13:56:05

While in new RN version there is one entry point (index.js) you need to use this flag --entry-file index.js instead of index.android.js

@Faris Rayhan 2018-04-30 10:36:20

This is awesome answer my friend...

@Sadanand 2018-05-17 04:30:59

I am getting build issues despite following these steps, the issue is in only for release build, where as debug build is fine. Error is as follows FAILURE: Build failed with an exception. * What went wrong: Failed to capture snapshot of input files for task 'bundleReleaseJsAndAssets' property '$1' during up-to-date check. > Failed to create MD5 hash for file '/Development/SourceCode/MobApp/testApp/root-state/sock'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED

@Fallen 2018-08-29 00:59:43

@aditya-singh, can you please add shashuec's comment to your answer?

@Pedram 2017-09-12 07:49:04

Following Aditya Singh's answer the generated (unsigned) apk would not install on my phone. I had to generate a signed apk using the instructions here.

The following worked for me:

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Place the my-release-key.keystore file under the android/app directory in your project folder. Then edit the file ~/.gradle/gradle.properties and add the following (replace **** with the correct keystore password, alias and key password)

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=****
MYAPP_RELEASE_KEY_PASSWORD=****

If you're using MacOS, you can store your password in the keychain using the instructions here instead of storing it in plaintext.

Then edit app/build.gradle and ensure the following are there (the sections with signingConfigs signingConfig may need to be added) :

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

Then run the command cd android && ./gradlew assembleRelease ,

For Windows 'cd android' and then run gradlew assembleRelease command , and find your signed apk under android/app/build/outputs/apk/app-release.apk

@Gokhan Sari 2017-09-13 02:04:50

This is the most up-to-date and accurate answer. Thanks.

@Balasubramanian 2017-10-06 17:10:29

app-release.apk is not installing. what would be the issue?

@Italo Rodrigo 2018-01-04 01:01:37

I create the apk, upload to google play, but it not working... some hint?

@DHLopez 2018-02-15 05:44:07

I can't find the android/app folder, where is this located?

@Pedram 2018-02-26 21:28:33

@DHLopez it should be in your project folder root

@DHLopez 2018-02-27 13:13:27

Thanks, it wasn't, but I found it was because I am using expo for testing, and the create native app npm has a different structure, so for future reference, if anyone gets this problem, just eject your project and then you get those folders, funny how the tutorial tells you to use npm to create the app, and then talks about a structure that doesn't exist when you use it

@Niklas Rosencrantz 2018-03-16 06:15:02

@DHLopez Thanks for answering my question :-) softwareengineering.stackexchange.com/questions/367683/…

@Neurion 2018-07-03 02:02:57

Thanks @DHLopez. For completeness, here's the docs on ejecting

@strange_developer 2019-04-08 08:13:10

On Windows, you may need to open a command line as administrator to run this command inside the JDK folder due to restriction of permissions for creating the keystore file.

@sumit kumar pradhan 2019-08-07 03:56:05

check this simple example to generate apk file : React Native Generate Release APK through Windows Command Prompt Android

@Joshua Pinter 2017-03-14 22:48:50

If you get Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES].

I tried using @Aditya's method of generating an unsigned APK file and installing that, but when I went to install it on my Android tablet, it gave me an error of Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES].

I imagine this is because the APK file wasn't signed and the tablet was not happy with this. So, after generating the React Native bundle file I was able to generate a signed APK file, as normal, via Android Studio.

By the way, our app is a fully functioning Android app that already exists in the Play Store and we are just adding React Native to it in bite-sized pieces, because it's awesome.

So to summarize, here were my steps:

1) Generate React Native bundle:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/<your-package-name>/src/main/assets/index.android.bu‌​ndle --assets-dest android/<your-package-name>/src/main/res/ 

2) Generate a Signed APK file from Android Studio.

3) Install Signed APK File to USB device:

adb -d install -r <path_to_signed_apk> 

The -d flag just tells adb to install on the usb device attached, in the event that you have an emulator running as well. If you want to install on whatever an emulator, drop the -d flag.

4) Profit!

@Sidharth Taneja 2017-10-23 07:13:30

Go to project directory and run the command:

cd android && ./gradlew assembleRelease

@Gokhan Sari 2017-10-23 14:06:34

This will generate an unsigned apk if you didn't do required configuration (like Pedram told).

@Sidharth Taneja 2017-10-25 12:56:04

It will create debug, release and unsigned apk in generated folder. My intention was to share release apk.

@Raman Bhasker 2017-08-08 11:58:03

I have another solution:- Generating a signing key You can generate a private signing key using keytool. On Windows keytool must be run from C:\Program Files\Java\jdkx.x.x_x\bin.

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Place the my-release-key.keystore file under the android/app directory in your project folder.

Edit the file android/app/build.gradle in your project folder and add the signing config,

android {
....
signingConfigs { 
  release { 

      storeFile file('my-release-key.keystore') 
      storePassword 'yourpassword' 
      keyAlias 'my-key-alias' 
      keyPassword 'yourpassword' 

  } 
}}}


buildTypes {release {signingConfig signingConfigs.release}}

and run

gradlew assembleRelease

This will give you two files at android\app\build\outputs\apk app-release.apk and app-release-unsigned.apk now install the app-release.apk in your android device.

@DHLopez 2018-02-15 05:46:39

Where is the android\app folder? I don't see it under my project (I only see node_modules, and inside of it, there's no android/app)

@fxbayuanggara 2019-06-10 21:32:00

@DHLopez you have to use the pure React Native project to have access to the android folder. If you're using Expo, then you have to detach the Expo project using expo eject.

@Ahmed Ashraf 2016-12-29 15:25:26

Run this command:

react-native run-android --variant=release

Note that --variant=release is only available if you've set up signing with cd android && ./gradlew assembleRelease.

@jasan 2017-05-20 10:11:51

I keep getting error: installRelease not found

@Ahmed Ashraf 2017-05-21 10:57:13

@jasan I found another issue like yours here : github.com/facebook/react-native/issues/11586 This may fix the issue: cd android && ./gradlew installRelease

@ThomasReggi 2017-08-03 17:48:12

I tried cd android && ./gradlew installRelease and got this error Task 'assembleRelease.' not found in root project 'project'. Some candidates are: 'assembleRelease'.

@Ahmed Ashraf 2017-08-06 09:39:32

Yes, You have to generate the Keystore file. and edit the gradle file.Follow those instructions to fix this issue. facebook.github.io/react-native/docs/signed-apk-android.html

@Mike Axle 2017-02-14 16:52:17

You should just use android studio for this process. It is just simpler. But first run this command in your react native app directory:

react-native bundle --platform android --dev false --entry-file index.android.js   --bundle-output android/app/src/main/assets/index.android.bundle   --assets-dest android/app/src/main/res/

Then Use android studio to open the 'android' folder in you react native app directory, it will ask to upgrade gradle and some other stuff. go to build-> Generate signed APK and follow the instructions from there. It's really straight forward.

@WiRa 2017-05-12 08:57:01

I also use Android Studio and Xcode to build release versions for my React Native apps... but the android generation could be done with a script as described by @Aditya Singh

@onmyway133 2018-09-01 22:03:53

This is no longer needed proandroiddev.com/…

Related Questions

Sponsored Content

11 Answered Questions

[SOLVED] Build and Install unsigned apk on device without the development server?

3 Answered Questions

[SOLVED] react-native compiled apk wont run on device

  • 2016-07-27 13:08:53
  • Evgheny Kalkutin
  • 6858 View
  • 7 Score
  • 3 Answer
  • Tags:   android react-native

23 Answered Questions

[SOLVED] Android failed to load JS bundle

0 Answered Questions

Build unsigned debug apk to run without the development server with react-native 0.55?

2 Answered Questions

[SOLVED] react native: Install dowloaded apk

2 Answered Questions

0 Answered Questions

1 Answered Questions

2 Answered Questions

[SOLVED] React native blank screen after generating APK

Sponsored Content