[Android 1.13.2-beta]: NPE on loadBundle
Context
[email protected][email protected]Android 4.4 and 5.1, armv7a(Shouldn't matter..)CodePushcreated withisDebugModeoff.
Stacktrace
java.lang.NullPointerException
at CodePushNativeModule.loadBundleLegacy(CodePushNativeModule.java:86)
at CodePushNativeModule.loadBundle(CodePushNativeModule.java:103)
at CodePushNativeModule.restartApp(CodePushNativeModule.java:460)
...
Reproduction
- Ensure there is a new CodePush release in the cloud.
- Launch the React Native based app.
- (In the JS side) Call
CodePush.sync({ installMode: IMMEDIATE }). - (In the JS side, at the same time) Launch a native activity (In our case it is a Google AdMob Interstitial).
- Keep the native activity open. Wait until the CodePush bundle is downloaded. Once the installation finishes (and
CodePushNativeModule#restartAppis 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 are you using https://www.npmjs.com/package/react-native-admob?
@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 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?
The fix was relatively quick because you provided a ton of useful information.
@geof90 Yes, I can confirm that 337a03e fixes this issue. Good job!
Awesome! We'll publish the changes to NPM tomorrow.
We've published [email protected] to NPM that includes this fix.