React-native-code-push: Android crashes as soon as app opened (production bundle build)

Created on 31 Mar 2016  路  28Comments  路  Source: microsoft/react-native-code-push

Most helpful comment

Nope, but your APK needs to contain a JS bundle. As I mentioned, by default, RN doesn't generate the JS bundle in the APK when doing a debug build (it assumes you're using the packager), so if you're running react-native run-android, you are doing a debug build and your APK won't actually include a JS bundle file to run. That isn't a CodePush issue, and would manifest itself if you removed CodePush entirely as well.

There are two solutions:

  1. Do an actual release build
  2. Modify the android\app\react.gradle file to enable generating the APK-bundled JS bundle file even in debug builds. Simply changing this line to enabled true would do the trick.

Let me know if either of those work for you. If not, it would be helpful if you could remove the getJSBundleFile method from your MainActivity file and see if the issue still occurs.

All 28 comments

How are you running the app? "react-native run-android"? When you say that it's a production bundle build, do you mean that you actually did a release build of the APK or that you explicitly disabled developer support in your MainActivity? If the latter, then the RN build scripts don't generate the binary bundle by default in a debug build, and so your app will crash because it can't find the JS bundle.

If that is in fact the problem, you should be able to remove the "getJSBundleFile" method entirely from your MainActivity (to remove the use of CodePush), and still see the same issue,.

So I need to release one version to Code Push first in order for my app to stop crashing since it can't find a JS Bundle or something?

Nope, but your APK needs to contain a JS bundle. As I mentioned, by default, RN doesn't generate the JS bundle in the APK when doing a debug build (it assumes you're using the packager), so if you're running react-native run-android, you are doing a debug build and your APK won't actually include a JS bundle file to run. That isn't a CodePush issue, and would manifest itself if you removed CodePush entirely as well.

There are two solutions:

  1. Do an actual release build
  2. Modify the android\app\react.gradle file to enable generating the APK-bundled JS bundle file even in debug builds. Simply changing this line to enabled true would do the trick.

Let me know if either of those work for you. If not, it would be helpful if you could remove the getJSBundleFile method from your MainActivity file and see if the issue still occurs.

What does the JS Bundle compare itself to when you check for updates? Let's say I haven't released a version to Code Push yet -- I run gradle commands here, sign the app, and install it on a device. https://gist.github.com/marty-wang/5a71e9d0a6a2c6d6263c. Do I need to explicitly say the version I have on the device through JS or something?

As long as you did step 3 here, the CodePush plugin will compare the contents of the binary against the latest update on the server. If you don't do this step, then the client will simply assume any update that is available in the configured CodePush deployment, and is eligible for the requesting client (e.g. the targetBinaryVersion matches, and the release isn't marked as disabled) is available.

I used rnpm to install it, so I'm assuming it worked. I also edited my app's MainActivity.java file to add/replace the line with CodePush being added under list package (and added my deployment key in there in quotes).

Here's adb logcat, the bug persists with bundled builds somehow, is the packager cache not cleared for bundler? This is incredibly frustrating.

03-31 14:19:16.527 21131 21152 E ReactNativeJS: undefined is not a function (evaluating 'babelHelpers.asyncToGenerator')
03-31 14:19:16.534 21131 21153 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
03-31 14:19:16.534 21131 21153 E AndroidRuntime: Process: com.myapp, PID: 21131
03-31 14:19:16.534 21131 21153 E AndroidRuntime: Theme: themes:{}
03-31 14:19:16.534 21131 21153 E AndroidRuntime: com.facebook.react.modules.core.JavascriptException: undefined is not a function (evaluating 'babelHelpers.asyncToGenerator'), stack:

See https://github.com/Microsoft/react-native-code-push/issues/271 for how I resolved it in debug/developer mode - but for some reason it still persists with these bundled releases.

I just updated our README to mention the custom gradle as part of the RNPM installation path. I didn't realize that was missing. Apologies!

@lostintangent Still same issue after modifying/updating readme.

Yeah sorry, my readme comment was about the gradle file step missing from the RNPM installation steps.

And no, we don't have our own babelrc file. I'll have to investigate why you're still hitting this issue, but I don't suspect that it's a CodePush issue, as opposed to an RN issue with your custom babelrc.

@lostintangent Is it because the code-push dependency of [email protected] is 1.8.0-beta instead of 1.9+?

@niftylettuce The code-push dependency is correct, its the latest on NPM.

Have you tried @skevy's other recommendation of using babel-preset-react-native-stage-0?

I've gone ahead and packaged this up into ANOTHER, unofficial babel-preset, called babel-preset-react-native-stage-0.

To use, simply npm install babel-preset-react-native-stage-0 --save and put

{ presets: ['react-native-stage-0'] }

yeah, I've used that. Thing is I don't know how to clear the release/bundle cache. I tried on a fresh react-native init and added code push and it worked fine.

Could it be because contents of my index.android.js are require('./src');?

@niftylettuce have you tried deleting the entire contents of the android/build folder?

@geof90 yeah

Not sure if it makes a difference, but the clean/fresh react native init was v0.22.2 and the version I'm working with and running into this error with is v0.21.0

How about doing rm -fr $TMPDIR/react-*? (to clear the bundle cache)

Tried that too, and watchman del all thing -- and killed all processes with node/watchman

Just to help me understand the problem, what do u mean by a "production bundle build"? Are u following these steps https://facebook.github.io/react-native/docs/signed-apk-android.html#content to generate and run a release APK?

I'm following this https://gist.github.com/marty-wang/5a71e9d0a6a2c6d6263c - same thing pretty much @geof90

(I skip step 1)

OK got it working. I upgraded to latest RN v0.22.2, cleared node_modules, killed watchman and node, cleared watchman with watchman watch-del-all, rm -rf ~/.npm and then from scratch re-installed code push (w/o using rnpm). I also removed the android/app/build folder and android/build folder (I only had removed app's build folder in the past, which may have been the actual issue). Regardless, closing, as this is fixed.

@niftylettuce Glad it worked out!

Let me know if either of those work for you. If not, it would be helpful if you could remove the getJSBundleFile method from your MainActivity file and see if the issue still occurs.

@lostintangent Was experiencing the same, and I removed the getJSBundleFile per your advice and the problem indeed did stop occurring. I don't suppose this is a good solution if I want CodePush to still work in production though, so would you have any other advice? ;)

Hi @altruio, could you please create new issue using this template, so we would able to help you?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marf picture marf  路  25Comments

marcmo picture marcmo  路  26Comments

ujwal-setlur picture ujwal-setlur  路  32Comments

jpr-longgame picture jpr-longgame  路  25Comments

ivpusic picture ivpusic  路  25Comments