React-native: Only the original thread that created a view hierarchy can touch its views.

Created on 21 Sep 2017  路  21Comments  路  Source: facebook/react-native

This "Only the original thread that created a view hierarchy can touch its views" error given after react native version upgrade 44.2 to 47.2.

Environment:
OS: ubuntu 16.04
Node: 6.10.0
npm: 3.10.10
Watchman: 4.7.0
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react-native: 0.44.2 => 0.47.2
react: 16.0.0-alpha.12 => 16.0.0-alpha.12

Target Platform: Android (6.0.0)

Locked

Most helpful comment

I second this. Using Expo SDK 21 along with TypeScript 2.5, and getting consistent crashes on recompilation each time on Android.

I found my issue by viewing the stacktrace I could send to the dev (through the Android report bug feature). It was due to the following call:

abi21_0_0.com.facebook.react.devsupport.DebugOverlayController.setFpsDebugViewVisible(DebugOverlayConroller.java:49)

By turning off the Inspector module (for FPS perf etc), Expo stopped crashing.

All 21 comments

Hey, thanks for reporting this issue!

It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.

I am going to close this, but feel free to open a new issue that meets the requirements set forth in the template. Thanks!

I second this. Using Expo SDK 21 along with TypeScript 2.5, and getting consistent crashes on recompilation each time on Android.

I found my issue by viewing the stacktrace I could send to the dev (through the Android report bug feature). It was due to the following call:

abi21_0_0.com.facebook.react.devsupport.DebugOverlayController.setFpsDebugViewVisible(DebugOverlayConroller.java:49)

By turning off the Inspector module (for FPS perf etc), Expo stopped crashing.

same problem, crashes on reload when perf monitor is visible.

"react-native": "^0.48.4",
"react": "^16.0.0",
E/AndroidRuntime(17714): FATAL EXCEPTION: main
E/AndroidRuntime(17714): Process: com.chipta, PID: 17714
E/AndroidRuntime(17714): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
E/AndroidRuntime(17714):    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7093)
E/AndroidRuntime(17714):    at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1076)
E/AndroidRuntime(17714):    at android.view.View.requestLayout(View.java:17416)
E/AndroidRuntime(17714):    at android.view.ViewGroup.removeAllViews(ViewGroup.java:4198)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DebugOverlayController.setFpsDebugViewVisible(DebugOverlayController.java:49)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl.resetCurrentContext(DevSupportManagerImpl.java:610)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl.onReactInstanceDestroyed(DevSupportManagerImpl.java:516)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager.tearDownReactContext(ReactInstanceManager.java:941)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager.runCreateReactContextOnNewThread(ReactInstanceManager.java:793)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager.recreateReactContextInBackground(ReactInstanceManager.java:782)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager.onReloadWithJSDebugger(ReactInstanceManager.java:754)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager.access$000(ReactInstanceManager.java:109)
E/AndroidRuntime(17714):    at com.facebook.react.ReactInstanceManager$1.onReloadWithJSDebugger(ReactInstanceManager.java:157)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl.reloadJSInProxyMode(DevSupportManagerImpl.java:805)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl.handleReloadJS(DevSupportManagerImpl.java:650)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl$5.onOptionSelected(DevSupportManagerImpl.java:372)
E/AndroidRuntime(17714):    at com.facebook.react.devsupport.DevSupportManagerImpl$15.onClick(DevSupportManagerImpl.java:470)
E/AndroidRuntime(17714):    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1017)
E/AndroidRuntime(17714):    at android.widget.AdapterView.performItemClick(AdapterView.java:308)
E/AndroidRuntime(17714):    at android.widget.AbsListView.performItemClick(AbsListView.java:1510)
E/AndroidRuntime(17714):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3472)
E/AndroidRuntime(17714):    at android.widget.AbsListView$3.run(AbsListView.java:4835)
E/AndroidRuntime(17714):    at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime(17714):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(17714):    at android.os.Looper.loop(Looper.java:146)
E/AndroidRuntime(17714):    at android.app.ActivityThread.main(ActivityThread.java:5653)
E/AndroidRuntime(17714):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17714):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(17714):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
E/AndroidRuntime(17714):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
E/AndroidRuntime(17714):    at dalvik.system.NativeStart.main(Native Method)

Also have this error on React-native 0.50.3 and android 8

@hramos reopen?

@hramos
same question,
I quick repeat click one button on Android, it will show my toast repeat, in a minute, crash.
ndroid.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7361) at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1156) at android.view.View.requestLayout(View.java:19841) at android.view.View.requestLayout(View.java:19841) at android.widget.TextView.checkForRelayout(TextView.java:7688) at android.widget.TextView.setText(TextView.java:4585) at android.widget.TextView.setText(TextView.java:4442) at android.widget.TextView.setText(TextView.java:4417) at com.xsl.kit.utils.ToastWrapper.updateToast(ToastWrapper.java:61)

I also have this issue, with Android 7, and:

"react": "^16.2.0",
"react-native": "^0.51.0",

It is fixed when I disable the performance-monitor overlay. (so seemingly a bug in react-native)

thanks for @Venryx , it's works to me

@Venryx How do you disable the performance monitor overlay? Is it by shaking the phone and clicking the "Hider Perf Monitor"? I already did that, but still running into this error.

Yes, that's what fixed it for me. Must be another root-cause in your case.

I think the combination that breakes the System is having JS Dev Mode deactivated and Show performance Monitor true. Either one on its own seems to be working fine...

Need Help

Only the original thread that created a view hierarchy can touch its views.
checkThread
ViewRootImpl.java:6357
requestLayout
ViewRootImpl.java:874
requestLayout
View.java:17476
removeAllViews
ViewGroup.java:4345
setFpsDebugViewVisible
DebugOverlayController.java:115
resetCurrentContext
DevSupportManagerImpl.java:599
onNewReactContextCreated
DevSupportManagerImpl.java:523
setupReactContext
ReactInstanceManager.java:995
access$1300
ReactInstanceManager.java:113
run
ReactInstanceManager.java:965
handleCallback
Handler.java:739
dispatchMessage
Handler.java:95
dispatchMessage
MessageQueueThreadHandler.java:31
loop
Looper.java:135
run
MessageQueueThreadImpl.java:194
run
Thread.java:818

{
"main": "node_modules/expo/AppEntry.js",
"private": true,
"dependencies": {
"expo": "^25.0.0",
"react": "16.2.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",
"react-navigation": "^1.3.2"
}
}

Show performance monitor = true caused this issue for me.

Running on android 8.0
react-native-cli: 2.0.1
react-native: 0.54.2

I am sorry, but how you click on the "Hider Perf Monitor"?
I have android 7.0 version. I cannot do it. Please, help me.

@Venryx How do you disable the performance monitor overlay? Is it by shaking the phone and clicking the "Hider Perf Monitor"? I already did that, but still running into this error.

Hide Perf Monitor works for me.

I got the same issue. I shut down the server and restarted it and the issue went away.

Toggling the "Perf Monitor" off solved the issue for me.

To do this you can use the following adb command to bring up the menu (or shake your device):

adb shell input keyevent KEYCODE_MENU

Then you'll see "Hide Perf Monitor". Press that to hide it.

2018-06-16_23-29-15

Having the same issue. So Performance Monitor cannot be used along Live Reload? :(

Same issue? Are you going to fix it?

It seems it has been solved in https://github.com/facebook/react-native/pull/17544, in beta version 0.57.

Was this page helpful?
0 / 5 - 0 ratings