Skip to content
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

[Android] Compiling error flutter 3.24 #973

Open
lorisgir opened this issue Aug 8, 2024 · 7 comments
Open

[Android] Compiling error flutter 3.24 #973

lorisgir opened this issue Aug 8, 2024 · 7 comments
Labels
android This issue is specific to the Android Platform. bug This issue refers to a bug in the plugin

Comments

@lorisgir
Copy link

lorisgir commented Aug 8, 2024

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:

  • OS: MacOS
  • Version 2022.3.36

Smartphone:

  • Device: Pixel 8 Emulator
  • OS: Android
  • Version 15
@timbotimbo timbotimbo added bug This issue refers to a bug in the plugin android This issue is specific to the Android Platform. labels Aug 9, 2024
@timbotimbo
Copy link
Collaborator

timbotimbo commented Aug 9, 2024

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.

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
}
}

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 e4cd059

[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: master # branch name
      # UPDATE: this fix is now included in the master branch
      # ref: flutter_3.24_android_hotfix

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

@timbotimbo timbotimbo changed the title Compiling error flutter 3.24 [Android] Compiling error flutter 3.24 Aug 9, 2024
@viktorsht
Copy link

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

@artificerchris
Copy link

@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
Copy link
Collaborator

timbotimbo commented Aug 15, 2024

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
Copy link

Thank you very much!

@keyss-vivaan
Copy link

thanks you it is working now

@guilherme-francisco
Copy link

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.

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
}
}

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 e4cd059

[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.

this fixed most of my problems, I later had some conflicts with NDK but I managed to fix it. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android This issue is specific to the Android Platform. bug This issue refers to a bug in the plugin
Projects
None yet
Development

No branches or pull requests

6 participants