-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App crashing after restart on Android with react-native-navigation when starting app after AsyncStorage access #1088
Comments
Hi @Jay1337 and thanks for submitting the issue. Please try to replace import { AsyncStorage } from 'react-native';
import { Navigation } from 'react-native-navigation';
import React from 'react';
import { Text } from 'react-native';
import codePush from "react-native-code-push";
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<Text onPress={() => codePush.restartApp(false)}>
Touch to run codePush.restartApp and see the crash
</Text>
);
}
}
Navigation.registerComponent('app', () => codePush(App));
AsyncStorage.getItem('environment', () => {
Navigation.startSingleScreenApp({
screen: {
screen: 'app',
},
passProps: { },
});
}); Let us know if it helps. |
Thanks for your help. With your code, the app does not crash. An other interesting case that makes the app crash:
Here are the logs:
My feeling is that everything is not perfectly cleared before starting the app again (previous app id expected by RN) and also the app is not started again the good RN Navigation way (RN should not expect any app id to be registered since with RNN there is no |
As documentation for react-native-navigation said,
I believe, you have to place |
@ruslan-bikkinin, with registration after AsynStorage, everything works find except CodePush restart (that's why I've posted an issue here). Also everything is ok on iOS. So it's not a bad implementation of RNN. I think that the way CodePush restarts the app is not compatible with RNN screens registration. Again, it's strange that RN expects a specific app id to be registered. Have you tried to reproduce the bug on your side ? As for |
Hi @Jay1337 sorry for late response. After further investigation, yeah, I believe you was right, something isn't clearing up completely after |
@ruslan-bikkinin Thanks for this update. |
@Jay1337 JFYI we've created issue in react-native-navigation repo as we have no clues what could be the source of problem and whether that approach for screen registration (generate random name on each programmatic restart) is valid or not. No worries, we will be able to continue investigation as we'll get help/response from folks from RNN. |
@ruslan-bikkinin thanks a lot for the update and for your precious help. |
@ruslan-bikkinin Is their anywhere I can go to find the correct MainApplication.java and MainActivity.java with CodePush and React Native Navigation? We had no problems with code push before integrating react-native-navigation, but after we are experiencing this same issue on android only - iOS has been working great! |
@ruslan-bikkinin here are mine:
|
@die20 @Jay1337 The correct way to integrate CodePush SDK into RNN application is the following:
import com.facebook.react.ReactActivity;
import com.reactnativenavigation.controllers.SplashActivity;
public class MainActivity extends SplashActivity {
}
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.microsoft.codepush.react.CodePush;
import com.reactnativenavigation.NavigationApplication;
import com.microsoft.codepush.react.ReactInstanceHolder;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication implements ReactInstanceHolder {
@Override
public boolean isDebug() {
// Make sure you are using BuildConfig from your own application
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
return Arrays.<ReactPackage>asList(
new CodePush("deployment-key-here", getApplicationContext(), BuildConfig.DEBUG)
);
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
@Override
public String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
public String getJSMainModuleName() {
return "index";
}
@Override
public ReactInstanceManager getReactInstanceManager() {
return getReactNativeHost().getReactInstanceManager();
}
} |
@ruslan-bikkinin the only difference is the use of |
@Jay1337 We should use it because CodePush must be told how to find React Native instance. In RNN case you can implement |
@ruslan-bikkinin Thanks for that info! - I came across issue #1096 but when I add ReactInstanceManager I get this build error on android
I'm using |
@die20 just add |
Thanks @Jay1337 that worked! |
I'm so glad I found that issue, I thought I was the only one experiencing this error.
So do you think adding |
It is required for RNN apps which is using CodePush. Please add it and let us know if it helps you. |
Hey @Jay1337, sorry for the delayed response, I’ve investigated this issue once again and unfortunately I cannot see any simple and reliable ways to resolve it right now, so please let me know if you have any ideas how we could avoid this issue. Anyway we’ll try to get any feedback from As for now, since your use case looks very specific and we haven’t received such kind of issues before - we are going to close it and focus on other hight priority features. But please feel free to reopen the issue if you have any news or ideas how to resolve it, we’ll also reopen this issue in case of a lot of similar requests. |
@ruslan-bikkinin thanks for the news. I understand your decision. I don't have any idea how to resolve that... |
@ruslan-bikkinin Nope, the problem isn't resolved, after adding that code I still received the same crash on Thanks! |
@SudoPlz You must NOT wait for AsyncStorage before registering screens. |
Good, thanks, I'll try that and post back if it worked. On the mean time, I guess we can disable force-restarting the app. Perhaps downloading the patch but updating the next time the app starts naturally might be a good way around that issue until it's resolved, since that won't force the app to restart and thus crash. |
Unfortunately that doesn't do it for me, I'm still getting the crash after downloading an update even with ON_NEXT_RESTART install mode. |
So that solution did work for me. I'm no longer receiving a crash. |
@SudoPlz Thanks for the tip, I'll try that. Do you also call startTabBasedApp (or startSingleScreenApp) before the code push update happens as well? |
I'm using |
It does work after I move the call to codePush.sync after registerScreens and wait for the Promise to complete before calling startTabBasedApp. Thanks! |
I did what you suggested but navigation is not working for me. Here are the logs I get
|
Steps to Reproduce
index.js
as following:Expected Behavior
App restarts
Actual Behavior
App crashes with error:
It's similar to #852
It also crashes after an immediate update.
Reproducible Demo
Cf repro steps.
Environment
+-- react@16.0.0
+-- react-native@0.50.4
+-- react-native-code-push@5.2.0-beta
+-- react-native-navigation@1.1.295
I really need to access AsyncStorage before starting the app to decide which screen display to the user.
Thanks for your help !
The text was updated successfully, but these errors were encountered: