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

Created on 30 Jan 2018  ·  57Comments  ·  Source: crazycodeboy/react-native-splash-screen

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

Most helpful comment

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>

All 57 comments

works for me, thank you.

edit: it was not... as mentioned below.

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

@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> >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.

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

After some further testing I have to admit that it is not working :( Seems that there were some files not up-to-date yesterday.

I use the version 3.0.1, it working

@MonkeyInWind , Okay , I am going to give it a try however, I see "Upgrade build tools to 25.0.1" in 3.0.1 release note, is this anything have to do with my build tool ? I am still using 23.0.1

@amitbravo install sdk 25.0.1

and target sdk too ?

my ../android/app/build.gradle file is something like

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {

    applicationId "au.com.myapp"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    vectorDrawables.useSupportLibrary = true
     multiDexEnabled true
}

dexOptions {
incremental true
javaMaxHeapSize "4G"
}
....
...

I already installed almost all build tools , which would be best to choose .

screen shot 2018-02-04 at 3 11 17 pm

screen shot 2018-02-04 at 3 11 58 pm

I am already using another dep. react-native-permissions which is requiring following requirements

android {
compileSdkVersion 23 // ← set at least 23
buildToolsVersion "23.0.1" // ← set at least 23.0.0

defaultConfig {
minSdkVersion 16
targetSdkVersion 23 // ← set at least 23
// ...

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

this is solved by creating the file: android/app/src/main/res/values/colors.xml

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>

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

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".

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

Much appreciated.

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

@tlloydukdev Were you able to find a solution? I'm running into the same thing.

Not yet I’m afraid 😪

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.

Unfortunately I don't know much about native Android dev... have you managed to get around it yet ?

@ntomallen Interesting. What version of React Native are you running?

@callmetwan I'm using 0.54 rc3 if it helps

@callmetwan I'm on 0.53.3. I'm actually not sure if everything is resolved yet. First, the image doesn't seem to show up when loading - it just shows a gray background. And then, everything in the app is basically just showing white... but for some reason the few text elements I'm putting in to debug will render properly. Something got f-d up along the way but I'm not sure where it is

Got most of the stuff rendering, but my image still isn't showing up on the splash screen

@ntomallen I'd recommend using Android Studio for that type of stuff. It makes it obvious if Android can see it or not as it will show up in the ide.
See for reference - https://youtu.be/yFrx8HZlNtI?t=4m25s

I also run into this crashing problem on android. After trying all the solutions on this thread, I am still getting the crash. I checked on the logcat on Android Studio and i am getting an error with something like "Resource ID is not valid" (sorry i did not copy it when i see it)

Then i clean my project and now i am not getting the crash anymore.
Seems like Android studio somehow cannot find the "primary_dark" color that I added.
Cleaning the project fixed it for me.
Sorry if my explanation is not too clear.
Hope this help someone.

03-21 21:44:52.180 23477 23477 E AndroidRuntime: FATAL EXCEPTION: main 03-21 21:44:52.180 23477 23477 E AndroidRuntime: Process: com.stag, PID: 23477 03-21 21:44:52.180 23477 23477 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stag/com.stag.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f04002a type #0x1 is not valid 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.os.Looper.loop(Looper.java:156) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6577) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04002a type #0x1 is not valid 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.content.res.Resources.loadXmlResourceParser(Resources.java:2192) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.content.res.Resources.getLayout(Resources.java:1178) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:424) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:454) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:290) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.Dialog.setContentView(Dialog.java:637) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.Activity.runOnUiThread(Activity.java:6091) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:26) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at com.stag.MainActivity.onCreate(MainActivity.java:20) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6910) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746) 03-21 21:44:52.180 23477 23477 E AndroidRuntime: ... 9 more
Same problem as @hansen94 tells

Resource with this id:
public static final int launch_screen=0x7f04002a;

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

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

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

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

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 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 will try different solutions and it seems that the English readme is not in sync with the other Readme

Confirming adding:

<color name="primary_dark">#000000</color>

to res/values/colors.xml works.

Can you show your working MainActivity.java? Mine dosn't not have "protected void onCreate(Bundle savedInstanceState)"

Nothing above worked for me, still crashing with SplashScreen.show(...); with 3.0.7 and also 3.0.1. I'll have to use another method.

Adding this in case it helps someone in the future. For me, I had to _update the multidex dependency_ for this to work (I did all the suggestions above and still didn't work).

implementation 'com.android.support:multidex:1.0.3' // this works

implementation 'com.android.support:multidex:1.0.2' // this doesn't work and crashes the app

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);
}

@asinel this step fixed what your seeing for me:
Unable to start activity ComponentInfo I had to do what is described in this step:
https://github.com/crazycodeboy/react-native-splash-screen#getting-started

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.

  • MultiDex.install(this)

This worked for me!

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 .! :)

@rahuljograna's solution worked for me! Using a smaller image did the trick.
[email protected]
[email protected]

03-09 22:14:38.384 28230-28230/com.base_proj2 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.base_proj2, PID: 28230 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.base_proj2/com.base_proj2.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001e type #0x1 is not valid at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404) at android.app.ActivityThread.access$900(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5296) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001e type #0x1 is not valid at android.content.res.Resources.loadXmlResourceParser(Resources.java:2754) at android.content.res.Resources.getLayout(Resources.java:1129) at android.view.LayoutInflater.inflate(LayoutInflater.java:416) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378) at android.app.Dialog.setContentView(Dialog.java:490) at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32) at android.app.Activity.runOnUiThread(Activity.java:5396) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49) at com.base_proj2.MainActivity.onCreate(MainActivity.java:17) at android.app.Activity.performCreate(Activity.java:6093)

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

This has been forked a number of times. I imagine someone had solved it in a fork that could work for you. For example:
https://github.com/GamgeeNL/react-native-splash-screen

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

When running on production, Firebase it's giving the follow log:

Fatal Exception: java.lang.NoClassDefFoundError: org.devio.rn.splashscreen.SplashScreen
       at com.myapp.MainActivity.onCreate + 36(MainActivity.java:36)
       at android.app.Activity.performCreate + 5372(Activity.java:5372)
       at android.app.Instrumentation.callActivityOnCreate + 1104(Instrumentation.java:1104)
       at android.app.ActivityThread.performLaunchActivity + 2257(ActivityThread.java:2257)
       at android.app.ActivityThread.handleLaunchActivity + 2349(ActivityThread.java:2349)
       at android.app.ActivityThread.access$700 + 159(ActivityThread.java:159)
       at android.app.ActivityThread$H.handleMessage + 1316(ActivityThread.java:1316)
       at android.os.Handler.dispatchMessage + 99(Handler.java:99)
       at android.os.Looper.loop + 176(Looper.java:176)
       at android.app.ActivityThread.main + 5419(ActivityThread.java:5419)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke + 525(Method.java:525)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1046(ZygoteInit.java:1046)
       at com.android.internal.os.ZygoteInit.main + 862(ZygoteInit.java:862)
       at dalvik.system.NativeStart.main(NativeStart.java)

https://github.com/crazycodeboy/react-native-splash-screen/issues/184
https://github.com/crazycodeboy/react-native-splash-screen/issues/174

"react": "16.8.6",
"react-native": "0.60.4",
"react-native-splash-screen": "^3.2.0",

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.

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'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()

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

2020-01-18 22:14:49.449 3995-3995/com.example.splash E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.splash, PID: 3995
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.splash/com.example.splash.Splash}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.splash-jdd_1hH7R2Xr-3h34DhqLA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.splash-jdd_1hH7R2Xr-3h34DhqLA==/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:428)
at android.app.Activity.setContentView(Activity.java:2683)
at com.example.splash.Splash.onCreate(Splash.java:29)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

After changing the color.xml
Still not work
I dont have MainActivity only have Splash.ava and Xml

Splash.Java
package com.example.splash;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import static com.example.splash.R.*;

public class Splash extends FragmentActivity {

private Animation animation;
private ImageView logo;
private TextView appTitle;
private TextView appSlogan;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    logo = findViewById(R.id.logo);
    appTitle = findViewById(R.id.grocery);
    appSlogan = findViewById(R.id.slogan);





    if (ConnectivityReceiver.isConnected()) {

        if (savedInstanceState == null) {
            flyIn();
        }

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                endSplash();
            }
        }, 3000);


    } else {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("No Internet Connection ");
        builder.setMessage("Do you want to go to settings");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

                Intent j = new Intent(Settings.ACTION_WIFI_SETTINGS);
                startActivity(j);
                System.exit(0);
            }
        });

        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
                System.exit(0);
            }
        });
        builder.show();
    }










}

private void flyIn() {
    animation = AnimationUtils.loadAnimation(this, anim.logo_animation);
    logo.startAnimation(animation);

    animation = AnimationUtils.loadAnimation(this,
            anim.app_name_animation);
    appTitle.startAnimation(animation);

    animation = AnimationUtils.loadAnimation(this, anim.pro_animation);
    appSlogan.startAnimation(animation);
}

private void endSplash() {
    animation = AnimationUtils.loadAnimation(this,
            anim.logo_animation_back);
    logo.startAnimation(animation);

    animation = AnimationUtils.loadAnimation(this,
            anim.app_name_animation_back);
    appTitle.startAnimation(animation);

    animation = AnimationUtils.loadAnimation(this,
            anim.pro_animation_back);
    appSlogan.startAnimation(animation);

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {

            Intent intent = new Intent(getApplicationContext(),
                    StartActivity.class);
            startActivity(intent);
            finish();
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

}

@Override
public void onBackPressed() {
    // Do nothing
}

}

activity_Splash.xml


xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context="Splash">

<TextView
    android:id="@+id/grocery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:text="@string/app_name"
    android:textColor="@color/color_black_light"
    android:textSize="32sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/logo" />

<TextView
    android:id="@+id/slogan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/slogan"
    android:textColor="@color/color_black"
    android:textSize="14sp"
    android:textStyle="normal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/grocery" />


<ImageView
    android:id="@+id/logo"
    android:layout_width="133dp"
    android:layout_height="150dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:src="@drawable/icon"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.100000024" />

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_width="250sp"
    android:layout_height="250dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.7"
    app:lottie_autoPlay="true"
    app:lottie_loop="true"
    app:lottie_rawRes="@raw/loading" />

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

Hello,

I had issues with SplashScreen for Android API 24 only. The issue i had came from having this as a style in my application.

 <style name="SplashTheme" parent="Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@layout/launch_screen</item>
    </style>

☝🏻 NOTE: Having <item name="android:windowBackground">@layout/launch_screen</item> crashed the application, since layout is actually a ConstraintLayout and not a drawable.

Aside

Taking care of the blank screen on load, which actually feels like a lag
I set the above theme(SplashTheme) as my MainApplication Theme, after which i set a theme without a background. This way i don't need to create an Activity for SplashScreen.

// MainActivity
@Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashScreenTheme);
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
  }

Here's my complete styles.xml file

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:textColor">#000000</item>
    </style>

    <style name="SplashTheme" parent="Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@layout/launch_screen</item>
    </style>

    <style name="SplashScreenTheme" parent="Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen">
        <item name="android:windowBackground">@android:color/white</item>
    </style>
</resources>

Pass SplashTheme as Application Theme

    <application
        android:name=".MainApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/SplashTheme">
        <activity
            android:name=".MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

Back to the earlier Issue

I solved it by creating a style for API 24 specific and omitting the <item name="android:windowBackground">@layout/launch_screen</item> entry.

Now my app feels like it lags onload for API 24 devices. 😕
Please if you know another way to set background, or view from the theme, i would love that, please tag me as it will help me make my app feel less laggy. 😁

Here's stack trace for SEO 😅

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.s7care, PID: 4924
    java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.s7care/com.s7care.MainActivity}: 
android.content.res.Resources$NotFoundException: Drawable com.s7care:layout/launch_screen 
with resource ID #0x7f0b002e
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
     Caused by: android.content.res.Resources$NotFoundException: Drawable 
com.s7care:layout/launch_screen with resource ID #0x7f0b002e
     Caused by: android.content.res.Resources$NotFoundException: File res/layout/launch_screen.xml 
from drawable resource ID #0x7f0b002e
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:775)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)
        at android.content.res.Resources.getDrawable(Resources.java:1640)
        at android.content.res.XResources.getDrawable(XResources.java:790)
        at android.content.Context.getDrawable(Context.java:525)
        at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2807)
        at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2857)
        at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2167)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97)
        at android.app.Dialog.show(Dialog.java:419)
        at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36)
        at android.app.Activity.runOnUiThread(Activity.java:6045)
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27)
        at com.s7care.MainActivity.onCreate(MainActivity.java:21)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
     Caused by: android.view.InflateException: Class is not a Drawable 
androidx.constraintlayout.widget.ConstraintLayout
        at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:204)
        at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:132)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1251)
        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1224)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:765)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621) 
        at android.content.res.Resources.getDrawable(Resources.java:1640) 
        at android.content.res.XResources.getDrawable(XResources.java:790) 
        at android.content.Context.getDrawable(Context.java:525) 
        at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2807) 
        at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2857) 
        at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2167) 
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346) 
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97) 
        at android.app.Dialog.show(Dialog.java:419) 
        at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36) 
        at android.app.Activity.runOnUiThread(Activity.java:6045) 
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27) 
        at com.s7care.MainActivity.onCreate(MainActivity.java:21) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107) 
     Caused by: java.lang.ClassCastException: class androidx.constraintlayout.widget.ConstraintLayout 
cannot be cast to android.graphics.drawable.Drawable
        at java.lang.Class.asSubclass(Class.java:2340)
        at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:191)
        at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:132) 
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1251) 
        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1224) 
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:765) 
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621) 
        at android.content.res.Resources.getDrawable(Resources.java:1640) 
        at android.content.res.XResources.getDrawable(XResources.java:790) 
        at android.content.Context.getDrawable(Context.java:525) 
        at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2807) 
        at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2857) 
        at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2167) 
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346) 
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97) 
        at android.app.Dialog.show(Dialog.java:419) 
        at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36) 
        at android.app.Activity.runOnUiThread(Activity.java:6045) 
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27) 
        at com.s7care.MainActivity.onCreate(MainActivity.java:21) 
        at android.app.Activity.performCreate(Activity.java:6942) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107) 
Was this page helpful?
0 / 5 - 0 ratings