By kAy_4337270


2016-02-09 04:33:37 8 Comments

As I am new in react-native so if there is anything wrong in steps let me know.

I have build a react native android app using the command as per documentation

react-native android

while running on device the following command was used

react-native run-android

which gives me the output of 2 apk files in my projectfolder/android/app/build/outputs/apk

enter image description here

now when I use to install this apk after the installation it ask for an development server to connect to bundle the JS. But my requirement is that the user doesn't have to struggle with the development server just he needs to install the apk and everything is done.

Have gone through some stackoverflow Questions but not helpful to build unsigned apk which doesn't require development server.

Can you guys help me finding the way that how to build and unsigned apk in react native?

8 comments

@m4r00p 2017-02-10 09:33:56

Please follow those steps.

Bundle your js:

if you have index.android.js in project root then run

react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

if you have index.js in project root then run

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

Create debug apk:

cd android/
./gradlew assembleDebug

Then You can find your apk here:

cd app/build/outputs/apk/

@Simon Forsberg 2017-08-03 18:59:26

And if doing this gives me a big red screen when I start the app? (Note: I am running this directly after ejecting)

@Zuha Karim 2018-04-20 05:30:59

@SimonForsberg Did you find any solution? because i'm stuck at the same point.

@Kalanka 2018-04-25 06:22:11

@m4r00p: i did as you mentioned,but it gives me this error Command bundle unrecognized. Make sure that you have run npm install and that you are inside a react-native project. note i am building the app in jenkins

@d.bayo 2018-04-25 18:08:34

@SimonForsberg if you are using react ^0.5, change the entry point to index.js instead of App.js or index.android.js, react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android‌​.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

@Vishal Chhodwani 2018-08-10 10:36:28

Not working, this commands building an apk but that apk is not running without packager server.

@Anuj 2018-10-09 12:16:59

it is build apk but not able to install it

@rams 2018-10-17 14:07:14

after two steps when i run this command ./gradlew assembleDebug getting this error '.' is not recognized as an internal or external command, operable program or batch file.

@Goehybrid 2019-05-15 17:16:10

This is not going to work, because it requires a dev server

@user3195905 2018-12-22 23:07:34

It can be possible to generate an unsigned apk version for testing purpose so you can run on your mobile.

Initially i got the red screen errors as most mentioned here. but i followed the same which was mentioned here and it worked for me.

On your console from working directory, run these four commands

react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

cd android

gradlew assembleDebug

gradlew assembleRelease

And then APK file will produce on : android\app\build\outputs\apk\debug\app-debug.apk

@Nhan Cao 2017-08-29 03:59:25

With me, in the project directory run the following commands.

For react native old version (you will see index.android.js in root):

mkdir -p android/app/src/main/assets && rm -rf android/app/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 && cd android && ./gradlew clean assembleRelease && cd ../

For react native new version (you just see index.js in root):

mkdir -p android/app/src/main/assets && rm -rf android/app/build && 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 && cd android && ./gradlew clean assembleRelease && cd ../

The apk file will be generated at:

  • Gradle < 3.0: android/app/build/outputs/apk/
  • Gradle 3.0+: android/app/build/outputs/apk/release/

@Priyal 2017-08-29 05:00:49

can you please elaborate a bit and how does it solves the problem?

@zephyr 2018-04-19 12:09:11

I was getting error opening in in index.android.bundle , and solved it by your suggestion. Thank you... :)

@Arif 2018-04-28 16:39:53

For me it is $ mkdir -p android/app/src/main/assets && rm -rf android/app/build && 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 && cd android && ./gradlew assembleDebug

@Anuj 2018-09-20 12:35:14

File not found: index.android.js in any of the project roots

@daka 2018-09-25 12:13:08

Note that --entry-file index.android.js needs to be replaced with --entry-file index.js for newer projects that have index.js instead of index.android.js in the root of their project directory.

@Goehybrid 2019-05-15 17:17:20

@daka you are wrong, index.android.js is the correct one

@Dmitry Mugtasimov 2016-04-30 22:40:08

You need to manually create the bundle for a debug build.

Bundle debug build:

#React-Native 0.49.0+
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

#React-Native 0-0.49.0
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

Then to build the APK's after bundling:

$ cd android
#Create debug build:
$ ./gradlew assembleDebug
#Create release build:
$ ./gradlew assembleRelease #Generated `apk` will be located at `android/app/build/outputs/apk`

P.S. Another approach might be to modify gradle scripts.

@Juan Solano 2016-08-10 19:36:41

In case someone is missing assets: this worked for me --assets-dest ./android/app/src/main/res/

@Sydney 2017-07-24 18:57:16

This works but I had to do the following on windows: 1. Instead of "./gradlew assembleDebug", i had to run "gradlew assembleDebug" (without ./) 2. Open cmd as administrator to run the last command.

@Simon Forsberg 2017-08-03 19:01:09

And if doing this gives me a big red screen when I start the app? (Note: I am running this directly after ejecting)

@Vivek 2017-10-11 15:44:53

How to take build for latest version because we do not hve index.android.js ?

@Shaked Sayag 2017-10-15 14:21:05

@VivekE Just use index.js

@Francesco Pasa 2017-12-18 18:27:03

I had to use --entry-file App.js to get it to run. Other note: if you get a red error page in the app, try to put AppRegistry.registerComponent('AppName', () => RootElement); export default RootElement; after (with appropriate import of AppRegistry) at the end of the file. Note that the export should follow the registration for it to work properly.

@Rishabh Bhatia 2018-03-02 16:18:49

People with latest version, please change entry point to --entry-file index.js, thanks.

@ir2pid 2018-06-18 08:40:25

react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android‌​.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug for the new reactnative version where the index.js is unified for ios and android

@GuiFGDeo 2018-06-20 16:21:58

For some reason I had to build my "gradlew" file with: cd android, gradle wrapper. However, after that, when I run gradlew assembleRelease I run into the following issue: Task 'assembleRelease' not found in root project 'android'. Any thoughts? Thanks!

@Murtuza 2018-08-15 18:44:30

APK is generated but it does not let you install the apk on device. It says, 'APK not installed'.

@Anuj 2018-09-20 16:29:44

undefined is not an object (evaluating 'r.default') i am getting this

@Anuj 2018-09-20 16:30:27

and in release apk i am getting An error occurred: 4001504: Invalid .apk file: couldn't retrieve the signature, the app must be signed to be able to install it on a device

@lance.dolan 2018-10-03 16:31:49

On RN v0.52.2 on linux, I needed to use a different bundle output and asset directory. Not sure why: --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res <--- that worked for me

@Rakesh Gujari 2018-10-09 18:12:15

run this command after the above process: react-native run-android --variant=debug. And then install the apk generated at <your project directory>/android/app/build/outputs/apk/debug on device. Reference: [stackoverflow.com/a/47618413/3301452]

@rams 2018-10-17 14:05:12

after two steps when i run this command ./gradlew assembleDebug getting this error '.' is not recognized as an internal or external command, operable program or batch file.

@Top-Master 2019-04-27 07:58:49

I was getting duplicate-file-error, but this did the trick (because it is using the build dir as output)

@Shem Leong 2018-06-17 09:51:07

I'm on react native 0.55.4, basically i had to bundle manually:

react-native bundle --dev false --platform android --entry-file index.js --bundle- 
output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets- 
dest ./android/app/build/intermediates/res/merged/debug

Then connect your device via usb, enable usb debugging. Verify the connected device with adb devices.

Lastly run react-native run-android which will install the debug apk on your phone and you can run it fine with the dev server

Note:

  • From 0.49.0, the entrypoint is a single index.js
  • gradlew assembleRelease only generates the release-unsigned apks which cannot be installed

@Abdellah Alaoui 2017-12-03 12:37:05

After you follow the first response, you can run your app using

react-native run-android --variant=debug

And your app will run without need for the packager

@Dharam Mali 2017-01-02 07:15:20

For Windows user if all steps followed properly from this: https://facebook.github.io/react-native/docs/signed-apk-android.html

You need to only run: gradlew assembleRelease

And your file will be:

  • app-release.apk
  • app-release-unaligned.apk

Location: E:\YourProjectName\android\app\build\outputs\apk

@Dharam Mali 2017-01-02 07:16:16

You can install/share app-release.apk to any device

@Josh 2017-02-27 15:39:35

Usually, the debug build has a different configuration than the release build (e.g. it uses a staging API). This doesn't help if you want a standalone APK that uses a different build configuration from the release

@Dharam Mali 2017-02-28 06:15:50

This APK is just for development/Testing purpose.

@manonthemat 2016-02-09 07:51:16

Change into the android folder and run ./gradlew assembleRelease to build the release file which you can send to your android device. The release apk doesn't need to have the dev server running.

@Lwin Kyaw Myat 2016-04-23 07:57:19

I run ./gradlew assembleRelease when I don't have signing key. I got only app-release-unsigned.apk.It not installed on android devices.

@Lwin Kyaw Myat 2016-12-02 03:52:47

@barha, @serg I cannot solved it, but I build with signing key. I got app-release-unaligned.apk and app-release.apk. It two apk is worked on most android devices and does not need development server.

@Tuananhcwrs 2019-05-07 10:49:54

You need the signing key. Or else the apk release version is not workable

Related Questions

Sponsored Content

16 Answered Questions

[SOLVED] Build unsigned APK file with Android Studio

15 Answered Questions

13 Answered Questions

[SOLVED] Failed to find Build Tools revision 23.0.1

22 Answered Questions

[SOLVED] Android failed to load JS bundle

11 Answered Questions

[SOLVED] How do I get the APK of an installed app without root access?

  • 2012-06-13 10:29:36
  • pinas
  • 160526 View
  • 171 Score
  • 11 Answer
  • Tags:   android root apk

30 Answered Questions

[SOLVED] How do you install an APK file in the Android emulator?

0 Answered Questions

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

38 Answered Questions

[SOLVED] Is quitting an application frowned upon?

  • 2010-01-09 15:59:46
  • Ted
  • 265712 View
  • 1101 Score
  • 38 Answer
  • Tags:   android

8 Answered Questions

[SOLVED] Android error: Failed to install *.apk on device *: timeout

2 Answered Questions

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

  • 2016-07-27 13:08:53
  • Evgheny Kalkutin
  • 5974 View
  • 6 Score
  • 2 Answer
  • Tags:   android react-native

Sponsored Content