react-native-splash-screen icon indicating copy to clipboard operation
react-native-splash-screen copied to clipboard

Android App Crashing on Open

Open GenericJam opened this issue 7 years ago • 66 comments

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

GenericJam avatar Jan 30 '18 17:01 GenericJam

works for me, thank you.

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

ma-pe avatar Jan 31 '18 12:01 ma-pe

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

MurugappanV avatar Jan 31 '18 18:01 MurugappanV

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

GenericJam avatar Jan 31 '18 23:01 GenericJam

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

victorighalo avatar Feb 01 '18 05:02 victorighalo

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

ma-pe avatar Feb 01 '18 10:02 ma-pe

I use the version 3.0.1, it working

MonkeyInWind0 avatar Feb 03 '18 01:02 MonkeyInWind0

@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 avatar Feb 03 '18 09:02 amitbravo

@amitbravo install sdk 25.0.1

MonkeyInWind0 avatar Feb 04 '18 00:02 MonkeyInWind0

and target sdk too ?

amitbravo avatar Feb 04 '18 09:02 amitbravo

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

amitbravo avatar Feb 04 '18 10:02 amitbravo

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

holumyn avatar Feb 08 '18 14:02 holumyn

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

MrChinmaya avatar Feb 08 '18 15:02 MrChinmaya

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>

ethan6077 avatar Feb 08 '18 22:02 ethan6077

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

sadi304 avatar Feb 11 '18 12:02 sadi304

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

brownieboy avatar Feb 20 '18 22:02 brownieboy

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

Much appreciated.

okeeffed avatar Feb 21 '18 05:02 okeeffed

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 avatar Mar 06 '18 20:03 tlloydukdev

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

callmetwan avatar Mar 09 '18 18:03 callmetwan

Not yet I’m afraid 😪

tlloydukdev avatar Mar 09 '18 18:03 tlloydukdev

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.

noahtallen avatar Mar 14 '18 20:03 noahtallen

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

tlloydukdev avatar Mar 14 '18 20:03 tlloydukdev

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

callmetwan avatar Mar 14 '18 20:03 callmetwan

@callmetwan I'm using 0.54 rc3 if it helps

tlloydukdev avatar Mar 14 '18 20:03 tlloydukdev

@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 avatar Mar 14 '18 21:03 noahtallen

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

noahtallen avatar Mar 14 '18 21:03 noahtallen

@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

GenericJam avatar Mar 14 '18 21:03 GenericJam

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.

hansen94 avatar Mar 17 '18 15:03 hansen94

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;

asinel avatar Mar 21 '18 20:03 asinel

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

tlloydukdev avatar Mar 25 '18 15:03 tlloydukdev

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

kaammii avatar Mar 25 '18 20:03 kaammii