software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.08k stars 519 forks source link

Crash issue on Oneplus, Vivo, Samsung & Oppo devices. Screen just go black on release. #1994

Closed randomittin closed 9 months ago

randomittin commented 10 months ago

Description

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mewt.app/com.mewt.app.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3864) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4006) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:111) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2462) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:240) at android.os.Looper.loop (Looper.java:351) at android.app.ActivityThread.main (ActivityThread.java:8377) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1013) Caused by androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception at androidx.fragment.app.Fragment.instantiate (Fragment.java:631) at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:57) at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:483) at androidx.fragment.app.FragmentStateManager. (FragmentStateManager.java:85) at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:2728) at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:198) at androidx.fragment.app.FragmentActivity$2.onContextAvailable (FragmentActivity.java:149) at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable (ContextAwareHelper.java:99) at androidx.activity.ComponentActivity.onCreate (ComponentActivity.java:362) at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:273) at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:45) at android.app.Activity.performCreate (Activity.java:8397) at android.app.Activity.performCreate (Activity.java:8370) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1403) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3837) Caused by java.lang.reflect.InvocationTargetException: at java.lang.reflect.Constructor.newInstance0 at java.lang.reflect.Constructor.newInstance (Constructor.java:343) at androidx.fragment.app.Fragment.instantiate (Fragment.java:613) Caused by java.lang.IllegalStateException: Screen fragments should never be restored. Follow instructions from https://github.com/software-mansion/react-native-screens/issues/17#issuecomment- to properly configure your main activity. at com.swmansion.rnscreens.ScreenFragment. (ScreenFragment.kt:57) at com.swmansion.rnscreens.ScreenStackFragment. (ScreenStackFragment.kt:38)

Steps to reproduce

Here's the entire list: crash_data.xlsx

You can download the app on playstore & see the error yourself (https://play.google.com/store/apps/details?id=com.mewt.app&pli=1).

I'm stuck here & have tried all the other suggestions including the one for import {enableScreens} from 'react-native-screens'; enableScreens(false);

The app is unexpectedly crashing on these devices & is already in production.

Snack or a link to a repository

https://github.com/mewt-app/superapp

Screens version

3.29.0

React Native version

0.72.8

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

Release mode

Device

Real device

Device model

No response

Acknowledgements

Yes

github-actions[bot] commented 10 months ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

kkafar commented 10 months ago

Hey @randomittin, have you tried following suggestions in stacktrace?

  1. Discussion: https://github.com/software-mansion/react-native-screens/issues/17#issuecomment
  2. Resulting library installation steps: https://github.com/software-mansion/react-native-screens?tab=readme-ov-file#android
dev-abhinavsinghHP commented 10 months ago

Hi @randomittin Did you find any Solution ??

tboba commented 10 months ago

Hi @dev-abhinavsinghHP, have you tried the solutions @kkafar has mentioned above?

vishaljnimblechapps commented 10 months ago

I'm still getting the issue on specific Samsung and OPPO devices(samsung dm3q (Galaxy S23 Ultra), OPPO OP4F0BL1 (CPH2207)). Even after adding this block of code in MainActivity.java.

OS Version:- Samsung - 14 OPPO - 13

Versions react-native-screens: ^3.18.2 react-native": 0.70.4 @react-navigation/bottom-tabs: ^6.5.3 @react-navigation/elements: ^1.3.6 @react-navigation/native": ^6.0.13 @react-navigation/stack: ^6.3.3

import android.os.Bundle;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); }

Thank you in advance for any help.

tboba commented 10 months ago

@vishaljnimblechapps great, thanks for clarifying this. Luckily I have physical Samsung phone, so I'll try to check this issue today 👍

vishaljnimblechapps commented 10 months ago

@tboba ohh thanks. Let me know if you need anything from my side.

vishaljnimblechapps commented 10 months ago

@tboba any update ? We are still facing this issue in production.

randomittin commented 10 months ago

Hi All,

I've figured out a couple of issues in my code from earlier. We accidentally moved on new react native architecture called Fabric & didn't include the calling Override part in the constructor. I tried fixing it this way, but it wasn't working.

I ended up removing react-native-screens completely by disabling it in MainActivity.java file in 'android/app/src/main/java/com/appname/MainActivity.java'.

Screenshot 2024-01-10 at 4 07 48 PM

to

Screenshot 2024-01-10 at 4 07 34 PM

See I commented the following code to disable Fabric usage as the Override for react-native-screen's onCreate is getting missed here & thus the exception error resulting in crash.

@Override protected ReactActivityDelegate createReactActivityDelegate() { return new DefaultReactActivityDelegate( this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. DefaultNewArchitectureEntryPoint.getFabricEnabled() ); }

I've also added detachInactiveScreens={false} in the stack navigator declaration:

Screenshot 2024-01-10 at 4 15 36 PM

I'd also like to point out that we had to create a new build entirely as in process of fixing this bug, we went on to break almost all parts of app, (fixed many other bugs on the way), & ended up moving the entire src folder to an older build. This seem to fix the bug.

Thus, I believe detachInactiveScreens={false} in the stack navigator declaration should suffice.

vishaljnimblechapps commented 10 months ago

@tboba did you find anything ?

tboba commented 9 months ago

Hi @vishaljnimblechapps, sorry for no response. I was quite busy lately and had other bugs to fix. Unfortunately I can't reproduce that, as the repro is no longer available on Github. Have you tried the solution that @vishaljnimblechapps has mentioned above?