react-native-screens: Crash on app launch
Hello,
I have encountered a problem while using react-native-screens combine with react-navigation : sometimes the app crash when I launched it (tested on Android only). This is the error catch in Logcat in Android Studio :
Process: com.XXXX, PID: 30449
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XXXX/com.XXXX.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2825)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1601)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6589)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
at androidx.fragment.app.Fragment.instantiate(Fragment.java:532)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2848)
at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:85)
at androidx.fragment.app.FragmentManagerImpl.restoreSaveState(FragmentManagerImpl.java:2485)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:195)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:288)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
at com.XXXX.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1601)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6589)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:514)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2848)
at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:85)
at androidx.fragment.app.FragmentManagerImpl.restoreSaveState(FragmentManagerImpl.java:2485)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:195)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:288)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
at com.XXXX.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1601)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6589)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Screen fragments should never be restored
I didn’t have this issue when I was using react-native-screens 1.0.0-alpha.22
with react-navigation 3.11.0
on react-native 0.59.4
.
I don’t really know what could be the cause of this issue. I didn’t have it before upgrading and it only appears sometimes.
My setup: react-native: 0.60.5 react-navigation: 4.0.7 react-native-screens: 2.0.0-alpha.3 OS: Android 8.0.0 Device: real
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 17
- Comments: 19 (1 by maintainers)
@Alaa-Ben @vivekraj I tried all the solutions presented here for both navigation and flipper. I have version 0.63.2 and my problem persists, any solution?
I missed something during the Installation.
Fixed the issue by adding below lines to dependencies section in android/app/build.gradle
implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
@nicolashemonic Flipper isn’t working on 0.61.x, so commenting out/removing
initializeFlipper(this)
in yourMainApplication.java
should do the trick.@Alaa-Ben Effectively
initializeFlipper(this)
triggered the error. The React Native team is working hard to simplify the upgrade processus but I don’t understand why this line is not commented by default! So much time lost! Thank you.Edit: So the error is not related to
react-native-screens
(sorry!) but I hope that will help anyone 😃I also encountered this problem, as long as you install this package Android will flip back, because react-navigation can not remove react-native-screens, how to solve it?
For me, those 2 lines are already added, I followed exactly the installations instructions but still have this issue sometimes.
I had a similar issue where my app crashed on startup on Android. However I am using react-native-screens and react-native-track-player and in the npm version in the dependencies is used
So although the react-native-screens I had the dependencies needed (as described by @vivekraj ) in android>app>build.gradle the app stopped crashing after I replaced the above dependencies within react-native-track-player.