mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
290 stars 119 forks source link

Unresolved reference: ViewTreeLifecycleOwner #629

Closed LuisChiej closed 1 month ago

LuisChiej commented 3 months ago

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.

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

vchrisb commented 3 months ago

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

jaumard commented 3 months ago

With last stable I have same issue

DMrubencesario commented 3 months ago

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.

ThomasAunvik commented 3 months ago

@DMrubencesario what error do you get?

DMrubencesario commented 3 months ago

@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

ThomasAunvik commented 3 months ago

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

jnorkus commented 3 months ago

My workaround was to downgrade from Flutter 3.24.0 to 3.22.3.

saconger commented 3 months ago

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

andyngdz commented 3 months ago

Current Flutter 3.24.0 is still getting the issues

jnorkus commented 2 months ago

Latest plugin version 2.2.0 still has the same issue.

ilhamskh commented 2 months ago

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

Koleshy commented 2 months ago

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

hiloliddinj commented 2 months ago

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
evil159 commented 2 months ago

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.

DMrubencesario commented 2 months ago

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.

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?

ThomasAunvik commented 2 months ago

@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?

Odalith commented 2 months ago

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.

hiloliddinj commented 2 months ago

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

Odalith commented 2 months ago

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

hafidzaini commented 2 months ago

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 😁👍

hiloliddinj commented 2 months ago

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

reiv commented 2 months ago

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:

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.

evil159 commented 1 month ago

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.

hafidzaini commented 1 month ago

great!

evil159 commented 1 month ago

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 commented 1 month ago

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