react-native: [Android] Unable to recreateReactContextInBackground
Hey guys,
Description
There is an issue with recreateReactContextInBackground()
method after upgrading React Native version from 0.44.3 to 0.45.1:
06-08 13:19:29.400 2262 2262 E AndroidRuntime: FATAL EXCEPTION: main
06-08 13:19:29.400 2262 2262 E AndroidRuntime: Process: com.testapp_rn, PID: 2262
06-08 13:19:29.400 2262 2262 E AndroidRuntime: com.facebook.react.uimanager.IllegalViewOperationException: Trying to add a root view with an explicit id already set. React Native uses the id field to track react tags and will overwrite this field. If that is fine, explicitly overwrite the id field to View.NO_ID before calling addMeasuredRootView.
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.uimanager.NativeViewHierarchyManager.addRootViewGroup(NativeViewHierarchyManager.java:504)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.uimanager.NativeViewHierarchyManager.addRootView(NativeViewHierarchyManager.java:496)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.uimanager.UIViewOperationQueue.addRootView(UIViewOperationQueue.java:570)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.uimanager.UIImplementation.registerRootView(UIImplementation.java:129)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.uimanager.UIManagerModule.addMeasuredRootView(UIManagerModule.java:210)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.attachMeasuredRootViewToInstance(ReactInstanceManager.java:861)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:816)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:109)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.facebook.react.ReactInstanceManager$4$2.run(ReactInstanceManager.java:771)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-08 13:19:29.400 2262 2262 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-08 13:19:29.401 652 784 W ActivityManager: Force finishing activity com.testapp_rn/.MainActivity
06-08 13:19:29.516 346 346 E EGL_emulation: tid 346: eglCreateSyncKHR(1215): error 0x3004 (EGL_BAD_ATTRIBUTE)
I have RN project that uses CodePush SDK and I want to call CodePush.restartApp
method, but I’m receiving the error above.
To restart an app (reload js bundle) CodePush.restartApp
method uses loadBundle
method and loadBundle
method uses recreateReactContextInBackground()
to recreate context and load new js bundle:
restartApp -> loadBundle -> recreateReactContextInBackground
I’m expecting that react context will be recreated successfully without no errors.
Reproduction Steps
- unzip archive that I’ve provided below
npm i
gradlew assembleDebug
(I’m usingbundleInDebug: true
)- install apk
- open app
- click
Restart App
Sample Code
Here is app sample. rncp210release.zip
Source code:
import CodePush from "react-native-code-push";
...
restartApp() {
CodePush.restartApp(false);
}
...
<TouchableOpacity onPress={this.restartApp.bind(this)}>
<Text style={styles.syncButton}>Restart App</Text>
</TouchableOpacity>
Additional Information
- React Native version: 0.45.1
- Platform: Android
- Development Operating System: Windows
- Build tools: Android Studio 2.3.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 17
- Comments: 17
Hey guys, I’ve figured out what goes wrong here - we need to perform the following commands on attached root views in instanceManager:
The details are here: https://github.com/Microsoft/react-native-code-push/pull/901/files#diff-99865b122cb5308ab005ac99ccb55da0R185
So could someone please tell me why those lines that fixes the exception has been removed from RN 0.45? - I’m going to create PR that will fix it in RN itself, but good to know what was wrong with those lines and why they have been removed.
Still have this issue:
Using
react-native-restart
library that callsrecreateReactContextInBackground
, for changing app’s language.RN 0.53.3 (and 0.51.0)
UPDATE: This was probably because it was called multiple times, so fixed it by calling once. But still this is a bug.
Can we keep this issue open? Because it might be fixed in react-native-code-push but is is not in react-native in general where this issue remain…
Hi @andrepcg, great! Thanks for the response, going to release version 3.0.0 of react-native-code-push on the next week.
Also have this issue, when runing in debug mode from Visual studio, since I ugrated a project from react native 0.41 to 0.45.1 . I don’t know how to fix it…
Hey guys, would you have a chance please to take a look at this? Let me know if you need more info or need any help.