react-native-splash-screen: Android App Crashing on Open

For anyone with this issue I spent a bit of time trying to figure out how to solve it. This library works well for me on ios and I didn’t want to have two different libraries for the different operating systems. If you are having this issue, in MainActivity.java: instead of SplashScreen.show(this); use SplashScreen.show(this, true);

The problem is in the supporting Java file, SplashScreen.java. This is the default call which calls another method called show(final Activity activity, final boolean fullScreen). public static void show(final Activity activity) { show(activity, false); }

Because it calls it with ‘false’, the second style is used which React Native can’t figure out and it crashes. on line ~31 `mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme);’

If you just call show(final Activity activity, final boolean fullScreen) directly with ‘true’ as the second argument, it should be able to figure out the first style and it will work.

Please update the documentation

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 10
  • Comments: 63 (1 by maintainers)

Most upvoted comments

Yes, adding “android/app/src/main/res/values/colors.xml” solved the problem. Just add a “primary_dark” value to the file like this.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary_dark">#000000</color>
</resources>

crashing even after changing to SplashScreen.show(this, true);

This works for me

In MainActivity.java use SplashScreen.show(this, true); instead of SplashScreen.show(this);

Then, go to node_modules>react-native-splash-screen>android>src> >SplashScreen.java

Replace mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme); with mSplashDialog = new Dialog(activity, R.layout.launch_screen);

I hope this helps someone

Fixed it:

  • added multiDexEnabled true in the defaultConfig of the build.gradle and compile 'com.android.support:multidex:1.0.1'
  • added import android.support.multidex.MultiDex; and MultiDex.install(this); on the onCreate of the MainApplication.java

I am having the same problem but none of the suggestions here have helped.

Using v3.0.6 and React Native 0.54, API 26. I get no build errors but with this in MainActivity.java the app crashes as soon as it starts. If I uncomment it, all is good again.

@Override
   protected void onCreate(Bundle savedInstanceState) {
       SplashScreen.show(this, true);
       super.onCreate(savedInstanceState);
   }

The only other thing perhaps to note is there is also an onCreate in MainApplication.java

@Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
  }

I also updated the SplashScreen.java as suggested above, tried it with SplashScreen.show(true) too.

I had a missing colors.xml so created that too but no difference.

Any other thoughts ? It’s all working perfectly with iOS

this is solved by creating the file: android/app/src/main/res/values/colors.xml <resources> <color name="primary_dark"></color> </resources>

Hi, guys, in react-native ^0.60.0 and react-native-splash-screen ^3.2.0, I face the same problem. I solve this issue with:

  1. change the code SplashScreen.show(this) with SplashScreen.show(this, true) in android/app/src/main/java/com/yourapp/MainActivity.java :

@Override protected void onCreate(Bundle savedInstanceState) { SplashScreen.show(this, true); // change here super.onCreate(savedInstanceState); }

  1. add a launch_screen.xml in your android/app/src/main/res/layout folder with code :

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/launch_screen" android:orientation="vertical"> </LinearLayout>

  1. add colors.xml in your android/app/src/main/res/values folder with code:

<?xml version="1.0" encoding="utf-8"?> <resources> <color name="primary_dark">#000000</color> </resources>

The README or guide document should be updated.

Good luck.

Not sure how I missed it the first time around but there’s a section under Getting Started for Android here https://github.com/crazycodeboy/react-native-splash-screen which describes creating a launch_screen.xml file and adding an image to the drawable folder (had to manually create this). I’m no longer getting the crashing now

Problem Solved By Compress the Resolutions.!

My App Crashed Because I haven’t used the exact resolution size of splash screen, So Your App Maybe crash because of that also, you just have to use correct splash screen for every layout .! 😃

This still happens in my app when running it in 4.X android.

  • SplashScreen.show(this, true); done
  • colors.xml done
  • launch_screen.xml done
  • mSplashDialog = new Dialog(activity, R.layout.launch_screen); done

still not not working with java.lang.NoClassDefFoundError: org.devio.rn.splashscreen.SplashScreen

Also, downgrading to 3.0.1 also not working… My RN version is 0.54.4

I used another way to solve this issues, First) in MainActivity.java: instead of SplashScreen.show(this); use SplashScreen.show(this, true);

Second) in node_modules/react-native-splash-screen/android/src/main/res/values/styles.xml add these styles

<resources>
    <style name="SplashScreen_SplashAnimation">
        <item name="android:windowExitAnimation">@android:anim/fade_out</item>
    </style>

    <style name="SplashScreen_SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowAnimationStyle">@style/SplashScreen_SplashAnimation</item>
    </style>
    <style name="SplashScreen_Fullscreen" parent="SplashScreen_SplashTheme">
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>

you can check here 👍

I tried but This is the error i get. error: cannot find symbol mSplashDialog = new Dialog(activity, R.layout.layout_screen);

The reason my app was crashing was because the image size was too large. Compressing the image and then moving it to drawable-xxhdpi folder fixes it.

colors.xml contributors you definitely saved me from what I could only image would have turned into a few hours.

Much appreciated.

Hello guys! I was also having crashes on app start in Android. I followed this guide and now it is working correctly:

https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae

In my case I think I was missing the launch_screen.xml file inside android/app/src/main/res/layout

Adding the colors.xml fixed it for me too.

This definitely needs addressing the Readme. The way it’s written there, it looks like colors.xml is an optional extra, only “if you want to customize the color of the status bar”.

solved by adding colors.xml file. should be mentioned in the DOCS i guess if app crashes on first time .

My coworkers have spent over a day on this so far (no results yet). Pretty insane considering it’s just a splash screen.

SplashScreen.show(this, true); fixed it for me as well as creating colors.xml

I use the version 3.0.1, it working

Hello guys! I was also having crashes on app start in Android. I followed this guide and now it is working correctly:

https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae

In my case I think I was missing the launch_screen.xml file inside android/app/src/main/res/layout

ah, it turns out to be a trivial problem, maybe I don’t drink enough coffee for this. haha

thanks @ruipneves

I just follow this link step by step and every thing solved from me

the problem was that I must add a layout folder inside res and an launch_screen.xml file so the names are important

Hey if anyone still struggling, follow the below step:

  1. Please check you have colors.xml and <color name="primary_dark">#4F6D7A</color> added in the file. This is a bug in splash screen package so be aware of it.

  2. Please check do you have launch_screen.xml file in res/layout/launch_screen.xml folder. (if you don’t have this file and folder create it under res dir). Below is the code you can use <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primary_dark" android:gravity="center"> <ImageView android:layout_width="300dp" android:layout_height="300dp" android:layout_marginTop="24dp" android:src="@mipmap/splash_icon" /> </LinearLayout>

please note you have to change splash_icon with the name of your icon image and primary_dark according to what you set up in the colors.xml.

Follow the below tutorial if you still have doubts. (scroll all the way down to see the crash fix ) https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae

I’m having crashing issue with RN 0.60.0 and splash screen 3.2.0 App crashed after splash screen before loading init screen.

This is what i got in the crashlytics logs.

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.****/com.****.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Bundle.unparcel()' on a null object reference at android.app.ActivityThread.performLaunchActivity + 3037(ActivityThread.java:3037) at android.app.ActivityThread.handleLaunchActivity + 3172(ActivityThread.java:3172) at android.app.servertransaction.LaunchActivityItem.execute + 78(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks + 108(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute + 68(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage + 1906(ActivityThread.java:1906) at android.os.Handler.dispatchMessage + 106(Handler.java:106) at android.os.Looper.loop + 193(Looper.java:193) at android.app.ActivityThread.main + 6863(ActivityThread.java:6863) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 537(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main + 858(ZygoteInit.java:858)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Bundle.unparcel()' on a null object reference at android.os.Bundle.putAll + 289(Bundle.java:289) at android.content.Intent.putExtras + 9034(Intent.java:9034) at com.gudppl.SplashActivity.onCreate + 18(SplashActivity.java:18) at android.app.Activity.performCreate + 7149(Activity.java:7149) at android.app.Activity.performCreate + 7140(Activity.java:7140) at android.app.Instrumentation.callActivityOnCreate + 1288(Instrumentation.java:1288) at android.app.ActivityThread.performLaunchActivity + 3017(ActivityThread.java:3017) at android.app.ActivityThread.handleLaunchActivity + 3172(ActivityThread.java:3172) at android.app.servertransaction.LaunchActivityItem.execute + 78(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks + 108(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute + 68(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage + 1906(ActivityThread.java:1906) at android.os.Handler.dispatchMessage + 106(Handler.java:106) at android.os.Looper.loop + 193(Looper.java:193) at android.app.ActivityThread.main + 6863(ActivityThread.java:6863) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 537(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main + 858(ZygoteInit.java:858)

anyone found workaround for this issue?

I was able to fix this issue. issue was not the splash screen. I was using FCM messaging and in the splashActivity.java passed getIntent.getExtras() to the next screen.

if (getIntent().getExtras() != null) { intent.putExtras(getIntent().getExtras()); // Pass along FCM messages/notifications etc. }

Fix was, just added null check to the getIntent().getExtras()

for me it was adding this to MainApplication.java on top of other changes listed by @albert-carreras

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

Had a similar issue. The launch_screen.xml in the github page for react-native-splash-screen fixed my issue as well.

Yeah, was pretty confused. It doesn’t quite seem like we should be adding the onCreate() method (it does not exist previously) to our main activity, since react native doesn’t include it there. I could be wrong, though, I’m not sure how react native deals with those two files.

Adding the color file does stop the crash for me, though.

@MurugappanV If it isn’t crashing at the very beginning this probably isn’t the problem. If you don’t need your project to be portable (like storing in a repo not with the node_module folder), you can alter the SplashScreen.java file directly in the node_modules. It will be at node_modules>react-native-splash-screen>android>src> <other folders> >SplashScreen.java Modify mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme); to mSplashDialog = new Dialog(activity, R.layout.layout_screen); That was the first modification that I did that worked. If you have made the layout_screen.xml as the install instructions say it will find that one and use it to make your image full screen. The layout screen goes in android>app>src>main>res>layout>layout_screen.xml.

If this doesn’t work it could be a multitude of other things or not even a problem with this library.