简体   繁体   中英

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

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

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 .

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.

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 xxxx with 1.3.10

This should help you in resolve the error

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.

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.

转到 External Libraries / Flutter Plugins / google_api_availability / android / build.gradle 并将 ext.kotlin_version 更改为 LATEST_VERSION。

   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.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM