Open timbotimbo opened 4 months ago
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.
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.
After a report in the Flutter repo this can be labeled as a Unity issue.
Once AR boots up, Unity uses the getMethodID
function in the ReflectionHelper
class of unity-classes.jar
.
This function gets a list of all function in the current Activity using Java reflection getDeclaredMethods()
, and then tries to match function signatures.
It then repeats this for all super classes of the current Activity.
The getDeclaredMethods
call instantly crashes on Android <13 because it can't handle the OnBackInvokedCallback
return type that is defined in API 33.
Flutter won't stop using this class for a few people using the niche use-case of embedding Unity with AR. So AR is broken from now on unless this can be fixed on the Unity side.
With some luck a try-catch around getDeclaredMethods
might be enough.
However this means either:
I've tried to decompile unity-classes.jar, but none of the decompilers that I could find returned valid code that could compile again without errors.
To replicate this issue witthout Flutter:
import android.annotation.TargetApi;
import android.window.OnBackInvokedCallback;
@TargetApi(33)
protected OnBackInvokedCallback getOnBackInvokedCallback() {
return null;
}
AR is broken with Flutter 3.22+. Don't expect this to be fixed for months, if at all.
This is now in the Unity issue tracker.
They seem to have omitted most details from my bug report, but I guess it is a first step.
Anyone affect by this should probably upvote this in the issuetracker.
note that if you want to use AR with flutter 3.19.6 on android, make sure useAndroidViewSurface: true
or the player view will freeze
Unity got back to me on the bug report, calling it "By Design".
Given that Flutter devs point me at Unity, and Unity considers it by design, AR is likely a lost cause on Android < 13.
Since 3.16 and 3.19 contain various serious bugs (https://github.com/juicycleff/flutter-unity-view-widget/issues/912, https://github.com/juicycleff/flutter-unity-view-widget/issues/929) the last reliable version is 3.13.9, which is getting old.
[UPDATE]
This is now in the Unity issue tracker. Anyone affect by this should probably upvote this in the issuetracker.
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)
(unity 2023.2)
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:
Did not crash on:
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:
Devices with crash:
Some things I've tried
-keep class android.window.** { *; }
-keep class android.window.OnBackInvokedCallback { *; }
.android:enableOnBackInvokedCallback="false"
to all androidmanifest activities and applications.implementation "androidx.activity:activity:1.6.0
in gradle (OnbackInvokedCallback is mentioned in the changes.)