Hey guys,
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.
npm igradlew assembleDebug (I'm using bundleInDebug: true)Restart AppHere 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>
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.
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...
I can confirm that this issue also happens on a production app with the following details:
When downloading a fresh app from the Play Store, it crashes a few seconds after the first run (probably because it's trying to do a restart like mentioned above).
In the crash reports I can also see the error:
"Trying to add a root view with an explicit id already set. React Native uses the id field to track react tags..."
(Interesting to see if it happens also on 0.45.0)
0.45.0 to .1 is only a small update of the packanger that was referencing a wrong path for the cli to pick up.
However, 0.45.x uses a slightly different way of handling the js in the delegate file.
@D1no I don't know about a fresh project. Need to check it.
I almost sure the update is applied, but need to check it again.
Hi @D1no, thank you for the assistance, please let me know if you need any help.
Hi @D1no, thanks for your help. I also should mention, that the issues reproduces for 0.45.x only and we have not seen such kind of issues before, another words - the issue does not reproduce for previous versions of RN (0.44.x, 0.43.x and so on).
Hey guys, I've figured out what goes wrong here - we need to perform the following commands on attached root views in instanceManager:
reactRootView.removeAllViews();
reactRootView.setId(View.NO_ID);
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.
Having this same crash as well. Will try the fix above.
Edit: it works
Hi @andrepcg, great! Thanks for the response, going to release version 3.0.0 of react-native-code-push on the next week.
Wow that was quick! Congrats!
Thank you! We are eagerly waiting for it (:
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 @ramsestom, sure, I've closed it by mistake, sorry for it.
Hey guys, as I can see - the fix I've implemented for react-native-code-push is currently in master branch here . And the previous version of RN 0.45.1 does not contain this changes. So the issue probably should be fixed in next versions of RN.
The issue has been fixed in https://github.com/facebook/react-native/commit/c639a1f802d8da58405ac5132ed75b8a0e9ac032, closing this.
Still have this issue:
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 addRootView.
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.uimanager.NativeViewHierarchyManager.addRootViewGroup(NativeViewHierarchyManager.java:510)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.uimanager.NativeViewHierarchyManager.addRootView(NativeViewHierarchyManager.java:502)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.uimanager.UIViewOperationQueue.addRootView(UIViewOperationQueue.java:605)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.uimanager.UIImplementation.registerRootView(UIImplementation.java:211)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.uimanager.UIManagerModule.addRootView(UIManagerModule.java:302)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1021)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:978)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.access$1300(ReactInstanceManager.java:113)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager$5$2.run(ReactInstanceManager.java:941)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:790)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:164)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
02-27 17:55:33.392 11588 11711 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:764)
Using react-native-restart library that calls recreateReactContextInBackground, 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.
Most helpful comment
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.