Flutter | The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher
Asked Answered
P

10

15

I am trying to add firebase dependencies. When I run flutter run I get

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
The following dependencies do not satisfy the required version:
project ':google_api_availability' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71

Pubscec.yaml

dependencies:
  flutter:
    sdk: flutter
  firebase_auth: ^0.8.1
  google_sign_in: ^4.0.1
  cloud_firestore: ^0.9.0+1
  firebase_core: ^0.3.0+1
  firebase_storage: ^2.0.1
  cupertino_icons: ^0.1.2
  font_awesome_flutter: ^8.0.1
  country_code_picker: ^1.1.0
  fluttertoast: ^2.0.7
  image_picker: ^0.4.6
  shared_preferences: ^0.4.2
  cached_network_image: ^0.4.1
  intl: ^0.15.7
  geolocator: ^2.1.1
  http: ^0.11.3+14
  flutter_google_places: ^0.1.4+1
  location: ^1.1.6
  uuid: ^1.0.3
  auto_size_text: 0.3.0

build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

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

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.myapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'  // Gradle plugin
Philoprogenitive answered 14/2, 2019 at 15:14 Comment(1)
The discussions in There are similar issues where the discussions might help github.com/flutter/flutter/issues/26889, github.com/flutter/flutter/issues/26145, github.com/flutter/flutter/issues/23626 might help to figure it out.Hindi
Q
27

You can find which package depends on google_api_availability by running flutter packages pub deps on the root of the project - this will list all the direct and transitive dependencies of your project in a tree view.

I couldn't find a way to display the plugin dependencies of a package - I guess you'll only find out once you try to build it.

The problem is you are using version 3.3.1 of the Android Gradle plugin, which enforces Kotlin 1.3.0 or above. At the same time, the geolocator package depends on google_api_availability, which seems to be using Kotlin 1.2.71. At the moment there is no version of google_api_availability that uses Kotlin 1.3.0 or above, so you only have 1 solution - downgrade the Android Gradle plugin to version 3.2.1.

Questionless answered 15/2, 2019 at 10:32 Comment(2)
Thank you so much :) I changed my gradle version for dependencies dependencies { classpath 'com.android.tools.build:gradle:7.3.1' // I changed this to 7.2.1 ,and It worked classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } You can find this code is in this file ../android/build.gradleAreola
This fixed it. And clear explanation btw, thankyouCrosse
G
8
   buildscript {
    ext.kotlin_version = '1.6.10' //-> i added
    repositories {
        google()
        mavenCentral()
    }

dependencies {
  classpath 'com.android.tools.build:gradle:4.1.3'
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"//->added

}

Just added the two line above to build.gradle and it worked. Even if there is a warning like;"Kotlin version that is used for building with Gradle (1.6.10) differs from the one bundled into the IDE plugin (1.3.72) " Anyway i think i need to update IDE plugin soon.

Greaseball answered 30/12, 2021 at 9:0 Comment(0)
G
7

In android folder you shall see file named as build.gradle

You would see a piece of code

buildscript {
    ext.kotlin_version = 'x.x.xx'
    repositories {
        google()
        jcenter()
    }

edit the version of property ext.kotlin_version by replacing x.x.xx with 1.3.10

This should help you in resolve the error

Greeneyed answered 18/1, 2020 at 12:12 Comment(0)
C
4
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
The following dependencies do not satisfy the required version:
project ':google_api_availability' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71

The solution we used was to include the package and all their dependency directly in the flutter build environment. !! This might not be ideal in the long run, but will help you while this AndroidX migration is happening and messing with your builds.

In the pubspec.yaml we included specific versions like so

geolocator: 3.0.0               # AndroidX - Breaking! 
google_api_availability: 1.0.6  # Geolocator Dependency. 
meta: 1.1.6                     # Geolocator Dependency. 
permission_handler: 2.2.0       # Geolocator & Meta Dependency.

The breakage for us happend between the google_api_availability v1.0.6 and v2.0.0

You can find which package depends on google_api_availability by doing as Ovidiu sayes or by opening https://pub.dartlang.org/ and type "dependency:google_api_availability" in the search bar. Also on each package page you can see the dependency and who depends on them.

Chloroform answered 21/2, 2019 at 12:10 Comment(1)
Right now, this is the better approach. Just adding google_api_availability: 1.0.6 to pubspec.yaml is enough.Mosstrooper
B
2

I just had to change the kotlin_version in android/build.gradle file:

buildscript {
    // change here:
    ext.kotlin_version = '1.3.21'
    dependencies {
        // kotlin version is used here:
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

After the changes in BuildScript and dependencies, the error is gone.

Benzophenone answered 26/1, 2020 at 7:21 Comment(0)
U
1

Go to External Libraries / Flutter Plugins / google_api_availability / android / build.gradle and changed ext.kotlin_version to LATEST_VERSION.

Ulyanovsk answered 31/8, 2020 at 11:23 Comment(0)
R
1

2024 additional info Upgrade ext.kotlin_version to the latest version Run flutter pub upgrade

Rustyrut answered 3/1 at 22:34 Comment(0)
S
0

My problem started with an HTTP connection getting closed early. Then somehow that problem changed to Android X issue.

To solve this android x issue I followed steps of https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#not-recommended-manually-migrate-your-app but instead, it leads me to another problem of version. I was using geolocator 1.6.3 and that was calling google API's developed in kotlin 1.2.x. The current gradle 3.4.1 requires kotlin 1.3.1 and above but that was not a possibility. So there was a bottleneck of version.

So

  • I degraded the gradle to 3.3.0 and the geolocator problem was solved.
  • lastly, I upgraded the geolocator to 5.0.1 and gradle to 3.4.1 and all things were solved.
Sera answered 14/6, 2019 at 5:29 Comment(0)
J
0

ext.kotlin_version = '1.3.50' => ext.kotlin_version = '1.6.0' that's work for me.I hope this can resolve your problem.

Jaimie answered 23/2, 2022 at 8:18 Comment(0)
M
-4

The problem is you are using version 3.3.1 or the higher version of the Android Gradle plugin, which enforces to have Kotlin 1.3.0 or above. so you only have 1 solution - downgrade the Android Gradle plugin to version 3.2.1.

Millimicron answered 7/2, 2020 at 7:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.