From f51fedc77007f603c5df68820fcf51d04c32e1d9 Mon Sep 17 00:00:00 2001 From: timbotimbo Date: Fri, 16 Aug 2024 00:12:35 +0200 Subject: [PATCH] Comment ProxyLifecycleProvider to fix Flutter 3.24 kotlin compilation. --- CHANGELOG.md | 1 + .../FlutterUnityWidgetPlugin.kt | 140 +++++++++--------- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a098758f..60b43483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938) * [Android] Workaround for mUnityplayer error in Unity plugins using the AndroidJavaProxy. [#908](https://github.com/juicycleff/flutter-unity-view-widget/pull/908) * [Android] Add namespace for Android gradle plugin (AGP) 8 compatibility. +* [Android] Fix kotlin compilation error with Flutter 3.24 and newer. [#973](https://github.com/juicycleff/flutter-unity-view-widget/issues/973) ## 2022.2.1 diff --git a/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt b/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt index 332f00cf..f9392f35 100755 --- a/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt +++ b/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt @@ -87,78 +87,80 @@ class FlutterUnityWidgetPlugin : FlutterPlugin, ActivityAware { } /** + * [August 2024 UPDATE] This unused class was disabled to fix compilation errors in Flutter 3.24. + * * This class provides a {@link LifecycleOwner} for the activity driven by {@link * ActivityLifecycleCallbacks}. * *

This is used in the case where a direct Lifecycle/Owner is not available. */ - @SuppressLint("NewApi") - private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider { - private val lifecycle = LifecycleRegistry(this) - private var registrarActivityHashCode: Int = 0 - - init { - UnityPlayerUtils.activity = activity - this.registrarActivityHashCode = activity.hashCode() - activity.application.registerActivityLifecycleCallbacks(this) - } - - override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE) - } - - override fun onActivityStarted(activity: Activity) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START) - } - - override fun onActivityResumed(activity: Activity) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME) - } - - override fun onActivityPaused(activity: Activity) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE) - } - - override fun onActivityStopped(activity: Activity) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP) - } - - override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { - UnityPlayerUtils.activity = activity - } - - override fun onActivityDestroyed(activity: Activity) { - UnityPlayerUtils.activity = activity - if (activity.hashCode() != registrarActivityHashCode) { - return - } - - activity.application.unregisterActivityLifecycleCallbacks(this) - lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY) - } - - override fun getLifecycle(): Lifecycle { - return lifecycle - } - } +// @SuppressLint("NewApi") +// private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider { +// private val lifecycle = LifecycleRegistry(this) +// private var registrarActivityHashCode: Int = 0 +// +// init { +// UnityPlayerUtils.activity = activity +// this.registrarActivityHashCode = activity.hashCode() +// activity.application.registerActivityLifecycleCallbacks(this) +// } +// +// override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE) +// } +// +// override fun onActivityStarted(activity: Activity) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START) +// } +// +// override fun onActivityResumed(activity: Activity) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME) +// } +// +// override fun onActivityPaused(activity: Activity) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE) +// } +// +// override fun onActivityStopped(activity: Activity) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP) +// } +// +// override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { +// UnityPlayerUtils.activity = activity +// } +// +// override fun onActivityDestroyed(activity: Activity) { +// UnityPlayerUtils.activity = activity +// if (activity.hashCode() != registrarActivityHashCode) { +// return +// } +// +// activity.application.unregisterActivityLifecycleCallbacks(this) +// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY) +// } +// +// override fun getLifecycle(): Lifecycle { +// return lifecycle +// } +// } } \ No newline at end of file