-
Notifications
You must be signed in to change notification settings - Fork 6
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 & 3.24] ARFoundation crashes on Android < 13 - NoClassDefFoundError: Landroid/window/OnBackInvokedCallback #21
Comments
Narrowed it down to this commit on Flutter master. |
With some custom plugin modifications I managed to try this on Unity 2023.2.20 and 6000.0.7. I'm still getting the same error, so I will probably have to open an issue in the Flutter repo. 2023.2.20
6000
|
After a report in the Flutter repo this can be labeled as a Unity issue. The causeOnce AR boots up, Unity uses the The What nowFlutter won't stop using this class for a few people using the niche use-case of embedding Unity with AR. With some luck a try-catch around 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. Unity reproductionTo replicate this issue witthout Flutter:
TLDR (too long didn't read)AR is broken with Flutter 3.22+. Don't expect this to be fixed for months, if at all. |
Thanks again for your tireless and meticulous work tracking all of this @timbotimbo it's very much appreciated. I've added a note to the README for this issue. |
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. |
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. |
I took a final look at this and actually found a simple workaround. This because the FlutterFragmentActivity did not (yet?) get updated with the WorkaroundUpdate MainActivity.kt to use this: import io.flutter.embedding.android.FlutterFragmentActivity;
class MainActivity: FlutterFragmentActivity() {
} I tested ARFoundation on a Galaxy S8 with Android 9 on these Flutter versions:
This workaround should allow AR apps stuck on Flutter 3.1x to upgrade to 3.22+. Drawbacks and side effectsI'm still playing around with this so this list might not be complete yet.
<!-- Androidmanifest -->
<application
...
android:enableOnBackInvokedCallback="false"> So if you want to test this workaround, pay extra attention to the 'back' behavior in your app. |
… app facing package to 1.2.4 to publish update to README to pub.dev
Thanks for the detailed update @timbotimbo this is really appreciated. I have updated the README to note that there is a workaround documented in this issue, but that it may break in future versions of Flutter. |
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.
In my own project Unity works fine for 3D scenes but crashes when I switch to a scene that includes ARFoundation.
In the example project here, Unity shows up with the Flutter logo but crashes once the AR support check runs.
Error in the console:
Looking up OnBackInvokedCallback, it is added in API 33 (android 13) and is related to the predictive back gesture in Android 14.
I'm not sure if this is a flutter bug where it sends some kind of message which it shouldn't on API <33, or if it is caused by Unity missing an implementation.
Error log
Full console log up to the crash
Flutter version
Crashed on:
Did not crash on:
Unity version
Only tested with:
2022.3.21f1, 2022.3.33f1
ArFoundation 5.1.2 and 5.1.4
Minimum reproducible example
flutter_embed_unity
folder from this repoexample_unity_2022_3_project
folder from this repo.The only change applied to build the example was to change the android sdk to 34 in the gradle files.
Any project using AR with android <13 will likely work to trigger this.
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.)
The text was updated successfully, but these errors were encountered: