Today, I attempted to update to the latest react-navigation, and I figured I would try to use react-native-screens to improve performance. Unfortunately, it crashes on Android immediately upon opening. I have followed all of the instalation instructions, and I can confirm that my code works fine if I a) do not call useScreens() and b) extend from ReactActivity instead in the code below.
The exception only shows up in adb logcat:
49:04.038 11335 11335 E AndroidRuntime: FATAL EXCEPTION: main
12-22 17:49:04.038 11335 11335 E AndroidRuntime: Process: com.zonderstudios.zonder, PID: 11335
12-22 17:49:04.038 11335 11335 E AndroidRuntime: java.lang.IllegalArgumentException: No view found for id 0x1f1 (unknown) for fragment ScreenFragment{c8216f5 #0 id=0x1f1}
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1422)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2617)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2388)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2344)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:790)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6494)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
12-22 17:49:04.038 11335 11335 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
12-22 17:49:04.040 1634 1644 W ActivityManager: Force finishing activity com.zonderstudios.zonder/.MainActivity
12-22 17:49:04.047 1634 1649 I ActivityManager: Showing crash dialog for package com.zonderstudios.zonder u0
Here is my MainActivity.java.
package com.zonderstudios.zonder;
import android.os.Bundle;
import com.facebook.react.ReactFragmentActivity;
import org.devio.rn.splashscreen.SplashScreen;
import android.content.Intent;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactFragmentActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "zonder";
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, false);
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
// I also tried this, along with deleting the two lines for splash screen and set theme:
// super.onCreate(null);
}
@Override
protected void onPause() {
SplashScreen.hide(this);
super.onPause();
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}
Any thoughts on fixing this? My one thought might be that there is a conflict with something else. Not sure, though.
This happens to me everytime i use react-navigation with some rehydrated state (redux-persist) and try to navigate into another stack in a switch navigator as soon as the app starts (ex: user already logged). I will try to make up some repro to make this problem more clear... But i get the same error in android studio and just by removing useScreens() everything comes back to normal.
This happens to me too whenever the app is updated with a new version from the play store (only if using screens). It crashes, then the next time app starts all is good.
I'm having the same issue. I couldn't be sure it was an issue with this lib, but I tried removing it and the crash stopped.
Does anyone have an idea where to start looking to solve this?
It seems that the newest version [email protected] already solves this issue.
I updated it here and it worked for me.
Indeed, the new version 22, is working for me too.
Caveat: simply running yarn upgrade didn't do it. I had to delete node_modules and yarn.lock and install everything again.
EDIT: the crashes started happening again after installing react-native-splash-screen, but they seem to have been fixed by moving useScreens() into my App.js' componentDidMount().
@fjcaetano That's interesting, I have been using that splash screen library for quite a white and I was wondering if that might be the cause :P Any idea why moving to componentDidMount in that case works?
Experiencing the same problem on alpha-22, but without using react-native-splash-screen.
However all the crashes happened after navigating to our Offline screen, that appears when the user loses connection. That screen is in a different Stack Navigator.
The problem does not appear on iOS nor when disabling react-native-screens on Android.
I haven't tried moving useScreens() to componentDidMount() as I am not sure what the consequences of that could be.
Here is the full trace:
java.lang.IllegalArgumentException No view found for id 0xbf3 (unknown) for fragment ScreenFragment{85410b9 #14 id=0xbf3}
FragmentManager.java:1413 android.support.v4.app.FragmentManagerImpl.moveToState
FragmentManager.java:2601 android.support.v4.app.FragmentManagerImpl.addAddedFragments
FragmentManager.java:2372 android.support.v4.app.FragmentManagerImpl.executeOpsTogether
FragmentManager.java:2328 android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute
FragmentManager.java:2229 android.support.v4.app.FragmentManagerImpl.execPendingActions
FragmentManager.java:700 android.support.v4.app.FragmentManagerImpl$1.run
Handler.java:790 android.os.Handler.handleCallback
Handler.java:99 android.os.Handler.dispatchMessage
Looper.java:171 android.os.Looper.loop
ActivityThread.java:6651 android.app.ActivityThread.main
Method.java:-2 java.lang.reflect.Method.invoke
RuntimeInit.java:547 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run
ZygoteInit.java:824 com.android.internal.os.ZygoteInit.main
I believe moving to componentDidMount() have solved it because it enabled some time for the app to properly launch. If this is the case, a simple setImmediate might also do the trick, but I haven't tested that.
Our app is now working correctly. I've checked on iOS and react-native-screens are working as intended (by removing the screens not in display), but I haven't been able to assess if the behavior is the same for Android.
Unfortunately, after moving useScreens() to our root component's componentDidMount(), we're still seeing this error:
java.lang.IllegalArgumentException No view found for id 0xbf3 (unknown) for fragment ScreenFragment{9f211c8 #10 id=0xbf3}
FragmentManager.java:1413 android.support.v4.app.FragmentManagerImpl.moveToState
FragmentManager.java:2601 android.support.v4.app.FragmentManagerImpl.addAddedFragments
FragmentManager.java:2372 android.support.v4.app.FragmentManagerImpl.executeOpsTogether
FragmentManager.java:2328 android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute
FragmentManager.java:2229 android.support.v4.app.FragmentManagerImpl.execPendingActions
FragmentManager.java:700 android.support.v4.app.FragmentManagerImpl$1.run
Handler.java:739 android.os.Handler.handleCallback
Handler.java:95 android.os.Handler.dispatchMessage
Looper.java:145 android.os.Looper.loop
ActivityThread.java:6219 android.app.ActivityThread.main
Method.java:-2 java.lang.reflect.Method.invoke
Method.java:372 java.lang.reflect.Method.invoke
ZygoteInit.java:1399 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
ZygoteInit.java:1194 com.android.internal.os.ZygoteInit.main
Any other possible workaround? Thanks!
Not sure if this is related, but I have hunch it might be. We are experiencing this issue when moving between screens inside a SwitchNavigator.
When I change createSwitchNavigator to createStackNavigator the above error seems to go away... but we really need that switch navigator in there.
We also use SwitchNavigator, however I don't see an easy way to re-implement the same kind of navigation we need with a StackNavigator :/
@kmagiera fixed on 1.0.0-alpha.22
Hi, we were still experiencing this with 1.0.0-alpha.22
Specifically when using a switch navigator and navigating between scenes in the switch navigator.
Same scenario here
1.0.0-alpha.22 does not to fix this. It is happening extremely consistently even at that version.
I've been doing a bit of digging on this issue. Still haven't found a solution, but I did make some observations.
@kmagiera Could you take a look at some of the observations below to see if you have any ideas?
This happens because something is trying to find a ScreenContainer that does not exist in the view hierarchy.
The switch navigator does not use react-native-screens at all. It renders a SceneView which is just a context wrapper which passes the screenProps and navigation props.
Rendering a stack navigator inside a switch navigator seems to cause this very consistently.
I noticed that my there were two separate instances of ScreenContainer created, but the View hierarchy from the exception log only includes one instance of that component.
It initializes a few Screen instances before creating the second instance of ScreenContainer. Perhaps one of those screens is getting attached to some sort of orphaned container?
I'm wiped for today, but I'm going to continue looking into this tomorrow, so if anyone has any more data or observations to share I'd appreciate it.
This issue is happening because this library is not using Fragments correctly.
The issue happens when a ScreenContainer is unmounted. When this happens it tries to disconnect all the Screen instances here, which calls into here.
However, it appears the expectation in android is that these sort of operations should be handled through the FragmentManager which will clear a bunch of private instance variables, most importantly this one.
If the ScreenContainer is removed from the view hierarchy and that id is not cleared, then the next time the FragmentManager tries to do something with that Fragment it will attempt to find the container in the view hierarchy, which will fail and cause the above exception.
It would be great if we could get this fixed, because as far as I can tell you can't use the react navigation switch navigator without it. This makes it hard to implement our auth flow. We've been forced to disable react-native-screens on android.
Here's a minimal reproduction:
import React, { PureComponent } from 'react'
import { View } from 'react-native'
import { useScreens } from 'react-native-screens'
import {
createSwitchNavigator, createStackNavigator, createAppContainer
} from 'react-navigation'
useScreens()
function SomeLoginScreen() {
return <View style={{ backgroundColor: 'blue', flex: 1 }} />
}
function SomeAppScreen() {
return <View style={{ backgroundColor: 'red', flex: 1 }} />
}
const LoginStack = createStackNavigator({
Form: SomeLoginScreen
})
const AppStack = createStackNavigator({
Home: SomeAppScreen
})
const Navigator = createSwitchNavigator({
Login: LoginStack,
App: AppStack
})
class App extends PureComponent {
static router = Navigator.router
componentDidMount() {
// Crash:
this.props.navigation.navigate({ routeName: "App" })
// Does not crash
// setTimeout(() => this.props.navigation.navigate({ routeName: "App" }), 0)
}
render() {
return <Navigator {...this.props} />
}
}
export default createAppContainer(App)
I suspect that there may be multiple ways of triggering this crash, but the code above seems to cover the Switch navigator case specifically.
I have a very ugly workaround that uses reflection, but it's enough to get running.
You can see it here.
Note: That branch should not be used as is without careful consideration. There's a few changes in there specific to the environment we're using, so please only consider it as reference.
Note 2: If using this hack with proguard, make sure you don't mangle Fragment.
Seems like RNS doesn't work well along with inlineRequires=true in metro config. After enabling it app crashes every time it starts with 'No view found for fragment' error.
I tried to swap in the SwitchNavigator from react-navigation-animated-switch to see if that might be a viable workaround for this issue. Unfortunately, it fails in the same way and it also exhibits a number of different (but probably related) crashes: https://github.com/react-navigation/animated-switch/issues/6
same here:
Fatal Exception: java.lang.IllegalArgumentException: No view found for id 0x5d1 (unknown) for fragment a{43450288 #6 id=0x5d1}
at android.support.v4.app.FragmentManagerImpl.addAddedFragments(FragmentManagerImpl.java)
at android.support.v4.app.FragmentManagerImpl.addAddedFragments(FragmentManagerImpl.java)
at android.support.v4.app.FragmentManagerImpl.allocBackStackIndex(FragmentManagerImpl.java)
at android.support.v4.app.FragmentManagerImpl.detachFragment(FragmentManagerImpl.java)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManagerImpl.java)
at android.os.Handler.handleCallback + 808(Handler.java:808)
at android.os.Handler.dispatchMessage + 103(Handler.java:103)
at android.os.Looper.loop + 193(Looper.java:193)
at android.app.ActivityThread.main + 5345(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke + 515(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 824(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main + 640(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(NativeStart.java)
same
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1454)
android.support.v4.app.FragmentManagerImpl.addAddedFragments (FragmentManager.java:2646)
android.support.v4.app.FragmentManagerImpl.executeOpsTogether (FragmentManager.java:2416)
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManager.java:2372)
android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:2273)
android.support.v4.app.FragmentManagerImpl$1.run (FragmentManager.java:733)
android.os.Handler.handleCallback (Handler.java:789)
android.os.Handler.dispatchMessage (Handler.java:98)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6938)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
@TikiTDO your reflection hack worked for me :) do you know what possible downsides there could be?
unfortunately i found a downside to @TikiTDO's hack
repro:
first, set "Don't keep activities" flag in Developer Options on your Android device to ensure the activity is destroyed every time it goes to bg
after every return from bg, react will mount the app container anew, but any JS state you may have accumulated will still exist. In our project, this caused all kinds of non-idempotent initialization to break
@kmagiera are there any estimations on fixing this?
I have a very ugly workaround that uses reflection, but it's enough to get running.
Thanks for sharing your workaround @TikiTDO.
A quick question: is there a significance to mContainerId in your workaround?
@ariya I don't understand the question. It's significant because it's the variable that's at the root cause of the bug. I have a post higher up that explains the code flow that leads to the issue.
However, I'm not an android developer, so I can't tell you what this variable is used for or what it should be set to in any given situation. I'm just good enough with a debugger to trace a null pointer exception to it's cause. As @mvayngrib pointed out, there are fairly big problems with the workaround, so really this is just an issue that's looking for a bit of love from someone that actually knows this environment
@ariya I don't understand the question. It's significant because it's the variable that's at the root cause of the bug. I have a post higher up that explains the code flow that leads to the issue.
Thank you, that's a beautiful explanation! Now I understand better how the workaround works!
Facing this issue while opening the App after keeping it in the background for a long time.
"react-native": "0.60.4"
"react-navigation": "^4.0.7"
"react-native-screens": "2.0.0-alpha.3"

We are facing this problem after upgrading react-native from 0.61.2 from 0.61.4:
"react-native": "0.61.4"
"react-navigation": "4.0.10"
"react-native-screens": "1.0.0-alpha.23"
This also occurs with react-native-screens 2.0.0-alpha.8. Removing useScreens() / enableScreens() from App.tsx fixes the problem.
Facing this issue as well. App crash after launch.
Package versions
"react-native": "0.59.10",
"react-native-screens": "^2.0.0-alpha.3",
"react-navigation": "^4.0.7",
Android LogCat Output:
2019-11-12 05:11:25.831 9544-9544/? E/.XXXXXXXX.mobil: Invalid ID 0x000000cf.
2019-11-12 05:11:25.833 9544-9544/? E/FragmentManager: No view found for id 0xcf (unknown) for fragment ScreenFragment{f0d42bd (d8a3f0d4-362c-422b-880e-eb77c49a6194) id=0xcf}
2019-11-12 05:11:25.833 9544-9544/? E/FragmentManager: Activity state:
2019-11-12 05:11:25.868 9544-9544/? E/AndroidRuntime: FATAL EXCEPTION: main
edit: not using enableScreens() for Android resolve the crashing. But i guess that's not a way how to implement this package.
Facing this issue as well. App crash after launch.
"react-native": "0.59.9",
"react-native-screens": "^1.0.0-alpha.22",
"react-navigation": "^3.3.2",
Hi, I also experience this error after I add react-native-community/netinfo, when I turn off the connection the app crash and shown the same error.
13189 13189 D AndroidRuntime: Shutting down VM 13189 13189 E AndroidRuntime: FATAL EXCEPTION: main 13189 13189 E AndroidRuntime: Process: com.mobilesupplier, PID: 13189 13189 13189 E AndroidRuntime: java.lang.IllegalArgumentException: No view found for id 0x269 (unknown) for fragment ScreenFragment{e3a3f1e #6 id=0x269} 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454) 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2646) 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2416) 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2372) 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) 13189 13189 E AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733) 13189 13189 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:754) 13189 13189 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 13189 13189 E AndroidRuntime: at android.os.Looper.loop(Looper.java:165) 13189 13189 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6375) 13189 13189 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 13189 13189 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 13189 13189 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
is there any solution yet?
Facing this issue too. Disable react native screens and all works perfect!
Thanks everyone for contributing in this discussion. I'd love to help resolve this issue. However, before I start it would be helpful if someone form the folks experiencing the crash could come up with a repro case. I went through the comments and maybe I missed the repro being posed, the closes was this comment https://github.com/kmagiera/react-native-screens/issues/54#issuecomment-475358114 by @thomasw but it only shows some code with no repro steps and rendering the app from the comment does not seem to cause the crash.
If you are willing to help get this ticket resolve please provide a code with repro steps (instructions how to run the sample and details on your setup: what device, which RN version etc)
Hi @kmagiera, I've managed to create repro https://github.com/dominiczaq/react-native-screens-no-view-found-issue
The issue is occurring when component renders <Stack.Navigator> and while navigating the render changes to null.
It seems that there are no issues when Stacks are changing rapidly, only when the Stacks are unmounted while navigating.
@dominiczaq do you know if the merged changes fix the bug?
Yes, the fix works. I believe this issue could be closed.
Hi @WoLewicki I'm still seeing this crash on the app making use of "react-native-screens": "^2.4.0",. I've created a new issue in #463
Most helpful comment
This issue is happening because this library is not using Fragments correctly.
The issue happens when a
ScreenContaineris unmounted. When this happens it tries to disconnect all theScreeninstances here, which calls into here.However, it appears the expectation in android is that these sort of operations should be handled through the
FragmentManagerwhich will clear a bunch of private instance variables, most importantly this one.If the
ScreenContaineris removed from the view hierarchy and that id is not cleared, then the next time theFragmentManagertries to do something with thatFragmentit will attempt to find the container in the view hierarchy, which will fail and cause the above exception.