Flutter | The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher
Solution 1
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
.
Solution 2
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.
Solution 3
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
Solution 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.
Solution 5
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.
Related videos on Youtube
TSR
Updated on December 30, 2021Comments
-
TSR over 2 years
I am trying to add firebase dependencies. When I run
flutter run
I getThe 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
-
yvan vander sanden over 5 yearsRight now, this is the better approach. Just adding google_api_availability: 1.0.6 to pubspec.yaml is enough.