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 518 forks source link

Unity 2023 & Unity 6000 breaking changes on Android. #839

Closed timbotimbo closed 3 months ago

timbotimbo commented 1 year ago

Describe the bug

Unity 2023 changed some Android classes, which cause compile errors with all plugin versions up to 2022.2.x. This makes Unity 2023 incompatible with the android version of this plugin.

In the 2023.1.0 changelog:

Android: Modified FrameLayout so you can call getFrameLayout function on UnityPlayer instance if you need access to frame layout. UnityPlayer/UnityPlayerForActivityOrService no longer derives from FrameLayout.

This fork was linked on Discord, which is supposed to handle these changes. https://github.com/ritolika/flutter-unity-view-widget/tree/Unity-2023.1

TODO

There are 2 choices:

  1. Figure out a way to support both 2023 and 2019-2022 using the same plugin
  2. Split the plugin in 2 branches: Pre-2023 and 2023+.

I hope that we can somehow achieve option 1, but I don't know how feasible that is.

Errors

Here are some of the compilation errors you'll get when you try to build it

Compile errors (expand this) ``` e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (13, 1): Class 'CustomUnityPlayer' is not abstract and does not implement abstract base class member public abstract fun setMainSurfaceViewAspectRatio(p0: Float): Unit defined in com.unity3d.player.UnityPlayer e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (13, 1): CustomUnityPlayer inherits invisible abstract members: public/*package*/ abstract fun handleFocus(p0: Boolean): Boolean defined in com.unity3d.player.UnityPlayer, public/*package*/ abstract fun getGfxView(): View! defined in com.unity3d.player.UnityPlayer, public/*package*/ abstract fun onOrientationChanged(p0: Int, p1: Int): Unit defined in com.unity3d.player.UnityPlayer, public/*package*/ abstract fun cleanupResourcesForDestroy(): Unit defined in com.unity3d.player.UnityPlayer e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (13, 102): Type mismatch: inferred type is IUnityPlayerLifecycleEvents? but UnityPlayer.h! was expected e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (13, 105): No value passed for parameter 'p2' e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (19, 5): 'onConfigurationChanged' overrides nothing e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (21, 15): Unresolved reference: onConfigurationChanged e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (24, 5): 'onAttachedToWindow' overrides nothing e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (26, 15): Unresolved reference: onAttachedToWindow e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (32, 5): 'onDetachedFromWindow' overrides nothing e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (36, 15): Unresolved reference: onDetachedFromWindow e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (39, 5): 'dispatchTouchEvent' overrides nothing e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (41, 22): Unresolved reference: dispatchTouchEvent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (45, 5): 'onTouchEvent' overrides nothing e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt: (49, 22): Unresolved reference: onTouchEvent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\FlutterUnityWidgetController.kt: (337, 44): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\FlutterUnityWidgetController.kt: (338, 45): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\FlutterUnityWidgetController.kt: (338, 77): Type mismatch: inferred type is CustomUnityPlayer? but View! was expected e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\FlutterUnityWidgetController.kt: (342, 44): Unresolved reference: z e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\FlutterUnityWidgetController.kt: (359, 44): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\OverrideUnityActivity.kt: (45, 23): Unresolved reference: lowMemory e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (38, 64): Unresolved reference: requestFocus e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (56, 31): Unresolved reference: bringToFront e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (57, 31): Unresolved reference: requestLayout e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (58, 31): Unresolved reference: invalidate e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (177, 31): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (179, 65): Type mismatch: inferred type is CustomUnityPlayer? but View! was expected e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (196, 19): None of the following functions can be called with the arguments supplied: public open fun addView(p0: View!, p1: ViewGroup.LayoutParams!): Unit defined in android.view.ViewGroup public open fun addView(p0: View!, p1: Int): Unit defined in android.view.ViewGroup e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (203, 31): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (204, 32): Unresolved reference: parent e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (204, 64): Type mismatch: inferred type is CustomUnityPlayer? but View! was expected e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (207, 31): Unresolved reference: z e: C:\\unity_widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\UnityPlayerUtils.kt: (210, 39): Type mismatch: inferred type is CustomUnityPlayer? but View! was expected ```

To Reproduce

Steps to reproduce the behavior:

  1. Export the example project using Unity 2023.1.x
  2. Run or build the Flutter project for Android.
k0uhe1D commented 1 year ago

I've briefly researched the changes in Unity Android that occur in Unity 2023 and later, and I'd like to share my findings.

timbotimbo commented 3 months ago

I added a branch to test an alpha implementation for Unity 6. Check https://github.com/juicycleff/flutter-unity-view-widget/issues/967 for instructions.

Given that 6 is actually 2023.3, I'm skipping 2023.1 and 2023.2.

Since Unity changed their classes, I decided on a separate verion that isn't backwards compatible. The only alternative is using a lot of reflection to pick the correct classes, which won't be good for maintenance and performance.