expo: [ANDROID] expo-splash-screen crashes when pressing reload in debug mode.

🐛 Bug Report

Environment

Expo CLI 3.17.11 environment info: System: OS: macOS 10.15.3 Shell: 5.7.1 - /bin/zsh Binaries: Node: 13.3.0 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.2 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman IDEs: Android Studio: 3.5 AI-191.8026.42.35.5977832 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: expo: ~37.0.3 => 37.0.3 react: ~16.9.0 => 16.9.0 react-native: ~0.61.4 => 0.61.5 npmGlobalPackages: expo-cli: 3.17.11

Steps to Reproduce

Install expo splash screen on android Do all the configuration as in documentation In development mode (debug) open the menu and click reload

Expected Behavior

Should reload without any problem

Actual Behavior

It crashes on reload press, I also have some logs that might help.

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5106)
        at android.view.ViewGroup.addView(ViewGroup.java:4935)
        at android.view.ViewGroup.addView(ViewGroup.java:4875)
        at android.view.ViewGroup.addView(ViewGroup.java:4848)
        at expo.modules.splashscreen.SplashScreenController$showSplashScreen$2.run(SplashScreenController.kt:33)
        at android.app.Activity.runOnUiThread(Activity.java:6904)
        at expo.modules.splashscreen.SplashScreenController.showSplashScreen(SplashScreenController.kt:32)
        at expo.modules.splashscreen.SplashScreenController.showSplashScreen$default(SplashScreenController.kt:31)
        at expo.modules.splashscreen.SplashScreenController$handleRootView$1.onChildViewRemoved(SplashScreenController.kt:116)
        at android.view.ViewGroup.dispatchViewRemoved(ViewGroup.java:5007)
        at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:5650)
        at android.view.ViewGroup.removeAllViews(ViewGroup.java:5589)
        at com.facebook.react.ReactInstanceManager.clearReactRoot(ReactInstanceManager.java:723)
        at com.facebook.react.ReactInstanceManager.tearDownReactContext(ReactInstanceManager.java:1112)
        at com.facebook.react.ReactInstanceManager.runCreateReactContextOnNewThread(ReactInstanceManager.java:921)
        at com.facebook.react.ReactInstanceManager.recreateReactContextInBackground(ReactInstanceManager.java:908)
        at com.facebook.react.ReactInstanceManager.onReloadWithJSDebugger(ReactInstanceManager.java:878)
        at com.facebook.react.ReactInstanceManager.access$100(ReactInstanceManager.java:125)
        at com.facebook.react.ReactInstanceManager$2.onReloadWithJSDebugger(ReactInstanceManager.java:278)
        at com.facebook.react.devsupport.DevSupportManagerImpl.reloadJSInProxyMode(DevSupportManagerImpl.java:994)
        at com.facebook.react.devsupport.DevSupportManagerImpl.handleReloadJS(DevSupportManagerImpl.java:858)
        at com.facebook.react.devsupport.DevSupportManagerImpl$6.onOptionSelected(DevSupportManagerImpl.java:448)
        at com.facebook.react.devsupport.DevSupportManagerImpl$16.onClick(DevSupportManagerImpl.java:613)
        at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1222)
        at android.widget.AdapterView.performItemClick(AdapterView.java:330)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1190)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:3198)
        at android.widget.AbsListView$3.run(AbsListView.java:4116)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Update

Happened on release build as well, crashes on launch

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I’m having the same issue. But I’m using codepush in my project as well and getting the following exception:

com.facebook.react.uimanager.ViewGroupManager.removeViewAt ViewGroupManager.java, line 68 java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.

Stack traces android.view.ViewGroup.addViewInner ViewGroup.java:5259 android.view.ViewGroup.addView ViewGroup.java:5090 android.view.ViewGroup.addView ViewGroup.java:5030 android.view.ViewGroup.addView ViewGroup.java:5003 expo.modules.splashscreen.SplashScreenController$showSplashScreen$2.run SplashScreenController.kt:33 android.app.Activity.runOnUiThread Activity.java:6404 com.facebook.react.uimanager.ViewGroupManager.removeViewAt ViewGroupManager.java:68 com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren NativeViewHierarchyManager.java:457 com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute UIViewOperationQueue.java:205 com.facebook.react.uimanager.UIViewOperationQueue$1.run UIViewOperationQueue.java:779 com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches UIViewOperationQueue.java:888 com.facebook.react.uimanager.UIViewOperationQueue.access$2200 UIViewOperationQueue.java:42 com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded UIViewOperationQueue.java:948 com.facebook.react.uimanager.GuardedFrameCallback.doFrame GuardedFrameCallback.java:28 com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame ReactChoreographer.java:174 com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame ChoreographerCompat.java:84 android.view.Choreographer$CallbackRecord.run Choreographer.java:947

So I was seeing this in production too and I think I fixed it - I was conditionally rendering an initial route in react navigation based on an authenticated firebase user, and i had a loading component that checked for the user and returned null if there was no user. If there was a user, I returned a stack navigator.

I was storing this user in state, but I didnt set a default value. It looked like const [user, setUser] = React.useState() and changing it to const [user, setUser] = React.useState(null) solved the crash for me.

TLDR: check all your javascript code for what you render before you hide the splash screen and make sure there aren’t any little mistakes like that.

Thanks @alorr10 for the tip. That helped me as well.

I think I fixed it as well. I had it in a setTimeout() to add some delay. Moved hiding the splashscreen and I havent had the same problem.

I don’t have anything useful to add, but we’re seeing the same crash report on the google playstore as the one in the initial bug report. I’m unable to reproduce it, either by launching the app or using Updates.reloadAsync()

On iOS we do also have crash reports related to expo-splash-screen like the one reported in #7689

@SamyOptimize

  1. you can’t import SplashScreen from the expo package in App.js after ejecting, need to switch it to import from expo-splash-screen. i replaced the contents of App.js with this to isolate the example
  2. ~the project you provided doesn’t build for android~ looks like the debug keystore wasn’t included, copied it over and it builds. i ran yarn expo-splash-screen -p "android" -r "cover" "#0a0234" assets/splashscreen_image.pngand rebuilt and it worked as expected including on reload
  3. the project you provided had no launchscreen set on ios - I ran yarn expo-splash-screen -p "ios" -r "cover" "#0a0234" assets/splashscreen_image.png and that fixes this problem
  4. once i confirmed this worked as expected, i replaced import { SplashScreen } from 'expo'; with import * as SplashScreen from 'expo-splash-screen'; and updated function calls SplashScreen.hide() to SplashScreen.hideAsync() and SplashScreen.preventAutoHide() to SplashScreen.preventAutoHideAsync() and reloading works as expected (updated App.js with these changes).

we need to improve this flow so it just works out of the box when you eject, this is something we are actively working on. in the future, expo-splash-screen will be used in managed workflow as well, which will make this a lot easier because no code will need to change.