React-native-navigation: Android crashes on startup

Created on 29 Nov 2017  路  31Comments  路  Source: wix/react-native-navigation

Issue Description

Followed all the instructions for android installation but my app got crashed on the first time (no log info). The documentation is also confusing it says "In MainApplication.java, add the following", should I replace the original? merge the original?

Code Snippets

MainAplication.java

package com.beausy_mobile;

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 java.util.Arrays;
import java.util.List;

import com.reactnativenavigation.NavigationApplication;

 public class MainApplication extends NavigationApplication {

   @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
       // No need to add RnnPackage and MainReactPackage
       return Arrays.<ReactPackage>asList(
        new MainReactPackage()
           // eg. new VectorIconsPackage()
       );
   }

   @Override
   public List<ReactPackage> createAdditionalReactPackages() {
       return getPackages();
   }
}

MainActivity.java

import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {

}

index.js

import {Navigation} from 'react-native-navigation';
import {registerScreens} from './src/screens';

registerScreens();

Navigation.startTabBasedApp({
  tabs: [
    {
      label: 'Signin',
      screen: 'page.Signin',
      title: 'Signin'
    },
    {
      label: 'Home',
      screen: 'page.Home',
      title: 'Home'
    }
  ]
});


Environment

  • React Native Navigation version: 1.1.296
  • React Native version: 0.50.4
  • React Native CLI version: 2.0.1
  • Platform(s) Android

Most helpful comment

Also make sure you have changed package name on the import for BuildConfig in MainApplication.java, if you mistakenly choose to import com.facebook.BuildConfig you will end up with a similar problem.
Like import com.yourpackage.BuildConfig

All 31 comments

The latest known working version of RN is 0.49.3 at the moment. Although there is a workaround for the issues, I still recommended downgrading.

Also, you need to provide icon assets for each tab. Otherwise, the app will crash.

@pqkluan I did what you said. I downgraded RN version, and inserted the icons. Nothing seems to change though. The app is still crashing.

Could you upload the Android crash log?

It only crashes with no log. The build succeed.
image

I uploaded the repo here

I mean run-time log, not build log. Use react-native log-android at project root or Android Studio to get the run-time log.

I just take a look at your uploaded repo, there are 2 things I see:

  • You need to split the index.js into two files index.android.js and index.ios.js to make it work with RN 0.49
  • Switch to png file instead of svg as tab bar asset.

Well my build.gradle points to the index.js as entry file, thats why I put it on index.js. I've made the changes suggested (and updated the repo). The app craches and the only log I get from log-android is the following.

react-native log-android

--------- beginning of crash
--------- beginning of system
--------- beginning of main
11-29 11:37:01.304 19128 19128 D ReactNative: ReactInstanceManager.onReloadWithJSDebugger()
11-29 11:37:01.306 19128 19128 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
11-29 11:37:01.306 19128 19128 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
11-29 11:37:01.309 19128 19128 D ReactNative: ReactInstanceManager.tearDownReactContext()
11-29 11:37:01.319 19128 19128 D ReactNative: CatalystInstanceImpl.destroy() start
11-29 11:37:01.969 19128 21578 D ReactNative: ReactInstanceManager.createReactContext()
11-29 11:37:02.091 19128 21578 D ReactNative: Initializing React Xplat Bridge.
11-29 11:37:02.093 19128 21578 D ReactNative: Initializing React Xplat Bridge before initializeBridge
11-29 11:37:02.095 19128 21578 D ReactNative: Initializing React Xplat Bridge after initializeBridge
11-29 11:37:02.096 19128 21578 D ReactNative: CatalystInstanceImpl.runJSBundle()

Try this,

change your App.js file to what u did in index.android.js:

  import {Navigation} from 'react-native-navigation';
   import {registerScreens} from './src/screens';

  registerScreens();

Navigation.startTabBasedApp({
tabs: [
{
label: 'Signin',
screen: 'page.Signin',
icon: require('./src/images/icons/unlocked.png'),
title: 'Signin'
},
{
label: 'Home',
screen: 'page.Home',
icon: require('./src/images/icons/home.png'),
title: 'Home'
}
]
});

and change your index.android.js file to look like this:

 import App from './app';

Try this first, also make sure u updated your Android.manifest file like it says in the docs.

@saudpunjwani101 thanks for your help but unfortunately is still crashing (remote repo is up to date if you wanna check it) :(

Only Android is crashing?
Have you checked ios?

That project I uploaded to github is just a mock project I've created as an example. I haven't made the configuration for ios on it. Even though on my original project ios is configurated and is working great.

Okay so the problem is with android. Let me see

@wellyal Do you get any progress with the Android build?

Is there any way we can get this package to work with react-native 0.51?

It would be great if we can get this package to work with react-native 0.51. I have decided not to use react-navigation and am impressed with the react-native-navigation performance so far.

I'll close this issue since the problem was resolved in the latest build version. Feel free to re-open if needed.

Hey, having the same issue. New app keeps crashing. is it something with the recent version?

@3210jr You should check the logs in Android Studio, this might relate to Android maven or an upstream with React-Native.

If the log relates to RNN, you might want to create a new issue.

I am facing the same issue here as well

i am facing the same issue

i am also facing same issue

+1

I had the same issue and I found out that on MainActivity.java I was giving the wrong packagename as I had copied the contents of this file form another project and I forgot to change the packagename.
Maybe when you were installing the package you forgot to set the package name like :
package com.projectname;
in the beginning of the file. Also it is not mentioned in the docs (when installing for Android , step 4 & 5 ) that you should be careful with the packagename but it says to replace the contents shown in the docs with the content of both files: MainApplication.java and MainActivity.java.
That can be confusing. I learned my lesson the hard way...
Hope it helps.

Thank you @maroparo for this solution!! :D :1st_place_medal:

In my case the application loads when the phone is connected to the metro-builder, but once the phone is disconnect from the Metro-builder the application crashes.

Also make sure you have changed package name on the import for BuildConfig in MainApplication.java, if you mistakenly choose to import com.facebook.BuildConfig you will end up with a similar problem.
Like import com.yourpackage.BuildConfig

As @folofse mentioned, I imported the BuildConfig from facebook package but was supposed to import from my app's package

As @folofse mentioned, I imported the BuildConfig from facebook package but was supposed to import from my app's package

I had the same issue, and it costed me almost a full day to find the cause of the crash. Thanks @Shivendra30 and @folofse

Also make sure you have changed package name on the import for BuildConfig in MainApplication.java, if you mistakenly choose to import com.facebook.BuildConfig you will end up with a similar problem.
Like import com.yourpackage.BuildConfig

Thank you, this is a life saver

Also make sure you have changed package name on the import for BuildConfig in MainApplication.java, if you mistakenly choose to import com.facebook.BuildConfig you will end up with a similar problem.
Like import com.yourpackage.BuildConfig

Oh Man! You saved my life.

Also make sure you have changed package name on the import for BuildConfig in MainApplication.java, if you mistakenly choose to import com.facebook.BuildConfig you will end up with a similar problem.
Like import com.yourpackage.BuildConfig

You little fucking monster.
Damn man. gotta jump on the "Thanks" train too. I dont think i would have EVER figured this out. Thanks

Was this page helpful?
0 / 5 - 0 ratings