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

Updates Lifecycle Runtime KTX and fixes build for flutter 3.24.0

Open ThomasAunvik opened this issue 1 year ago • 11 comments

What does this pull request do?

Fixes #629

Updates androidx.lifecycle:lifecycle-runtime-ktx to 2.8.4

Important Note: https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0

Had to remove getLifecycle from LifecycleHelper else this error would appear:

Running Gradle task 'assembleDebug'...
e: file:///home/thaun/.pub-cache/git/mapbox-maps-flutter-86d75763e5a7217170accc0b22dcc03120f56fe9/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:74:14 Platform declaration clash: The following declarations have the same JVM signature (getLifecycle()Landroidx/lifecycle/Lifecycle;):
    fun `<get-lifecycle>`(): Lifecycle defined in com.mapbox.maps.mapbox_maps.MapboxMapController.LifecycleHelper
    fun getLifecycle(): Lifecycle defined in com.mapbox.maps.mapbox_maps.MapboxMapController.LifecycleHelper
e: file:///home/thaun/.pub-cache/git/mapbox-maps-flutter-86d75763e5a7217170accc0b22dcc03120f56fe9/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:84:5 Platform declaration clash: The following declarations have the same JVM signature (getLifecycle()Landroidx/lifecycle/Lifecycle;):
    fun `<get-lifecycle>`(): Lifecycle defined in com.mapbox.maps.mapbox_maps.MapboxMapController.LifecycleHelper
    fun getLifecycle(): Lifecycle defined in com.mapbox.maps.mapbox_maps.MapboxMapController.LifecycleHelper

FAILURE: Build failed with an exception.

What is the motivation and context behind this change?

To be able to build

Pull request checklist:

  • [ ] Add a changelog entry.
  • [ ] Write tests for all new functionality. If tests were not written, please explain why.
  • [ ] Add documentation comments for any added or updated public APIs.

Misc

To temporarely use for your project to be able to build:

dependency_overrides:
  mapbox_maps_flutter:
    git:
      url: https://github.com/ThomasAunvik/mapbox-maps-flutter.git
      ref: c9cf8a0c117e2a96e35f8ddbb0edb4291473448a

ThomasAunvik avatar Jul 31 '24 10:07 ThomasAunvik

So I tried this fix but still can't compile, it give me:

ERROR:/Users/jaumard/.gradle/caches/transforms-3/3eea5313676f4b09a015decd9d7cff77/transformed/lifecycle-livedata-core-2.8.4-runtime.jar: D8: java.lang.NullPointerException

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDevelopmentDebug'.
> Could not resolve all files for configuration ':app:developmentDebugRuntimeClasspath'.
   > 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=23, 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 DexingWithClasspathTransform: /Users/jaumard/.gradle/caches/transforms-3/3eea5313676f4b09a015decd9d7cff77/transformed/lifecycle-livedata-core-2.8.4-runtime.jar.
         > Error while dexing.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 19s
Error: Gradle task assembleDevelopmentDebug failed with exit code 1

jaumard avatar Aug 07 '24 11:08 jaumard

@jaumard 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"

ThomasAunvik avatar Aug 08 '24 08:08 ThomasAunvik

@ThomasAunvik with your changes it look like it works perfectly! Thanks for the help :)

jaumard avatar Aug 08 '24 09:08 jaumard

@jaumard¿Puedes intentar actualizar tu versión de gradle?

Esto es lo que uso y me funciona: 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"

Thank you.

isaacsuazo7 avatar Aug 08 '24 21:08 isaacsuazo7

I have a Flutter project that started out 4 years ago so on a very old version of Flutter. It has been moved along with every updated of flutter since that time. Currently it Assembles fine on Flutter 3.22.x with Mapbox 2.1 but when moving to Flutter 3.24 the mapbox 2.2 it never compiles.

e: file:///D:/development/pub.home/hosted/pub.dev/mapbox_maps_flutter-2.2.0/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:10:27 Unresolved reference: ViewTreeLifecycleOwner e: file:///D:/development/pub.home/hosted/pub.dev/mapbox_maps_flutter-2.2.0/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:///D:/development/pub.home/hosted/pub.dev/mapbox_maps_flutter-2.2.0/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:176:20 Unresolved reference: ViewTreeLifecycleOwner e: file:///D:/development/pub.home/hosted/pub.dev/mapbox_maps_flutter-2.2.0/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:183:5 Unresolved reference: ViewTreeLifecycleOwner

What I have tried -----------------------------------------------------------------------

I am running on Windows 10. I have tried VSCode and Android Studio 2024.1.1 Patch 2. I have upgrade everything I can think of in Android studio. I have AGP updated to 8.5.1 which happened by opening the Android folder on my Flutter project in Android Studio and using the AGP upgrade tool.

My Flutter Doctor ------------------------------------------------------------------------

PS D:\android\caminha> flutter doctor --verbose [√] Flutter (Channel stable, 3.24.0, on Microsoft Windows [Version 10.0.19045.4780], locale en-US) • Flutter version 3.24.0 on channel stable at D:\development\Android\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 80c2e84975 (3 weeks ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) • Android SDK at D:\development\Android\sdk • Platform android-35, build-tools 35.0.0 • ANDROID_HOME = D:\development\Android • ANDROID_SDK_ROOT = D:\development\Android\Sdk • Java binary at: D:/development/java.home\bin\java • Java version OpenJDK Runtime Environment Temurin-17.0.10+7 (build 17.0.10+7) • All Android licenses accepted.

[√] Android Studio (version 2024.1) • Android Studio at D:/development/tools/AndroidStudio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = D:/development/tools/AndroidStudio • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] Connected device (1 available) • SM G973U1 (mobile) • RF8M216A2RT • android-arm64 • Android 12 (API 31)

[√] Network resources • All expected network resources are available.

penhorwood avatar Aug 20 '24 16:08 penhorwood

setttings.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.5.2' apply false
    id "org.jetbrains.kotlin.android" version "1.9.22" apply false
}

include ":app"

penhorwood avatar Aug 20 '24 16:08 penhorwood

@penhorwood is this with the fix of https://github.com/mapbox/mapbox-maps-flutter/pull/633#user-content-how-to-fix ?

As this PR fixes the errors of Unresolved reference: ViewTreeLifecycleOwner .

Should you still get the exact same error with the packaged path being pub.home/hosted/pub.dev/mapbox_maps_flutter-2.2.0, then the package is not being pulled from git.

You need to add the dependency override as linked above, and not from pub.dev to build with 3.24.

ThomasAunvik avatar Aug 20 '24 20:08 ThomasAunvik

@ThomasAunvik -- I tried the below steps multiple times. Not sure why Flutter 3.24 will not work.

On flutter 3.22.3 ran dart pub cache clean - which removes all of the pub.home files ran flutter clean ran flutter pub get ran flutter pub upgrade ran flutter pub outdated ran flutter run --debug - on to my phone

App works normally

I upgrade to flutter 3.24 ran dart pub cache clean - which removes all of the pub.home files ran flutter clean ran flutter pub get ran flutter pub upgrade ran flutter pub outdated ran flutter run --debug - on to my phone

I get the ViewTreeLifecycleOwner mapbox_maps_flutter-2.2.0/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt:10:27 Unresolved reference: ViewTreeLifecycleOwner

The only difference is Flutter 3.24

penhorwood avatar Aug 20 '24 22:08 penhorwood

I reviewed the code being downloaded from pub.dev ( mapbox_maps_flutter-2.2.0 ). The changelog.md says 2.2.0

That code does NOT have the changes from #633 on it.

penhorwood avatar Aug 21 '24 14:08 penhorwood

@ThomasAunvik - Ok, sorry for the noise on this pull request. I finally noticed that your changes did NOT make it into version mapbox_maps_flutter-2.2.0. Do we have any idea when this will be merged? I will merge your changes into my local version just to move on to Flutter 3.24.

penhorwood avatar Aug 21 '24 15:08 penhorwood

Changes merged into local version. Able to move on to Flutter 3.24 without issue.

penhorwood avatar Aug 21 '24 15:08 penhorwood

@ThomasAunvik Thank you for looking into this, closing this in favor of https://github.com/mapbox/mapbox-maps-flutter/pull/668

evil159 avatar Aug 27 '24 09:08 evil159