Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compile and deploy React Native Android app of Release version to device.
Disclaimer: The instructions are the collective efforts from a few places online.
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did.
First off, bundle.
==================
1. cd to the project directory
2. Start the react-native packager if not started
3. Download the bundle to the asset folder:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
(Credit: https://github.com/facebook/react-native/issues/2743#issuecomment-140697340)
Note: make sure there is assets folder under android/app/src/main beforehand, and check if there is any error in the packager terminal window after curl.
Secondly, compile release version.
==================================
1. cd to {YOUR_PROJECT}/android
2. ./gradlew assembleRelease
Thirdly, sign the apk.
======================
1. To generate keystore
keytool -genkey -v -keystore my-keystore.keystore -alias name_alias -keyalg RSA -validity 10000
2. To sign an apk
jarsigner -verbose -keystore <path of my-keystore.keystore> <path of apk> alias_name
3. To zip align an apk
zipalign -f -v 4 <your.apk > <your_aligned.apk>
(Credit: http://stackoverflow.com/questions/26828372/how-to-sign-a-modded-an-apk-on-a-mac-with-apktool)
Lastly, install apk to device.
==============================
1. connect your phone to computer
2. adb install {PATH_TO_APK}
@niftylettuce

This comment has been minimized.

@thejamespinto

This comment has been minimized.

Copy link

@thejamespinto thejamespinto commented Oct 4, 2016

Instead of writing instructions, just add the command

mkdir android/app/src/main/assets

@rezof

This comment has been minimized.

Copy link

@rezof rezof commented Feb 9, 2017

when signing the the apk:

jarsigner -verbose -keystore alias_name

should be

jarsigner -verbose -keystore name_alias

@Braidio

This comment has been minimized.

Copy link

@Braidio Braidio commented Apr 12, 2017

I'm confused. Nothing here actually generates an APK. Should that be done through Android Studio ( as usual )?

@thomascoe

This comment has been minimized.

Copy link

@thomascoe thomascoe commented Apr 24, 2017

./gradlew assembleRelease generates an APK in the android/app/build/outputs/apk/ directory

@saiprasad1996

This comment has been minimized.

Copy link

@saiprasad1996 saiprasad1996 commented May 22, 2017

@marty-wang thank you for the steps in one place.. Saved my life :-)

@leonardoballand

This comment has been minimized.

Copy link

@leonardoballand leonardoballand commented Jun 19, 2017

I can't find any resource about gradle configuration (target versions, support from Android x to Android y...). Any advices? Thanks :)

@saiprasad1996

This comment has been minimized.

Copy link

@saiprasad1996 saiprasad1996 commented Jun 23, 2017

@digitalz4k you can check out build.gradle file available at "android/app/build.gradle" path. There you can find minSDK compileSDK and all the relevant information.

@Maradox-D-Krypt

This comment has been minimized.

Copy link

@Maradox-D-Krypt Maradox-D-Krypt commented Jun 28, 2017

I have successfully deploy my app to my phone and while i was browsing the app i notice some errors that needed to be fixed. I made the changes to my source code and i want those changes to be reflected to the app on my phone. How can i update my app or apk, what must i do to see these changes made on my phone? Detailed instructions would be much appreciated.

@dwivediamit

This comment has been minimized.

Copy link

@dwivediamit dwivediamit commented Aug 23, 2017

Images are not coming in android if I am installing the build.

@dwivediamit

This comment has been minimized.

Copy link

@dwivediamit dwivediamit commented Aug 23, 2017

Where I have to place image folder ??

@AnandAron

This comment has been minimized.

Copy link

@AnandAron AnandAron commented Oct 24, 2017

curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
returns "curl: (7) Failed to connect to localhost port 8081: Connection refused"
Tried with my public ip too!!

Help me to build the app
Thanks in advance

@mach-kernel

This comment has been minimized.

Copy link

@mach-kernel mach-kernel commented Oct 25, 2017

This 100% works if followed step by step. Thank you, OP.

@1fabiopereira

This comment has been minimized.

Copy link

@1fabiopereira 1fabiopereira commented Dec 11, 2017

I followed the steps above and the compilation works, but the images I used in my application were not loaded, they used relative paths, how can I correct the image problems?

@llucifer97

This comment has been minimized.

Copy link

@llucifer97 llucifer97 commented Dec 11, 2018

hey @AnandAron I am also facing same issue. Can you tell me how did you fixed that?

@llucifer97

This comment has been minimized.

Copy link

@llucifer97 llucifer97 commented Dec 11, 2018

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

use this command to download in assets folder.
this works for me

@dhash357

This comment has been minimized.

Copy link

@dhash357 dhash357 commented Jan 17, 2019

I needed to create the directory

android/app/src/main/assets

and run the above command

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

This created the file

index.android.bundle

The install of the app on my device worked from there.

@kranthijulakantiwork

This comment has been minimized.

Copy link

@kranthijulakantiwork kranthijulakantiwork commented Feb 4, 2019

  1. (in project directory) 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
    react-native run-android

Previously, I didn't need to execute this command for a release build. But now I need to execute the command. Can I know whether it is a bug or caused due to some changes by me?

@mayurbaldha

This comment has been minimized.

Copy link

@mayurbaldha mayurbaldha commented Sep 11, 2019

after generating apk through ./gradlew assembleDebug

How to start again previous react-native run-android with metro bundler to develop further ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment