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)
Yes, adding “android/app/src/main/res/values/colors.xml” solved the problem. Just add a “primary_dark” value to the file like this.
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:
multiDexEnabled truein the defaultConfig of the build.gradle andcompile 'com.android.support:multidex:1.0.1'import android.support.multidex.MultiDex;andMultiDex.install(this);on the onCreate of the MainApplication.javaI 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.
The only other thing perhaps to note is there is also an onCreate in MainApplication.java
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.0andreact-native-splash-screen^3.2.0, I face the same problem. I solve this issue with:SplashScreen.show(this)withSplashScreen.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); }launch_screen.xmlin yourandroid/app/src/main/res/layoutfolder 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>android/app/src/main/res/valuesfolder 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);donecolors.xmldonelaunch_screen.xmldonemSplashDialog = new Dialog(activity, R.layout.launch_screen);donestill not not working with
java.lang.NoClassDefFoundError: org.devio.rn.splashscreen.SplashScreenAlso, 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);useSplashScreen.show(this, true);Second) in
node_modules/react-native-splash-screen/android/src/main/res/values/styles.xmladd these stylesyou 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-xxhdpifolder 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.xmlfile insideandroid/app/src/main/res/layoutAdding 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 creatingcolors.xmlI use the version 3.0.1, it working
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:
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.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 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.javaon top of other changes listed by @albert-carrerasHad 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);tomSplashDialog = 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.