apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

cordova-android@12 - Compatibility Error on Tiramisu #1620

Closed landabaso closed 11 months ago

landabaso commented 11 months ago

I have upgraded from cordova-android@10 to 12. I am encountering a compatibility error after running my Cordova app on an Android API Level 33 emulator (Tiramisu). The app works fine on real devices with older Android versions, but it fails to run on a Tiramisu emulator.

The runtime error message indicates a java.lang.NoClassDefFoundError with the message Failed resolution of: Landroid/window/OnBackInvokedCallback. This error is caused by a java.lang.ClassNotFoundException for the class android.window.OnBackInvokedCallback.

OnBackInvokedCallback was introduced in API level 33, and it seems that my project is making use of it after upgrading it to cordova-android@12, resulting in a crash on devices with API level 33. I have investigated the issue and set android:enableOnBackInvokedCallback="false" (also to true) in the Android manifest files to disable/enable this feature which did not help.

I have spent considerable time trying to identify the specific code that is making the call to OnBackInvokedCallback with no success. I am unsure whether this issue is due to a bug in cordova-android@12 or if there is something else I need to handle differently.

I would like to know if anyone else is facing a similar issue and if it is a known bug in cordova-android@12 or if there are any suggestions on how to properly handle this situation.

EDIT with some more info: I'm running cordova version 12

cordova --version
12.0.0 (cordova-lib@12.0.1)

Also: "cordova-android": "^12.0.0", I already removed all plugins and platforms and installed them from scratch just in case there was an issue in the upgrade process.

landabaso commented 11 months ago

After some more tests I found out it works with a new clean image using "API 33". However, it fails, using "API Tiramisu". The device manager is kind of confusing. Is it safe to assume that the created device "API Tiramisu" is kind of buggy?

That folder is from April 2022. It looks like a beta? drwxr-xr-x 3 xxx xxx 96B Apr 13 2022 android-Tiramisu/

image

breautek commented 11 months ago

Is it safe to assume that the created device "API Tiramisu" is kind of buggy?

I believe Google uses the codenames for the beta/prerelease software. The stable release versions uses the API number instead.

I scan cordova-android for OnBackInvokedCallback and it doesn't appear the cordova framework uses it directly. It could be used internally inside an SDK.

I'd also make sure you have the latest revision (revision 2) of the API 33 platform installed.

Screenshot from 2023-05-29 19-21-42

landabaso commented 11 months ago

Yeah, I checked and it was a preview image. I guess that preview did not implement OnBackInvokedCallback yet while it was being used by a plugin or some part of the code because the system believed it was running a normal API level 33. I'm closing the issue. Thanks!