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

[Bug]: Requires newer version of Kotlin Gradle Plugin

Open anmol-me opened this issue 1 year ago • 26 comments
trafficstars

Please check the following before submitting a new issue.

Please select affected platform(s)

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

Steps to reproduce

  1. Install the dependency.
  2. Run in Android emulator without even importing the package.

Expected results

Should run without any errors.

Actual results

App doesn't run

Code sample

android\build

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

app\build

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
    flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
    flutterVersionName = "1.0"
}

android {
    namespace = "com.anisingh.travel_project"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.anisingh.travel_project"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = 28
        targetSdk = flutter.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

Version

12.0.0

Flutter Doctor output

e: C:/Users/Anmol/.gradle/caches/transforms-3/362b2d499a05b04c0c112f7a304aa7e2/transformed/jetified-kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. e: C:/Users/Anmol/.gradle/caches/transforms-3/a986ff86be3aa69fb7fd119d17309b08/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. e: C:/Users/Anmol/.gradle/caches/transforms-3/a986ff86be3aa69fb7fd119d17309b08/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. e: C:/Users/Anmol/.gradle/caches/transforms-3/a986ff86be3aa69fb7fd119d17309b08/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

FAILURE: Build failed with an exception.

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

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

  • 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 7s

┌─ 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 C:\Users\Anmol\FlutterProjects\travel_project\android\build.gradle: │ │ ext.kotlin_version = '' │ └────────────────────────────────────────────────────────────────────────────────────────────┘ Error: Gradle task assembleDebug failed with exit code 1

anmol-me avatar May 22 '24 06:05 anmol-me

i am also facing the same issue

FlutteriPOP avatar May 22 '24 06:05 FlutteriPOP

This is related to geolocator_android 4.6.0 A workaround is to add 4.5.5 to your dependencies until 4.6.0 gets fixed.

rminkler1 avatar May 22 '24 06:05 rminkler1

This is related to geolocator_android 4.6.0 A workaround is to add 4.5.5 to your dependencies until 4.6.0 gets fixed.

Thanks @rminkler1

  1. Add the following to dependencies: geolocator: ^12.0.0 geolocator_android: 4.5.5

  2. Run the following commands: flutter clean flutter pub get

anmol-me avatar May 22 '24 06:05 anmol-me

Thanks @rminkler1 Now Its Working Perfectolly

FlutteriPOP avatar May 22 '24 07:05 FlutteriPOP

Wow! It works 🤗 You just saved the day. You won't believe that I've been battling with the error for days

Muhammadurasheed avatar May 23 '24 15:05 Muhammadurasheed

Wow! It works 🤗 You just saved the day. You won't believe that I've been battling with the error for days

I do believe you, because I was also battling this for days. I updated Flutter and I thought I broke something with my Flutter install. It took me almost a week to figure out it was this package.

rminkler1 avatar May 23 '24 17:05 rminkler1

This is related to geolocator_android 4.6.0 A workaround is to add 4.5.5 to your dependencies until 4.6.0 gets fixed.

thank you bro

ravikumarbigwings avatar May 29 '24 07:05 ravikumarbigwings

@anmol-me @rminkler1 what version to use for location package?

osamanoor17 avatar May 29 '24 08:05 osamanoor17

geolocator: ^12.0.0 geolocator_android: 4.5.5

rminkler1 avatar May 29 '24 14:05 rminkler1

@rminkler1 sir i am asking for location package not for geolocator..

osamanoor17 avatar May 29 '24 14:05 osamanoor17

@rminkler1 sir i am asking for location package not for geolocator..

Then I'm afraid I don't understand what you are asking. Geolocator is the package that gets the location of the device. This thread is about a bug in the Android implementation of that package and how to workaround that bug until it is fixed. I've only used geolocator once and ran into this bug, so I'm afraid I can't help beyond this.

rminkler1 avatar May 29 '24 15:05 rminkler1

@Meizzosama Hey, please search if you can find a similar issue with the author of location package. If you can't find it, please raise the issue with the author.

Here is a link to help you get started: https://github.com/Lyokone/flutterlocation/issues

anmol-me avatar May 30 '24 05:05 anmol-me

@anmol-me Brother i found the solution. i-e, I haven't updated the kotlin version on file "settings.gradle" that's why it was giving me that error, but later on i fixed it. Thanks a bunch for your reply :)

osamanoor17 avatar May 30 '24 05:05 osamanoor17

@rminkler1 thanks, switching to geolocator_android: 4.5.5 saved me hours of researches....

saumon avatar Jun 03 '24 13:06 saumon

Facing the same problem, after searching for days found out that geolocator causing it. hope it will be fixed soon.

aliwaseem27 avatar Jun 03 '24 20:06 aliwaseem27

geolocator: ^12.0.0 geolocator_android: 4.5.5

So for some reason when you add

geolocator_android: 4.5.5 it fixes the issue and then you can remove geolocator_android: 4.5.5 afterwards and geolocator: ^12.0.0 will work without it.

Pieter-Uys avatar Jun 06 '24 09:06 Pieter-Uys

  1. geolocator_android

geolocator: ^12.0.0 still gives an error

cnLiuMing avatar Jun 07 '24 03:06 cnLiuMing

  1. geolocator_android

geolocator: ^12.0.0 still gives an error

Add the following two dependencies: geolocator: ^12.0.0 geolocator_android: 4.5.5

Run the following commands: flutter clean flutter pub get

rminkler1 avatar Jun 07 '24 03:06 rminkler1

geolocator: ^12.0.0 geolocator_android: 4.5.5

So for some reason when you add

geolocator_android: 4.5.5 it fixes the issue and then you can remove geolocator_android: 4.5.5 afterwards and geolocator: ^12.0.0 will work without it.

That might happen if you don't re-run pub get. I suspect if you run pub get again, it breaks again.

rminkler1 avatar Jun 07 '24 03:06 rminkler1

Thanks @rminkler1, fixed my issue

jsqi2009 avatar Jul 01 '24 07:07 jsqi2009

geolocator: ^12.0.0 geolocator_android: 4.5.5

So for some reason when you add geolocator_android: 4.5.5 it fixes the issue and then you can remove geolocator_android: 4.5.5 afterwards and geolocator: ^12.0.0 will work without it.

That might happen if you don't re-run pub get. I suspect if you run pub get again, it breaks again.

nope mine works perfectly without ' geolocator_android'🤷🏻 ran multiple pub gets and cleans and nothing breaks

Pieter-Uys avatar Jul 09 '24 20:07 Pieter-Uys

This Error Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... Running Gradle task 'assembleDebug'... e: C:/Users/M360 App 1/.gradle/caches/transforms-3/884371f8ba4c22f7d845ae45913c9f76/transformed/jetified-kotlin-stdlib-2.0.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. e: C:/Users/M360 App 1/.gradle/caches/transforms-3/884371f8ba4c22f7d845ae45913c9f76/transformed/jetified-kotlin-stdlib-2.0.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. e: C:/Users/M360 App 1/.gradle/caches/transforms-3/884371f8ba4c22f7d845ae45913c9f76/transformed/jetified-kotlin-stdlib-2.0.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

FAILURE: Build failed with an exception.

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

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

  • 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 9s

┌─ 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 G:\RobiulFlutterProject\crm-zayed_robiul\android\build.gradle: │ │ ext.kotlin_version = '' │ └────────────────────────────────────────────────────────────────────────────────────────────┘ Error: Gradle task assembleDebug failed with exit code 1

packace version: geolocator: ^12.0.0 geolocator_android: ^4.5.5

buildscript { ext.kotlin_version = '2.0.0' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

}

}

allprojects { repositories { google() mavenCentral() } }

rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(":app") }

tasks.register("clean", Delete) { delete rootProject.buildDir }

plugins { id "com.android.application" // START: FlutterFire Configuration id 'com.google.gms.google-services' // END: FlutterFire Configuration id "kotlin-android" // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin"

}

def localProperties = new Properties() def localPropertiesFile = rootProject.file("local.properties") if (localPropertiesFile.exists()) { localPropertiesFile.withReader("UTF-8") { reader -> localProperties.load(reader) } }

def flutterVersionCode = localProperties.getProperty("flutter.versionCode") if (flutterVersionCode == null) { flutterVersionCode = "1" }

def flutterVersionName = localProperties.getProperty("flutter.versionName") if (flutterVersionName == null) { flutterVersionName = "1.0" }

def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { namespace = "com.crm360employee.crm" compileSdk = 34 ndkVersion "25.1.8937393"

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

defaultConfig {

    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId = "com.crm360employee.crm"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
    minSdk = flutter.minSdkVersion
    targetSdk = flutter.targetSdkVersion
    versionCode = flutterVersionCode.toInteger()
    versionName = flutterVersionName

}

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now,
        // so `flutter run --release` works.

// signingConfig signingConfigs.debug signingConfig signingConfigs.release } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Other dependencies }

flutter { source = "../.." } cupertino_icons: ^1.0.6 page_transition: intl: url_launcher: get: shared_preferences: http: file_picker: ^8.0.3 image_picker: ^1.1.2 lottie: in_app_update: rive: ^0.13.5 iconsax_flutter: ^1.0.0 syncfusion_flutter_calendar: ^26.1.41 cached_network_image: ^3.3.1 shimmer: ^3.0.0 iconsax: ^0.0.8 path_provider: ^2.1.3 flutter_image_compress: ^2.3.0 gallery_saver: ^2.1.1 percent_indicator: ^4.2.3 flutter_otp_text_field: ^1.1.3+2 device_info_plus: ^10.1.0 firebase_core: ^3.2.0 firebase_messaging: ^15.0.3 flutter_local_notifications: ^17.2.1+1 animation_list: ^3.0.0 flutter_background_service: ^5.0.6 geolocator: ^12.0.0 geolocator_android: ^4.5.5 connectivity_plus: ^6.0.3 sqflite: ^2.3.3+1 socket_io_client: ^3.0.0-beta.2 googleapis: googleapis_auth: geocoding: ^3.0.0 badges: ^3.1.2 primer_progress_bar: ^0.4.2 aura_box: ^1.0.2

robiulM360ict avatar Jul 14 '24 05:07 robiulM360ict

You can try adding dependencies After that just try performing the above-mentioned steps.

geolocator: ^12.0.0

geolocator_android: 4.5.5

Make sure to perform these two steps just because I did not clean it, it took me 2 hours to figure it out flutter clean flutter pub get

khushpajwani avatar Jul 31 '24 13:07 khushpajwani

https://github.com/Baseflow/flutter-geolocator/issues/1517#issuecomment-2124001518~~

~~Thank you for providing the solution! This solves the issue for building the APK in debug mode, but it doesn't solve it when I need to build the APK for production~~

~~I receive the following errors and APK features don't work:~~


After further investigations I conclude the issue is related to another library. Please ignore this post.

tgbv avatar Aug 04 '24 14:08 tgbv

I wonder if it would work using the dependency override for the Android module instead of declaring it directly. I also saw an update to the Android module to fix some bugs. I don't think it fixes this issue, but it might work without the override now. Worth trying

rminkler1 avatar Aug 04 '24 16:08 rminkler1

2. flutter clean flutter pub get

thanks bro, i also fixed it by your comment. it's blocking me for two days....

BAStriver avatar Aug 15 '24 15:08 BAStriver

I am also facing the same issue...

geolocator: ^12.0.0 geolocator_android: 4.5.5

flutter clean flutter pub get

Thanks @rminkler1 fixed my issue

sajil-cookee avatar Sep 02 '24 05:09 sajil-cookee

Version 4.6.0 of the geolocator_android package depends on version 21.2.0 of the com.google.android.gms:play-services-location Java package, which intern depends on version 1.8.0 or higher of the Kotlin Android coroutines.

For new applications this shouldn't be a problem as the current version of Flutter uses version 1.8.22 of the Kotlin Android coroutines (see the android/settings.gradle file of the project).

However for applications created with Flutter versions prior to 3.24.2 the above error will show up as those applications are generated using version 1.7.10 of the Kotlin Android coroutines. There are a few solutions here:

Recommended solution:

  • Upgrade to the latest version of Flutter and make sure the Android project settings are also up to date (a nice migration guide can be found here: https://medium.com/@iam.umairimran/flutter-app-migration-guide-updating-to-flutter-3-19-0-ab8b66008838)

Alternative solution:

  • As mentioned by other people in this thread, override the dependency on the geolocator_android package and fallback to version 4.5.5. This could look as follows in the pubspec.yaml:
dependency_overrides:
  geolocator_android: 4.5.5

dependencies:
  flutter:
    sdk: flutter

  geolocator: ^13.0.1

I will go ahead and close this issue now as solutions are available.

mvanbeusekom avatar Sep 20 '24 09:09 mvanbeusekom