react-native-splash-screen
react-native-splash-screen copied to clipboard
MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView
Hello.
When I start my app compiled in release mode I've got this error :
Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): android.view.WindowLeaked: Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
E/WindowManager(25826): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
E/WindowManager(25826): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager(25826): at android.app.Dialog.show(Dialog.java:281)
E/WindowManager(25826): at com.cboy.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32)
E/WindowManager(25826): at android.app.Activity.runOnUiThread(Activity.java:4662)
E/WindowManager(25826): at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:22)
E/WindowManager(25826): at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:42)
E/WindowManager(25826): at com.myapp.MainActivity.onCreate(MainActivity.java:11)
E/WindowManager(25826): at android.app.Activity.performCreate(Activity.java:5122)
E/WindowManager(25826): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
E/WindowManager(25826): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
E/WindowManager(25826): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/WindowManager(25826): at android.app.ActivityThread.access$600(ActivityThread.java:156)
E/WindowManager(25826): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
E/WindowManager(25826): at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager(25826): at android.os.Looper.loop(Looper.java:153)
E/WindowManager(25826): at android.app.ActivityThread.main(ActivityThread.java:5299)
E/WindowManager(25826): at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(25826): at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(25826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/WindowManager(25826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/WindowManager(25826): at dalvik.system.NativeStart.main(Native Method)
I fix it with the following code in the MainActivity.java
:
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
// my new code here
@Override
protected void onPause() {
SplashScreen.hide(this);
super.onPause();
}
I can't confirm that it's the best solution but it works !
I'm having the same problem over here, I tried the solution that you suggested but it didn't work. Did you find something else? Any help would be great :)
Hi, if someone else have troubles with this maybe my experience help.
I tried a lot of things, and nothing worked until I found this steps for generating a release APK on React Native official documentation:
https://facebook.github.io/react-native/docs/signed-apk-android.html
I followed the step by step and tested the APK on my phone and now everything is working. I really don't understand why using './gradlew assembleRelease' and generating the signed APK with the Android Studio didn't work with the splash screen but with this other way of generating the APK worked perfectly.
I hope it helps.
I'm having the same problem. v3.0.0
Yep - hitting this issue. Works fine in development, happens when running signed production build.
"react-native-splash-screen": "^3.0.1",
Was anyone able to determine a root cause for this? What's odd is I'm only running into this issue with an obfuscated Proguard build (+ signed w/ release key). When I set -dontobfuscate
in proguard-rules.pro
and then compile the release with minifyEnabled true
it works fine. I'm using version ^3.0.1
of this library.
i'm having the same error :(
if your method is onBackPressed, then delete the super.onBackPressed(); :D
I'm having this issue on Android even on Debug mode. Works fine on iOS. react-native 0.52.2 react-native-navigation 1.1.365 react-native-splash-screen 3.0.6 Android emulator API 26
E/WindowManager: android.view.WindowLeaked:
Activity com.xapps.x.MainActivity has leaked window DecorView@4c2ceb2[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:485)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
at android.app.Dialog.show(Dialog.java:330)
at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36)
at android.app.Activity.runOnUiThread(Activity.java:6152)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:26)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:47)
at com.xapps.x.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
02-01 00:08:58.704 16422-16422/com.xapps.x E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xapps.x, PID: 16422
java.lang.IllegalArgumentException: View=DecorView@4c2ceb2[] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:485)
Adding this method works!
@Override
protected void onPause() {
SplashScreen.hide(this);
super.onPause();
}
Thanks @rmarquois.
After 2 hours of research.
Above the problem :
android.view.WindowLeaked: Activity com.xxx.MainActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{b2059e6 V.E...... R.....ID 0,0-2048,1536} that was originally added here
I found that this error:
FATAL EXCEPTION: Thread-170 Process: com.xxx, PID: 1734 java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server. at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method) at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216) at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:33) at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:234) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1137) at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:944) at java.lang.Thread.run(Thread.java:818)
So after I tried to run the script below, I can install the release apk on my device.
mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
@brunolemos I was trying to run debug from Android Studio as well! The onPause
fixed it for me. I think it was because there's a point where the app shows "waiting for remote debugger to connect" (e.g. connecting to Android Studio), and the crash happened before right before that. I bet Android "paused" the activity while connecting to the debugger, resulting in some sort of error within the splash screen library.
Hey!
We're having this issue in production.
Any reason why the following change haven't already been added to the lib?
@Override
protected void onPause() {
SplashScreen.hide(this);
super.onPause();
}
Is a PR needed? (I see there are a bunch of open PRs)
Thanks!
It works fine with enableProguardInReleaseBuilds = true
in release mode without setting -dontobfuscate
in proguard-rules.pro
with version 3.1.1
.
@duongntb94 solution should fix above mentioned issue.
I am getting this error as well, even after adding the onPause method. Any solution here?
Using version 3.1.1 with React Native 0.55
public class MainActivity extends NavigationActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
@Override
protected void onPause() {
SplashScreen.hide(this);
super.onPause();
}
}
After 2 hours of research.
So after I tried to run the script below, I can install the release apk on my device.
mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
@duongntb94, that worked, thanks
After 2 hours of research.
So after I tried to run the script below, I can install the release apk on my device.
mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
@duongntb94 , This fixed it. thanks a lot.
Tried both solutions mentioned here.
Adding this method works!
@Override protected void onPause() { SplashScreen.hide(this); super.onPause(); }
Thanks @rmarquois.
After 2 hours of research.
So after I tried to run the script below, I can install the release apk on my device.
mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
@duongntb94 , This fixed it. thanks a lot.
android app crashes everytime, tried almost everything out there on internet, nothing is wokring... :-|
android app crashes everytime, tried almost everything out there on internet, nothing is wokring... :-|
Run the app from within android studio and check and logs. See what the issue is and paste the red color issue you found, in here. Someone might be able to help
@HishamMubarak
Got it working...
Just before generating apk run this command:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
I am getting this error as well, even after adding the onPause method. Any solution here?
Using version 3.1.1 with React Native 0.55
public class MainActivity extends NavigationActivity { @Override protected void onCreate(Bundle savedInstanceState) { SplashScreen.show(this); super.onCreate(savedInstanceState); } @Override protected void onPause() { SplashScreen.hide(this); super.onPause(); } }
I have the same problem, it caused by another package. After deleting the package, I solve it.
Any of this solution not working for me for android "Pie" There is any one have other solution.
Thanks!
After deleting the package, I solve it.
Which package did you delete and in which package it happened?
+1
I was getting this error when I was trying to run a production apk. It would throw onShow not on startup. This error is thrown when something goes wrong within your application. For me I never asked for the fine location permission and when trying to access the user's location the app would crash. I would suggest using Logcat in the Android Studio terminal and look around for errors. It's usually above the splash screen error.
In addition to @duongntb94 solution
I think this answer on StackOverflow will be useful :) https://stackoverflow.com/a/46363228
Looks like a proper way to do it automatically rather than manually.
Also, you can look into a comment in android/app/build.gradle
file. There you can find a bit more information about ext.react
configuration
I tried all the methods mentioned here added onPause() , executed the following command
mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
still getting the same error.
android.view.WindowLeaked: Activity com.io.proathlix.MainActivity has leaked window DecorView@27f75e5[] that was originally added here at android.view.ViewRootImpl.<init>(ViewRootImpl.java:518) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:338) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at android.app.Dialog.show(Dialog.java:328) at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36) at android.app.Activity.runOnUiThread(Activity.java:5879) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:56) at com.io.proathlix.MainActivity.onCreate(MainActivity.java:16) at android.app.Activity.performCreate(Activity.java:6692) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2709) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2825) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6339) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
Am on 3.1.1 version. Anyone else faced this problem and resolved by any other methods?
Updated to 3.2.0 fixed the issue for me.
make sure that you close the metro bundler and run it again, if you've been working on two react native projects you may have left metro bundler of some other package running. this is what happened to me.
I was getting this error when I was trying to run a production apk. It would throw onShow not on startup. This error is thrown when something goes wrong within your application. For me I never asked for the fine location permission and when trying to access the user's location the app would crash. I would suggest using Logcat in the Android Studio terminal and look around for errors. It's usually above the splash screen error.
Just wanted to say thanks for this. I was getting the error as well about windowLeaked, but the real error was way above it.
I'm using React Native 0.57.3 with react-native-splash-screen 3.1.1.
I had added buildTypes (for making different build variants of my app), and when making a signed app using any of those variants it would crash. It would work with release though, and that turns out to be due to the default behaviour that react will bundle your assets automatically for release without any config from you, but any other variants have to be managed by yourself.
I was getting the error:
2019-04-04 00:44:11.722 3892-3892/? E/WindowManager: android.view.WindowLeaked: Activity com.appmaster.MainActivity has leaked window DecorView@56c6dc3[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:417)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.app.Dialog.show(Dialog.java:316)
at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36)
at android.app.Activity.runOnUiThread(Activity.java:5849)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:56)
at com.appmaster.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Scrolling further above this error in logcat inside Android Studio revealed there was a smaller but main reason for the crash on start. Running this in the virtual emulator. (Crash happened on device too)
2019-04-04 00:51:58.670 4183-4201/? E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: com.appmaster.dev, PID: 4183
java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:32)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:243)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1114)
at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:913)
at java.lang.Thread.run(Thread.java:761)
Basically, it's saying it can't find any of the required assets since they weren't bundled so the app exits. Turns out there's nothing wrong with react-native-splash-screen.
I noticed in my build folder under android/app/build/intermediates/merged_assets for release that there is a index.android.bundle:
However, my build variant for dev didn't have this (which is the reason for the above error):
My added buildType looks like the following (in /android/app/build.gradle):
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
// dev is my added buildType
dev {
initWith release
applicationIdSuffix ".dev"
matchingFallbacks = ['release']
}
}
The solution was to add the following to the top of /android/app/build.gradle before the apply statement :
project.ext.react = [
entryFile: "index.js",
bundleInDev: true,
jsBundleDirdev: "$buildDir/intermediates/merged_assets/dev/mergeDevAssets/out",
]
Note that bundleInDev
needs to have the first letter of your buildType name capital, or it won't work. When I tried bundleIndev
it failed, it needs to be capital. This tells react that we are bundling our assets for this build variant.
The second one is jsBundleDirdev
. Strangely, this one works even if named jsBundleDirDev
. This one tells react where to put the bundle (named index.android.bundle).
After doing this, my problem was solved. Running Generate Signed Bundle / APK
worked for my dev variant, and starting up the app no longer crashes. The file index.android.bundle was being added for dev.
Basically, this will happen if you try to build a signed bundled version of debug too apparently, since it's set to bundleInDebug: false
by default from what I can see.
Hopefully this helps someone else, or points someone closer to the right direction for their problem.