mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

Unresolved reference: ViewTreeLifecycleOwner

Open LuisChiej opened this issue 1 year ago • 11 comments

I keep getting this error while trying to run the example application, Can someone help out

Task :mapbox_maps_flutter:compileDebugKotlin FAILED e: file:///mapbox-maps-flutter/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:10:27 Unresolved reference: ViewTreeLifecycleOwner e: file:///mapbox-maps-flutter/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:73:11 Class 'LifecycleHelper' is not abstract and does not implement abstract member public abstract val lifecycle: Lifecycle defined in androidx.lifecycle.LifecycleOwner e: file:///mapbox-maps-flutter/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:84:5 'getLifecycle' overrides nothing e: file:///mapbox-maps-flutter/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:176:20 Unresolved reference: ViewTreeLifecycleOwner e: `file:///mapbox-maps-flutter/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:183:5 Unresolved reference: ViewTreeLifecycleOwner

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':mapbox_maps_flutter:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel master, 3.24.0-1.0.pre.296, on macOS 14.5 23F79 darwin-arm64 (Rosetta), locale en-NG) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [!] Xcode - develop for iOS and macOS (Xcode 15.2) ✗ CocoaPods installed but not working. You appear to have CocoaPods installed but it is not working. This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it. This can usually be fixed by re-installing CocoaPods. For re-installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.91.1) [✓] Connected device (4 available) [✓] Network resources

LuisChiej avatar Jul 28 '24 02:07 LuisChiej

Use the flutter stable channel. You are using channel master Channel master, 3.24.0-1.0.pre.296

vchrisb avatar Aug 01 '24 09:08 vchrisb

With last stable I have same issue

jaumard avatar Aug 07 '24 09:08 jaumard

Same issue, #633 does not solve for me. I try to downgrade to mapbox_maps_flutter: ^2.0.0, still have the same issue. The problem appears to be only in Android, while iOS works fine.

DMrubencesario avatar Aug 08 '24 08:08 DMrubencesario

@DMrubencesario what error do you get?

ThomasAunvik avatar Aug 08 '24 08:08 ThomasAunvik

@ThomasAunvik the same of @LuisChiej.

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.0, on macOS 13.6 22G120 darwin-arm64, locale it-IT) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.92.0) [✓] Connected device (4 available) [✓] Network resources

DMrubencesario avatar Aug 08 '24 08:08 DMrubencesario

@DMrubencesario exactly the same error with the fix of #633 ?

If so, then the dependency isn't getting pulled from git and you would still be using the package from pub.dev.

ThomasAunvik avatar Aug 08 '24 08:08 ThomasAunvik

My workaround was to downgrade from Flutter 3.24.0 to 3.22.3.

jnorkus avatar Aug 09 '24 06:08 jnorkus

@jnorkus yep, had same issue. and had same temp solution aka downgraded to 3.22.2; compiles fine.

saconger avatar Aug 09 '24 14:08 saconger

Current Flutter 3.24.0 is still getting the issues

andyngdz avatar Aug 20 '24 03:08 andyngdz

Latest plugin version 2.2.0 still has the same issue.

jnorkus avatar Aug 21 '24 08:08 jnorkus

Latest plugin version 2.2.0 and my flutter version. 3.24.1 i still get this error. I cannot downgrade version to lower one because of video_player plugin

ilhamskh avatar Aug 25 '24 19:08 ilhamskh

flutter version. 3.24.1 still error. any solution for this?

Koleshy avatar Aug 26 '24 14:08 Koleshy

Getting this with Flutter 3.24.1 and mapbox_maps_flutter-2.2.0. Any solutions to not downgrade flutter? Only Android Problem. iOS builds image

hiloliddinj avatar Aug 28 '24 09:08 hiloliddinj

Hi all, sorry for the trouble, this issue is happening with Flutter SDK 3.24 as it bumped the version of androidx.lifecycle dependency. This issue affects only Android, iOS still compiles fine. We have addressed this in https://github.com/mapbox/mapbox-maps-flutter/pull/671, which is being released today as in a patch release 2.2.1.

evil159 avatar Aug 28 '24 11:08 evil159

After upgrading to 2.2.1 without changing nothing else the the error on top goes away but now it can't compile again giving me the following error:

ERROR:/Users/*/.gradle/caches/transforms-3/3e4c7e3f47ed5eda34cc39a74693193b/transformed/lifecycle-livedata-core-2.8.4-runtime.jar: D8: java.lang.NullPointerException Failure: Build completed with 2 failures. Task failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeExtDexDebug'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform lifecycle-livedata-core-2.8.4.aar (androidx.lifecycle:lifecycle-livedata-core:2.8.4) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for DexingNoClasspathTransform: /Users/rcesario/.gradle/caches/transforms-3/3e4c7e3f47ed5eda34cc39a74693193b/transformed/lifecycle-livedata-core-2.8.4-runtime.jar. > Error while dexing.

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.0, on macOS 13.6 22G120 darwin-arm64, locale it-IT) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.92.0) [✓] Connected device (4 available) [✓] Network resources

I tried to change some kotlin & gradle version but i can't solve the problem. Anyone else has the same problem?

DMrubencesario avatar Aug 29 '24 13:08 DMrubencesario

@DMrubencesario try with the following fix in comment: https://github.com/mapbox/mapbox-maps-flutter/pull/633#issuecomment-2275225659

can you try upgrading your gradle version?

This is what i use that works for me: android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

android/settings.gradle

pluginManagement {
   def flutterSdkPath = {
       def properties = new Properties()
       file("local.properties").withInputStream { properties.load(it) }
       def flutterSdkPath = properties.getProperty("flutter.sdk")
       assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
       return flutterSdkPath
   }
   settings.ext.flutterSdkPath = flutterSdkPath()

   includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

   repositories {
       google()
       mavenCentral()
       gradlePluginPortal()
   }
}

plugins {
   id "dev.flutter.flutter-plugin-loader" version "1.0.0"
   id "com.android.application" version '8.4.1' apply false
   id "org.jetbrains.kotlin.android" version "1.9.22" apply false

   id "com.google.gms.google-services" version "4.4.1" apply false
   id "com.google.firebase.firebase-perf" version "1.4.2" apply false
   id "com.google.firebase.crashlytics" version "3.0.1" apply false
}

include ":app"

And, if still not working, do you mind sharing your configs?

ThomasAunvik avatar Aug 29 '24 13:08 ThomasAunvik

Having the same issue as @DMrubencesario after going to 2.2.1. Upgrading Gradle from 7.6.3 to 8.6 resulted in the same build error:

ERROR:/home/lith/.gradle/caches/transforms-4/6968f2560310abc50484d452b3cc903f/transformed/lifecycle-livedata-core-2.8.4-runtime.jar: D8: java.lang.NullPointerException
...

Edit: re-ran with new project so all configurations except gradle version should be the default for a Flutter 3.24.1 project. Same error unfortunately.

Odalith avatar Aug 29 '24 14:08 Odalith

Having the same issue as @DMrubencesario after going to 2.2.1. But only on debug Builds with Gradle 7.6 (I can not upgrade to gradle 8+ as share package exist indirectly and will not let build), Release builds without problem: ERROR:/Users/user/.gradle/caches/transforms-3/f12166f053dc25a0be8380f6381377ec/transformed/lifecycle-livedata-core-2.8.4-runtime.jar: D8: java.lang.NullPointerException

hiloliddinj avatar Aug 30 '24 05:08 hiloliddinj

Just found what specifically is the issue and what fixes it: In your_proj/android/settings.gradle change the version of id "com.android.application" to something newer, like "8.4.1". Mine was originally "7.3.0".

Updated settings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.4.1" apply false// <-- Here
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"

@hiloliddinj I also tried with Gradle version 7.6.3 and it failed, asked for 8.6. So this doesn't fully solve your issue. This chart might help find the version combo that works for you

Odalith avatar Aug 30 '24 06:08 Odalith

Just found what specifically is the issue and what fixes it: In your_proj/android/settings.gradle change the version of id "com.android.application" to something newer, like "8.4.1". Mine was originally "7.3.0".

Updated settings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.4.1" apply false// <-- Here
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"

@hiloliddinj I also tried with Gradle version 7.6.3 and it failed, asked for 8.6. So this doesn't fully solve your issue. This chart might help find the version combo that works for you

Thanks a lot mate. you saved my countless hours trying to solve this problem 😁👍

hafidzaini avatar Aug 31 '24 08:08 hafidzaini

Just found what specifically is the issue and what fixes it: In your_proj/android/settings.gradle change the version of id "com.android.application" to something newer, like "8.4.1". Mine was originally "7.3.0".

Updated settings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.4.1" apply false// <-- Here
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"

@hiloliddinj I also tried with Gradle version 7.6.3 and it failed, asked for 8.6. So this doesn't fully solve your issue. This chart might help find the version combo that works for you

Thanks mate. I also deleted "share" package containing package (it was Alice) and update as you suggested gradle. It worked then

hiloliddinj avatar Aug 31 '24 21:08 hiloliddinj

Just chiming in here to add what worked / didn't work for me.

Flutter 3.24.2 + mapbox_maps_flutter 2.2.1 didn't build due to this error:

ERROR:/home/redacted/.gradle/caches/transforms-3/abe4cd01d4939bb9cb2e79505f114891/transformed/lifecycle-livedata-core-2.8.4-runtime.jar: R8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null

Upgrading AGP as others have suggested in this thread required several steps:

  • Used the AGP Upgrade Assistant to upgrade to 8.6 (available by opening the android project in Android Studio, Tools -> AGP Upgrade Assistant)
  • Fixed "Namespace not specified" build error due to flutter_compass by setting the subproject's namespace manually in android/build.gradle based on this Stackoverflow thread.
  • Plugins now required NDK version 26.1.10909125. Flutter hardcodes this to 23.1.7779620, so I had to override this in android/app/build.gradle, replacing the line that previously contained ndkVersion flutter.ndkVersion
  • flutter_local_notifications, which previously worked without changes to android/app/build.gradle, now required explicitly enabling core library desugaring

After all of this, it builds. But given that Flutter is firmly stuck on AGP 7.3.0, requiring these kinds of modifications seems really sketchy to me.

reiv avatar Sep 06 '24 09:09 reiv

Hi all sorry for the trouble, we've fixed Android build issues in https://github.com/mapbox/mapbox-maps-flutter/pull/712 which should be available as a part of 2.3.0 release.

evil159 avatar Oct 01 '24 10:10 evil159

great!

hafidzaini avatar Oct 01 '24 11:10 hafidzaini

After all of this, it builds. But given that Flutter is firmly stuck on AGP 7.3.0, requiring these kinds of modifications seems really sketchy to me.

@reiv Flutter SDK is generating Android projects with AGP 8.1.0 in the recent versions, 7.3.0 is probably the AGP version that was in use back when you had your project generated.

evil159 avatar Oct 01 '24 11:10 evil159

Closing this, feel free to reopen if you have any comments or questions.

evil159 avatar Oct 02 '24 12:10 evil159