juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 514 forks source link

[Android] Compiling error flutter 3.24 #973

Open lorisgir opened 1 month ago

lorisgir commented 1 month ago

Describe the bug After the update to flutter 3.24 every time I try to build & run on the emulator I get these error messages: e: file:///Users/{user}/.pub-cache/hosted/pub.dev/flutter_unity_widget-2022.2.1/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt:97:9 Cannot weaken access privilege 'public' for 'lifecycle' in 'LifecycleOwner' e: file:///Users/{user}/.pub-cache/hosted/pub.dev/flutter_unity_widget-2022.2.1/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt:97:21 'lifecycle' hides member of supertype 'LifecycleOwner' and needs 'override' modifier

I already tried to run flutter clean and rebuild the unity project from unity but always the same error

Unity:

Smartphone:

timbotimbo commented 1 month ago

Looks like an AndroidX library got updated in Flutter, resulting in an change in the LifecycleOwner kotlin interface.

As a result the current implementation breaks on Flutter 3.24.0+, but updating this implementation will break the plugin on all earlier Flutter versions.

Looking at the source, this is only used in a private class, which does not seem to have any references anywhere else in the plugin. I also added a log in each function, but I never saw any output in logcat. So it looks like this class isn't even used. https://github.com/juicycleff/flutter-unity-view-widget/blob/45fffb52e5e2c101bda435e396218b2ad9c56503/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt#L96-L163

Simply deleting or commenting this class does not seem to break anything and allows me to run the example project with Flutter 3.24.

[UPDATE] Looks like the reference using the class was removed over 2 years ago in https://github.com/juicycleff/flutter-unity-view-widget/commit/e4cd05930a5dc7f0b4b9c8457061020e2d24a3fa

[UPDATE 2] The fix below is now also on the master branch.

As a test I made a branch that should get this working again.

You can try it using this in pubspec.yaml:

flutter_unity_widget:
    git:
      url: https://github.com/juicycleff/flutter-unity-view-widget.git
      ref: flutter_3.24_android_hotfix # branch name
      # UPDATE: this fix is now included in the master branch

I can't publish plugin updates, so we would need @juicycleff to make a new release for Flutter 3.24.

viktorsht commented 1 month ago

@timbotimbo Thank you very much! You helped me a lot! God bless you!

artificerchris commented 1 month ago

@timbotimbo Any chance you could apply that same fix over on the 6.0 branch? I'm testing it out and just hit this error, and one other one I'm about to write up.

timbotimbo commented 1 month ago

I added the fix to the master branch, to make sure it gets included in a future update. This issue can stay open until it reaches pub.dev.

@artificerchris I've merged the updated master into the 6000 branch as well.

artificerchris commented 1 month ago

Thank you very much!