react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

[Android 1.13.2-beta]: NPE on loadBundle

Open overminder opened this issue 10 years ago • 7 comments

Context

Stacktrace

java.lang.NullPointerException
at CodePushNativeModule.loadBundleLegacy(CodePushNativeModule.java:86)
at CodePushNativeModule.loadBundle(CodePushNativeModule.java:103)
at CodePushNativeModule.restartApp(CodePushNativeModule.java:460)
...

Or here on master.

Reproduction

  1. Ensure there is a new CodePush release in the cloud.
  2. Launch the React Native based app.
  3. (In the JS side) Call CodePush.sync({ installMode: IMMEDIATE }).
  4. (In the JS side, at the same time) Launch a native activity (In our case it is a Google AdMob Interstitial).
  5. Keep the native activity open. Wait until the CodePush bundle is downloaded. Once the installation finishes (and CodePushNativeModule#restartApp is called), the app crashes.

Analysis

The faulty null pointer came from ReactContextBaseJavaModule#getCurrentActivity, which returns ReactContext#mCurrentActivity#get. This field will be set to null in ReactContext#onHostPause, which in this issue will be triggered by launching another native activity.

It's quite possible that this can't be solved without changes to the react-native repo.. Maybe we can propose to add something like Promise<Activity> getCurrentActivityEventually() so that we can restart the activity when it comes back.

overminder avatar Jul 11 '16 08:07 overminder

@overminder are you using https://www.npmjs.com/package/react-native-admob?

geof90 avatar Jul 11 '16 16:07 geof90

@geof90

Thanks for your fix! That's pretty quick..

Yes, I'm using react-native-admob. But as you might have already figured out, any kind of native activity should be able to trigger this.

overminder avatar Jul 11 '16 23:07 overminder

@overminder cool! Could you do us a favour and pull the latest bits from GitHub now that I have merged it, and verify that the fix works?

geof90 avatar Jul 11 '16 23:07 geof90

The fix was relatively quick because you provided a ton of useful information.

geof90 avatar Jul 11 '16 23:07 geof90

@geof90 Yes, I can confirm that 337a03e fixes this issue. Good job!

overminder avatar Jul 12 '16 03:07 overminder

Awesome! We'll publish the changes to NPM tomorrow.

geof90 avatar Jul 12 '16 04:07 geof90

We've published [email protected] to NPM that includes this fix.

geof90 avatar Jul 12 '16 18:07 geof90