flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[Bug]: With a new Gradle plugins

Open michaelnabil230 opened this issue 1 year ago • 7 comments
trafficstars

NOTE: This error with Flutter 3.19.0

Please select affected platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Expected results

I created a new project and added this package to test it, but I cannot extract the app version.

I've been running Flutter build APK for some time while installing another package with geolocator showing this error:

BUILD FAILED in 48s Running Gradle task 'assembleRelease'... 49.4s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ [!] Your project requires a newer version of the Kotlin Gradle plugin. │ │ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update /flutter-app/android/build.gradle: │ │ ext.kotlin_version = '' │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Gradle task assembleRelease failed with exit code 1

Actual results

Error

FAILURE: Build failed with an exception.

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

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.io.path.ExperimentalPathApi found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.io.path.PathRelativizer found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.io.path.PathsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10) Duplicate class kotlin.jvm.jdk8.JvmRepeatableKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.jvm.optionals.OptionalsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.streams.jdk8.StreamsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$1 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$2 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$3 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$4 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10) Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)

 Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
  • 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 8s Running Gradle task 'assembleRelease'... 9.1s Gradle task assembleRelease failed with exit code 1

Version

11.0.0

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.0, on macOS 14.3.1 23D60 darwin-arm64, locale
    en-EG)
[✓] 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 2023.1)
[✓] VS Code (version 1.86.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

michaelnabil230 avatar Feb 17 '24 20:02 michaelnabil230

Found a solution which works for me. Here's what I did:

  1. went to android/settings.gradle
  2. Changed the version number from "1.7.10" to "1.9.20" in the 3rd line of the following block of the code in settings.gradle file:

Before:

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

After:

 plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
} 
  1. Went to android/build.gradle and added the following block of code at the very top of the build.gradle file:
 buildscript {
    ext.kotlin_version = '1.5.31'
}
  1. ran the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
  1. Pressed F5, and it worked.

nabilbndev avatar Feb 18 '24 10:02 nabilbndev

This solution worked for me

Found a solution which works for me. Here's what I did:

1. went to `android/settings.gradle`

2. Changed the version number from `"1.7.10"` to `"1.9.20"` in the 3rd line of the following block of the code in `settings.gradle` file:

Before:

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

After:

 plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
} 
3. Went to `android/build.gradle` and added the following block of code at the very top of the `build.gradle` file:
 buildscript {
    ext.kotlin_version = '1.5.31'
}
4. ran the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
5. Pressed `F5`, and it worked.

hatch01 avatar Feb 18 '24 20:02 hatch01

The same problem here, I had to disable plugin by plugin to know which one was in conflict with the new version.

andrefedev avatar Feb 19 '24 00:02 andrefedev

Hi @michaelnabil230,

Thank you for reporting this issue, I was also able to reproduce it. The workaround suggested by @nabilbndev works which is a temporary solution for now. In the meantime we will look into a more permanent solution.

mvanbeusekom avatar Feb 19 '24 09:02 mvanbeusekom

Hi @michaelnabil230, @nabilbndev, @hatch01,

After diving into this issue I have found the culprit. This problem is caused by the upgrade of the com.google.android.gms:play-services-location from version 21.0.1 to 21.1.0.

Apparently Google changed some dependencies in the plugin which now requires Kotlin 1.9.0 or higher. I am a bit reluctant to rollback to the old version of the com.google.android.gms:play-services-location plugin as I am hoping (need confirmation yet) that this newer version resolves some issues related to slow location fixes.

I feel it would be best to update our README with the instructions mentioned by @nabilbndev. How would you all feel about that?

mvanbeusekom avatar Feb 19 '24 15:02 mvanbeusekom

Hi @mvanbeusekom,

From my point of view, we should not downgrade, as this will cause some problems for some users, but rather we should only update

michaelnabil230 avatar Feb 19 '24 15:02 michaelnabil230

Hello @mvanbeusekom, It'd be better if we can get a permanent solution. Even though the temporary solution works, IMHO it makes the app a bit laggy. Would you mind checking if the temporary solution degrades app performance or not?

nabilbndev avatar Feb 19 '24 19:02 nabilbndev

Found a solution which works for me. Here's what I did:

1. went to `android/settings.gradle`

2. Changed the version number from `"1.7.10"` to `"1.9.20"` in the 3rd line of the following block of the code in `settings.gradle` file:

Before:

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

After:

 plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
} 
3. Went to `android/build.gradle` and added the following block of code at the very top of the `build.gradle` file:
 buildscript {
    ext.kotlin_version = '1.5.31'
}
4. ran the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
5. Pressed `F5`, and it worked.

this solution worked for me

pjmd89 avatar Feb 23 '24 20:02 pjmd89

Found a solution which works for me. Here's what I did:

  1. went to android/settings.gradle
  2. Changed the version number from "1.7.10" to "1.9.20" in the 3rd line of the following block of the code in settings.gradle file:

Before:

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

After:

 plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
} 
  1. Went to android/build.gradle and added the following block of code at the very top of the build.gradle file:
 buildscript {
    ext.kotlin_version = '1.5.31'
}
  1. ran the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
  1. Pressed F5, and it worked.

In fact, only changing

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

to

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
}

worked for me!

pastelcode avatar Feb 28 '24 03:02 pastelcode

i tried everything mentioned in issues. only thing that worked for me was to add following lines to pubspec.yaml dependency_overrides: geolocator_android: 4.5.1

fazyamir avatar Feb 29 '24 13:02 fazyamir

Hi @michaelnabil230, @nabilbndev, @hatch01,

After some consideration we have decided to revert back to version 21.0.1 of the com.google.android.gms:play-services-location library as the new version simply isn't inline with the current stable version of Flutter.

Changes will land with PR #1463.

mvanbeusekom avatar Mar 19 '24 08:03 mvanbeusekom

Found a solution which works for me. Here's what I did:

  1. went to android/settings.gradle
  2. Changed the version number from "1.7.10" to "1.9.20" in the 3rd line of the following block of the code in settings.gradle file:

Before:

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

After:

 plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
} 
  1. Went to android/build.gradle and added the following block of code at the very top of the build.gradle file:
 buildscript {
    ext.kotlin_version = '1.5.31'
}
  1. ran the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
  1. Pressed F5, and it worked.

In fact, only changing

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

to

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.20" apply false
}

worked for me!

Also work after the > in fact, ..... on my project, thanks a lot man!

HikmetMelik avatar Apr 10 '24 21:04 HikmetMelik

Sometimes the problem is in some incompatible package, the ideal thing would be to identify it and change it for a compatible version or for another package, in my case it was to change the geolocator package from version 10.0.0 to 7.0.2

CarlosAlvarezdev avatar Jul 25 '24 12:07 CarlosAlvarezdev