Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Unable to recreateReactContextInBackground #14533

Closed
sergey-akhalkov opened this issue Jun 15, 2017 · 17 comments · Fixed by microsoft/react-native-code-push#901
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@sergey-akhalkov
Copy link

sergey-akhalkov commented Jun 15, 2017

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

  1. unzip archive that I've provided below
  2. npm i
  3. gradlew assembleDebug (I'm using bundleInDebug: true)
  4. install apk
  5. open app
  6. 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
@sergey-akhalkov
Copy link
Author

sergey-akhalkov commented Jun 20, 2017

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.

@ramsestom
Copy link

ramsestom commented Jun 21, 2017

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...

@yaronlevi
Copy link

yaronlevi commented Jun 21, 2017

I can confirm that this issue also happens on a production app with the following details:

  • nexus 5 device
  • react [email protected]
  • code push with default setup (just wrapping the top component with codepush() )

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)

@D1no
Copy link

D1no commented Jun 21, 2017

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.

  • Does this crash also appear in a fresh init project that has not been upgraded (re-producing)?
  • Even though the app crashes, is the update (after a manual restart) applied?

@yaronlevi
Copy link

@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.

@sergey-akhalkov
Copy link
Author

Hi @D1no, thank you for the assistance, please let me know if you need any help.

@sergey-akhalkov
Copy link
Author

sergey-akhalkov commented Jun 22, 2017

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).

@sergey-akhalkov
Copy link
Author

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.

@andrepcg
Copy link

andrepcg commented Jun 23, 2017

Having this same crash as well. Will try the fix above.

Edit: it works

@sergey-akhalkov
Copy link
Author

Hi @andrepcg, great! Thanks for the response, going to release version 3.0.0 of react-native-code-push on the next week.

@D1no
Copy link

D1no commented Jun 23, 2017

Wow that was quick! Congrats!

@yaronlevi
Copy link

Thank you! We are eagerly waiting for it (:

@ramsestom
Copy link

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....

@sergey-akhalkov
Copy link
Author

sergey-akhalkov commented Jun 26, 2017

Hi @ramsestom, sure, I've closed it by mistake, sorry for it.

@sergey-akhalkov
Copy link
Author

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.

@sergey-akhalkov
Copy link
Author

The issue has been fixed in c639a1f, closing this.

@gentlee
Copy link

gentlee commented Feb 28, 2018

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.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 27, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants