crazycodeboy / react-native-splash-screen

A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
MIT License
5.59k stars 1.09k forks source link

Android App Crashing on Open #167

Open GenericJam opened 6 years ago

GenericJam commented 6 years ago

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

ma-pe commented 6 years ago

works for me, thank you.

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

MurugappanV commented 6 years ago

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

GenericJam commented 6 years ago

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

victorighalo commented 6 years ago

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

ma-pe commented 6 years ago

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

MonkeyInWind commented 6 years ago

I use the version 3.0.1, it working

amitbravo commented 6 years ago

@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

MonkeyInWind commented 6 years ago

@amitbravo install sdk 25.0.1

amitbravo commented 6 years ago

and target sdk too ?

amitbravo commented 6 years ago

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

holumyn commented 6 years ago

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

MrChinmaya commented 6 years ago

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

ethan6077 commented 6 years ago

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>
sadi304 commented 6 years ago

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

brownieboy commented 6 years ago

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

okeeffed commented 6 years ago

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

Much appreciated.

tlloydukdev commented 6 years ago

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

callmetwan commented 6 years ago

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

tlloydukdev commented 6 years ago

Not yet I’m afraid 😪

noahtallen commented 6 years ago

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.

tlloydukdev commented 6 years ago

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

callmetwan commented 6 years ago

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

tlloydukdev commented 6 years ago

@callmetwan I'm using 0.54 rc3 if it helps

noahtallen commented 6 years ago

@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

noahtallen commented 6 years ago

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

GenericJam commented 6 years ago

@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

hansen94 commented 6 years ago

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.

asinel commented 6 years ago

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;

tlloydukdev commented 6 years ago

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

kaammii commented 6 years ago

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

SirPhemmiey commented 6 years ago

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

albert-carreras commented 6 years ago

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

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

albert-carreras commented 6 years ago

Fixed it:

aeskafi commented 6 years ago

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 👍

efleurine commented 6 years ago

I will try different solutions and it seems that the English readme is not in sync with the other Readme

iRoachie commented 6 years ago

Confirming adding:

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

to res/values/colors.xml works.

rendomnet commented 6 years ago

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

rodrigofbm commented 6 years ago

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.

Eyesonly88 commented 6 years ago

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
brycepavey commented 6 years ago

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);
}
aaronshier commented 6 years ago

@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

kevupton commented 5 years ago

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.

girish-sm commented 5 years ago
  • MultiDex.install(this)

This worked for me!

rahuljograna commented 5 years ago

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

dylanrhodius commented 5 years ago

@rahuljograna's solution worked for me! Using a smaller image did the trick. rn@0.50.3 react-native-splash-screen@3.0.1

Biplovkumar commented 5 years ago

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)

AdamZaczek commented 5 years ago

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

GenericJam commented 5 years ago

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

ruipneves commented 5 years ago

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

rochapablo commented 5 years ago

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