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

[Flutter 3.22] AR crashes on Android < 13 - NoClassDefFoundError: Landroid/window/OnBackInvokedCallback #957

Open
timbotimbo opened this issue Jun 21, 2024 · 2 comments
Labels
android This issue is specific to the Android Platform. bug This issue refers to a bug in the plugin Flutter issue/bug Problem caused by Flutte that we can't fix Unity issue/bug Problem caused by Unity that we can't fix on our end.

Comments

@timbotimbo
Copy link
Collaborator

timbotimbo commented Jun 21, 2024

Description

Since Flutter 3.22, Unity will crash on certain Android versions when ARFoundation is activated.
This only happens on Android <13.
This might also affect other unity plugins using native code, I just noticed it using ARFoundation.

Unity works fine for 3D scenes but crashes when I switch to a scene that includes ARFoundation and its ARSession.

Error in the console:
(unity 2022.3)

E/Unity   ( 7029): AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/window/OnBackInvokedCallback;
E/Unity   ( 7029): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/window/OnBackInvokedCallback;
E/Unity   ( 7029): 	at java.lang.reflect.Executable.getMethodReturnTypeInternal(Native Method)
E/Unity   ( 7029): 	at java.lang.reflect.Method.getReturnType(Method.java:148)
E/Unity   ( 7029): 	at java.lang.Class.getDeclaredMethods(Class.java:1880)
E/Unity   ( 7029): 	at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:26)
E/Unity   ( 7029): 	at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
E/Unity   ( 7029): 	at com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender(Unknown Source:0)
E/Unity   ( 7029): 	at com.unity3d.player.UnityPlayer$F$a.handleMessage(Unknown Source:122)
E/Unity   ( 7029): 	at android.os.Handler.dispatchMessage(Handler.java:102)
E/Unity   ( 7029): 	at android.os.Looper.loop(Looper.java:214)
E/Unity   ( 7029): 	at com.unity3d.player.UnityPlayer$F.run(Unknown Source:24)
E/Unity   ( 7029): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.window.OnBackInvokedCallback" on path: DexPathList[[zip file "

(unity 2023.2)

E/Unity   (17280): AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/window/OnBackInvokedCallback;
E/Unity   (17280): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/window/OnBackInvokedCallback;
E/Unity   (17280):   at java.lang.reflect.Executable.getMethodReturnTypeInternal(Native Method)
E/Unity   (17280):   at java.lang.reflect.Method.getReturnType(Method.java:148)
E/Unity   (17280):   at java.lang.Class.getDeclaredMethods(Class.java:1880)
E/Unity   (17280):   at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:26)
E/Unity   (17280):   at com.unity3d.player.UnityPlayerForActivityOrService.nativeRender(Native Method)
E/Unity   (17280):   at com.unity3d.player.S.handleMessage(Unknown Source:140)
E/Unity   (17280):   at android.os.Handler.dispatchMessage(Handler.java:102)
E/Unity   (17280):   at android.os.Looper.loop(Looper.java:214)
E/Unity   (17280):   at com.unity3d.player.V.run(Unknown Source:24)
E/Unity   (17280): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.window.OnBackInvokedCallback" on path: DexPathList[

More info

Looking up OnBackInvokedCallback, it is added in API 33 (android 13) and is related to the predictive back gesture in Android 14.

I narrowed it down to this commit on Flutter master, which includes the engine PR Platform channel for predictive back in route transitions on android.
Any Flutter master commit before this one won't crash.

I can also reproduce this with the flutter_embed_unity plugin. So it isn't specific to code in this plugin.

Flutter version

Crashed on:

  • Flutter 3.22,0, 3.22.2
  • master (3.23.0-13.0.pre.265 revision a9f554ac39)

Did not crash on:

  • Flutter 3.13.9
  • Flutter 3.16.9
  • Flutter 3.19.6.

Unity version

Only tested with:
2022.3.21f1, 2022.3.33f1, 2023.2.20f1.
ArFoundation 5.1.2, 5.1.4 and 5.1.5

Android devices

Devices without crash:

  • Samsung S20FE, Android 13
  • Xiaomi redmi note 10 pro, Android 13
  • Wilefox Swift, Android 7, (doesn't support AR)

Devices with crash:

  • Samsung S10, Android 12
  • Nokia 8.1, Android 11
  • Lenovo tab M10, Android 10
  • Samsung S8, Android 9

Some things I've tried

  • Adding proguard rules like -keep class android.window.** { *; } -keep class android.window.OnBackInvokedCallback { *; }.
  • Adding android:enableOnBackInvokedCallback="false" to all androidmanifest activities and applications.
  • Updating to the latest Unity 2022.3.33
  • Updating Android Studio to Jellyfish 2023.3.1 Patch2 and updating all SDK tools
  • Adding implementation "androidx.activity:activity:1.6.0 in gradle
    (OnbackInvokedCallback is mentioned in the changes.)
@timbotimbo timbotimbo added bug This issue refers to a bug in the plugin android This issue is specific to the Android Platform. Flutter issue/bug Problem caused by Flutte that we can't fix Unity issue/bug Problem caused by Unity that we can't fix on our end. labels Jun 21, 2024
@KailaashJeevan
Copy link

Yup, got the same for Vuforia integration. The app successfully runs on android version 14, but not on anything else. It results on black screen.

image

@CristovoXDGM
Copy link

I`ve also experienced some crashes too, but related to memory leak after open unity AR interaction my app a go back to previous screen.

@timbotimbo timbotimbo changed the title [Flutter 3.22] ARFoundation crashes on Android < 13 - NoClassDefFoundError: Landroid/window/OnBackInvokedCallback [Flutter 3.22] AR crashes on Android < 13 - NoClassDefFoundError: Landroid/window/OnBackInvokedCallback Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android This issue is specific to the Android Platform. bug This issue refers to a bug in the plugin Flutter issue/bug Problem caused by Flutte that we can't fix Unity issue/bug Problem caused by Unity that we can't fix on our end.
Projects
None yet
Development

No branches or pull requests

3 participants