apache / cordova-plugin-screen-orientation

Apache Cordova Screen Orientation Plugin
https://cordova.apache.org/
Apache License 2.0
219 stars 229 forks source link

App crashes on startup when locking or unlocking the orientation #127

Closed bsprengelmeijer closed 9 months ago

bsprengelmeijer commented 9 months ago

Bug Report

Problem

App crashes when orientation is changed on startup.

What is expected to happen?

Orientation locks to landscape.

What does actually happen?

App crashes.

Information

When I lock the orientation to landscape and fully close the application and restart it, it crashes.

It does not happen when I add a timeout with a minimum of 3 seconds, so after the app is fully loaded. So changing the orientation when the app is loaded works fine, just not on startup.

Waiting for the deviceready event doesn't make any difference only adding a minimum of 3 seconds delay.

Command or Code

window.screen.orientation.lock('landscape');

 FATAL EXCEPTION: mainandroid.content.res.Resources$NotFoundException: Resource ID #0x7f08007a
    at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:235)
    at android.content.res.Resources.getDrawableForDensity(Resources.java:991)
    at android.content.res.Resources.getDrawable(Resources.java:931)
    at android.content.res.Resources.getDrawable(Resources.java:906)
    at org.apache.cordova.splashscreen.SplashScreen.onConfigurationChanged(SplashScreen.java:215)
    at org.apache.cordova.PluginManager.onConfigurationChanged(PluginManager.java:585)
    at org.apache.cordova.CordovaActivity.onConfigurationChanged(CordovaActivity.java:502)
    at android.app.ActivityThread.performActivityConfigurationChanged(ActivityThread.java:5932)
    at android.app.ActivityThread.performConfigurationChangedForActivity(ActivityThread.java:5858)
    at android.app.ActivityThread.handleActivityConfigurationChanged(ActivityThread.java:6142)
    at android.app.servertransaction.ActivityConfigurationChangeItem.execute(ActivityConfigurationChangeItem.java:53)
    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2304)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7930)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

Environment, Platform, Device

Android 13

Version information

Cordova android version 10

Checklist

breautek commented 9 months ago

Based on the stacktrace, the screen orientation API ends up triggering a configuration change hook in the splashscreen plugin and the crash is actually in the splashscreen plugin. It's looking for a drawable resource which doesn't appear to be available (and obviously isn't guarded enough).

The splashscreen plugin is no longer supported and has been replaced by android's splashscreen API available in cordova-android@11 or later and the current version doesn't have an android implementation at all.

It would be suggested to update your project to the latest cordova-android platform release (currently cordova-android@12). It would be advisable to have a read on the Cordova Android 11 & Cordova Android 12 annoucements to learn about breaking changes that might affect your project.

If for some reason you cannot upgrade your project, or is unwilling to at this time, then you can try ensuring that all splashscreen resources are available (see the docs) which should avoid the crash.

I'm closing this issue because there isn't anything actionable in the screen orientation plugin to address this problem and the package in question is out of support for the android platform, so no updates will be made.

Should you run into further issues while using the current release of cordova-android, feel free to reach out on GitHub Discussions or create a new issue if you believed a bug has been found.