Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashing on Redmi device android 14 because of splash-screen plugin (NullPointerException) #2295

Open
MarcelSchuermann opened this issue Jan 17, 2025 · 2 comments

Comments

@MarcelSchuermann
Copy link

Bug Report

Plugin(s)

  • splash-screen 6.0.3 (com.capacitorjs.plugins.splashscreen.SplashScreen.lambda$show$7)

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

Installed Dependencies:

  @capacitor/core: 6.2.0
  @capacitor/cli: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

[success] Android looking great! 👌

Platform(s)

android 14 (SDK 34)

Current Behavior

When showing / hiding the app by going to the capgo browser, the splashscreen forces the mobile app to completely crash on Redmi device, resulting in the error below (java.lang.NullPointerException).

Exception **java.lang.NullPointerException**: Attempt to invoke virtual method 'android.content.Context android.view.View.getContext()' on a null object reference
  at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:169)
  at com.capacitorjs.plugins.splashscreen.SplashScreen.lambda$show$7 (SplashScreen.java:452)
  at com.capacitorjs.plugins.splashscreen.SplashScreen.$r8$lambda$A2qMbW91Y0O72KVpVNhkOgLCt-I (Unknown Source)
  at com.capacitorjs.plugins.splashscreen.SplashScreen$$ExternalSyntheticLambda6.run (D8$$SyntheticClass)
  at android.os.Handler.handleCallback (Handler.java:958)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:224)
  at android.os.Looper.loop (Looper.java:318)
  at android.app.ActivityThread.main (ActivityThread.java:8765)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:561)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1013)

Expected Behavior

When showing / hiding the app by going to the capgo browser, the splashscreen does not force the app to crash on Redmi device.

Other Technical Details

The error has currently only be observed on Redmi garnet (Redmi Note 13 Pro 5G) on Android 14.
Other devices f.e. Samsung Galaxy S24 on Android 14 works fine.

Additional Context

Gemini diagnosis:
`
The app crashed because it tried to call getContext() on a View object that was null. This happened when the app was trying to add a view to the WindowManager, likely related to showing the splash screen using the Capacitor Splash Screen plugin. Essentially, the code expected a view to exist, but it wasn't there, causing a NullPointerException. This occurred on the main thread.

Potential Solutions

Check for null before calling getContext(): The most likely cause is that the view being added to the WindowManager is null. This could happen if the view failed to inflate or was not properly initialized. A null check should be added before calling getContext() on the view. It can be assumed that this is happening inside com.capacitorjs.plugins.splashscreen.SplashScreen.show(), so that method should be checked for issues.
// Example inside SplashScreen.java show() method
if (splashScreenView != null) {
Context context = splashScreenView.getContext();
// ... rest of the code
} else {
// Handle the case where splashScreenView is null, perhaps by logging the error or attempting to re-initialize the view
Log.e("SplashScreen", "splashScreenView is null");
}

Verify Splash Screen View initialization: Ensure the splash screen view is being created and initialized correctly before it's added to the WindowManager. Double check XML layout files for errors and ensure resources are properly linked if the view is inflated from an XML layout. If the view is created programmatically, verify all the necessary steps are completed.
// Example (if view is inflated from XML):
View splashScreenView = LayoutInflater.from(context).inflate(R.layout.splash_screen, null);
// Make sure R.layout.splash_screen is a valid layout resource
if (splashScreenView == null) {
Log.e("SplashScreen", "Failed to inflate splash_screen layout");
return; // or throw an exception
}

Review Splash Screen Plugin Configuration: The Capacitor Splash Screen plugin might have configuration options related to the view's creation or display. Consult the plugin's documentation to ensure it is being used correctly and all necessary configurations are in place. If there are options for fallback behavior or error handling, make sure they are implemented correctly to prevent crashes. Look for any configuration related to delaying the hiding of the Splash Screen, since the error occurs in the SplashScreen.show() method. It's possible that showing the Splash Screen is being called at the wrong time or in a situation where it has already been shown.
`

@Ionitron
Copy link
Collaborator

This issue needs more information before it can be addressed.
In particular, the reporter needs to provide a minimal sample app that demonstrates the issue.
If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks!
Ionitron 💙

@MarcelSchuermann
Copy link
Author

I have created a simple sample app.
https://github.com/MarcelSchuermann/cap-bug-repo

However I could not test if the bug is shown in the basic app as I do not have the device mentioned.

Maybe someone can test if the bug occurs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants