Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Building release APK with react-native bundle #2743

Closed
mkonicek opened this issue Sep 16, 2015 · 44 comments
Closed

[Android] Building release APK with react-native bundle #2743

mkonicek opened this issue Sep 16, 2015 · 44 comments
Assignees
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@mkonicek
Copy link
Contributor

See #2703, looks like running react-native bundle and building with Gradle doesn't include the bundle in the APK.

Can you please document how to build release versions of Android apps? Should we release the Gradle plugin? Looks like react-native bundle is sufficient at this point. cc @kmagiera

@mkonicek mkonicek changed the title [Android] react-native bundle to build a release APK [Android] Building release APK with react-native bundle Sep 16, 2015
@mkonicek
Copy link
Contributor Author

I think we need a separate guide on building release versions of apps. "Using offline bundle" is only documented inside "Running On Device (iOS)" right now.

@flipace
Copy link
Contributor

flipace commented Sep 16, 2015

Yes, that'd be great. I could only find a short block of information about this topic on the Debugging page in the documentation (disabling developer mode for the app. And it doesn't include any information about the bundle command)

@cosmith
Copy link
Contributor

cosmith commented Sep 16, 2015

+1 on the documentation. Also see #2712

@krizpoon
Copy link

This works for me:

  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"

@hswolff
Copy link
Contributor

hswolff commented Sep 24, 2015

Messed around with this for a while...seems like the only way (as of my writing this) to create a bundle for Android is to use the method that @krizpoon outlined above.

I tried:

react-native bundle --url src/index.android.js --out android/app/src/main/assets/index.android.bundle --root src

However it seems like the packager is excluding *.android.* files and throws the following error, despite /Users/hswolff/Sites/chartbeat/mobile_app/src/index.android.js existing:

➜  ~/Sites/chartbeat/mobile_app git:(phoenix) ✗ react-native bundle --url src/index.android.js --out android/app/src/main/assets/index.android.bundle --root src
Building package...

/Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/node_modules/promise/lib/done.js:10
      throw err;
      ^
NotFoundError: Cannot find entry file src/index.android.js in any of the roots: ["/Users/hswolff/Sites/chartbeat/mobile_app","/Users/hswolff/Sites/chartbeat/mobile_app/src"]
    at DependencyGraph._getAbsolutePath (/Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js:186:11)
    at /Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js:141:28
    at tryCallOne (/Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/node_modules/promise/lib/core.js:37:12)
    at /Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/node_modules/promise/lib/core.js:103:15
    at flush (/Users/hswolff/Sites/chartbeat/mobile_app/node_modules/react-native/node_modules/promise/node_modules/asap/raw.js:50:29)
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)

Even trying to do something clever like this:

react-native bundle --root src --url index.android.bundle?platform\=android\&dev=

Also throws the same error.

I imagine this will be looked at once the packager is in its own repo. For now I'm using the above outlined method.

@javamonn
Copy link

@hswolff This is due to the hardcoded blacklist param that results in the index.android.js getting ignored. Looks like this has been fixed on 0.12-stable.

@marty-wang
Copy link

can someone document the complete steps, from bundling all the way to installing the release version apk to device?

@marty-wang
Copy link

I put together my steps here. Hopefully it will save people some time.

https://gist.github.com/marty-wang/5a71e9d0a6a2c6d6263c

@jguffey
Copy link

jguffey commented Oct 6, 2015

+1

1 similar comment
@syarul
Copy link

syarul commented Oct 6, 2015

+1

@satya164
Copy link
Contributor

satya164 commented Oct 7, 2015

I have a pull request open here - #3061

@kkganesan
Copy link

@marty-wang +1 for gist

@satya164
Copy link
Contributor

@kkganesan It's already on the documentation page - http://facebook.github.io/react-native/docs/signed-apk-android.html#content

@brentvatne
Copy link
Collaborator

Closing this issue, looks like it's been solved by @satya164's PR

@scgough
Copy link

scgough commented Nov 20, 2015

Hi all, whenever I run the $ cd android && ./gradlew assembleRelease step in the page linked by @satya164 I get the error: org.gradle.api.GradleException: Could not list contents of '/Users/me/React/myapp/node_modules/.bin/defs'.

Has anyone else experienced this? I can't seem to get around it. I've posted on SO with no luck so far: http://stackoverflow.com/questions/33785803/error-generating-signed-apk

@brentvatne
Copy link
Collaborator

cc @mikearmstrong001 ^

@scgough
Copy link

scgough commented Nov 21, 2015

Just as an update, the only way so far that I can create a signed APK is by running the curl "http://localhost:8081/index.android.bundle?platform=android" -dev=false -o "android/app/src/main/assets/index.android.bundle" command and then using Android Studio to create the actual APK. Whenever I try to create the APK fully via Terminal I get the error outlined here: http://stackoverflow.com/questions/33785803/error-generating-signed-apk

@shawnXiao
Copy link

@scgough I have same question. Have you solved it?

@scgough
Copy link

scgough commented Jan 22, 2016

Hi there @shawnXiao - I can run the following to compile the package now (from the project folder in terminal):

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/

@satya164
Copy link
Contributor

You don't need to run any commands. The gradle script automatically bundles the script for you.

@kadosh1000
Copy link

I have tried all the guides and still can't generate a working apk, it always keeps crushing, seems like the bundle not deliveres to the apk

@philohelp
Copy link

Same here ?
cd android && ./gradlew assembleRelease
cd android && ./gradlew installRelease
I can run apk-appdebug on my device but not the app-release. And I dont know what is happening since I cant get to the first screen of the app.

@pjnovas
Copy link

pjnovas commented May 4, 2016

Same here, It works for the app debug on my device, but when I build a release, install on device and open it throws a "App stopped working".

This started to happen from react-native 0.24 (It was working with 0.22)

Should I create a new issue?, because this one is closed

@hassankhan
Copy link

Same here, Gradle is not outputting the JS bundle file

@eladcandroid
Copy link

@philohelp There's no "./gradlew installRelease" task... (RN 0.26)

@juellez
Copy link

juellez commented Jun 8, 2016

@pjnovas same issue here, after upgrading to 0.22.2 from 18 - not sure if that's the same as your 0.22. Thought I'd add it here in case you did open another issue, as I'm at a loss of what to do.

@neciu
Copy link
Contributor

neciu commented Jun 19, 2016

I'm using version 0.28.0-rc.0 and this is my working flow of releasing signed Android APK:

  1. Bump version in android/app/build.gradle.
  2. As @scgough said: 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/
  3. In Android Studio: Build -> Generate Signed APK

@fab1an
Copy link

fab1an commented Jun 23, 2016

@neciu do you use the build.gradle supplied by react-native or your own?

@neciu
Copy link
Contributor

neciu commented Jun 23, 2016

@fab1an the one given to me by react-native init.

@fab1an
Copy link

fab1an commented Jun 23, 2016

but shouldn't that one build the bundle by itself without you manually having to do it?

@levinqdl
Copy link

I have encountered a similar problem as @scgough described. In my case, it is Could not list contents of '/Users/me/React/myapp/node_modules/.bin/window-size'. The windows-size is a symbolic link point to '../window-size/cli.js', and this file disappeared, so I reinstalled the window-size package and the problem solved.

@neciu
Copy link
Contributor

neciu commented Jun 24, 2016

@levinqdl o wow! I gonna test that this evening!

@scgough
Copy link

scgough commented Jun 24, 2016

Hi all - sorry I've not been active on this. Been on other projects. To summarise though, I can only create an Android APK using the method @neciu described. Not the end of the world but slightly more painful than iOS. It just feels a bit of a 'hacky' process.

@fabianbormann
Copy link

In my case

./gradlew assembleRelease

...

FAILURE: Build failed with an exception.

* What went wrong:
Could not list contents of '/Users/devpc/myproject/node_modules/.bin/window-size'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I simply had to remove that empty file rm ~/myproject/node_modules/.bin/window-sizeand now it works!

@TheGuy68
Copy link

@marty-wang : Your guide was awesome. Really helped a lot.
I wish there was a step by step like that for apple from unassigned app to deploying online.

@RichardLindhout
Copy link

A solution which worked for me was deleting node_modules, run 'npm install' on the project folder
than cd android
en run ./gradlew assembleRelease

@Vadorequest
Copy link

I tried the following:

Generate APK (UNSIGNED) (Android)
  1. Create the folder assets in android/app/src/main folder.
  2. Run curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
  3. Run 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/
  4. Run cd android && ./gradlew assembleRelease

BUILD SUCCESSFUL

But no .apk file created. I'm trying to generate an unsigned app, to install it on my own mobile. What did I miss?

@fab1an
Copy link

fab1an commented Jan 31, 2017

@Vadorequest the APK you seek should reside in app/build/outputs/apk

@Vadorequest
Copy link

@fab1an Thanks, I must have missed that in the doc. I tried to adb install the app-release-unsigned.apk but I couldn't (permission denied). So I tried the debug.apk, but I got a bundle error at startup, which I fixed by running the react-native start and react-native run-android commands, but it requires a wired connection between the phone and the computer. I wanted to have a standalone apk on the phone.

Finally, I just tried with the app-debug-unaligned.apk and it works on the phone without wired connection.
Thanks for the help!

@fab1an
Copy link

fab1an commented Feb 1, 2017

@Vadorequest You did not miss it, it's simply not in the docs.

You can install the signed apk using adb pm install myapk.apk

@weiliank
Copy link

weiliank commented Apr 3, 2017

@neciu do we have to run 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 everytime we wish to build apk?

@krishan-kumar-mourya
Copy link

(in project directory run following commands)

  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
  3. react-native run-android

@ggarg2
Copy link

ggarg2 commented Jul 30, 2017

I am creating release apk in react native using below commands. It works for me.

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/

Mac
watchman watch-del-all && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

Windows
Permanent delete node_modules
npm cache clean –force
npm install
npm start -- --reset-cache

Open SDK -> Click on rebuild -> Fixed gradle build issue -> click on rebuild again -> generate signed apk.

@WillGeller
Copy link

WillGeller commented Mar 9, 2018

I was able to build for offline use without having to sign using @krishan-kumar-mourya instructions! The only problem is now I don't have my assets that were loaded as so require('./assets/portal_ship/portal_ship_specular.png') from one of my js files.

Update
Found the Solution to ^ following step 5 of the answer here https://stackoverflow.com/questions/34175416/how-to-use-offline-bundle-on-android-for-react-native-project/

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests