【问题标题】:Flutter | The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher颤振 | Android Gradle 插件仅支持 Kotlin Gradle 插件版本 1.3.0 及更高版本
【发布时间】:2019-07-08 16:02:22
【问题描述】:

我正在尝试添加 firebase 依赖项。当我运行flutter run 时,我得到了

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

【问题讨论】:

标签: android gradle build flutter


【解决方案1】:

您可以通过在项目的根目录上运行 flutter packages pub deps 来查找依赖于 google_api_availability 的包 - 这将在树视图中列出项目的所有直接和传递依赖项。

我找不到显示包的插件依赖项的方法 - 我猜你只有在尝试构建它时才会发现。

问题是您使用的是 Android Gradle 插件的 3.3.1 版本,它强制执行 Kotlin 1.3.0 或更高版本。同时geolocator包依赖google_api_availability,貌似是在使用Kotlin1.2.71。目前还没有使用 Kotlin 1.3.0 或更高版本的 google_api_availability 版本,因此您只有一种解决方案 - 将 Android Gradle 插件降级到版本 3.2.1

【讨论】:

    【解决方案2】:

    在 android 文件夹中,您将看到名为 build.gradle 的文件

    你会看到一段代码

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

    通过将 x.x.xx 替换为 1.3.10 来编辑属性 ext.kotlin_version 的版本

    这应该可以帮助您解决错误

    【讨论】:

      【解决方案3】:
         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
      
      }
      

      只需将上面的两行添加到 build.gradle 就可以了。 即使有类似警告;“用于使用 Gradle (1.6.10) 构建的 Kotlin 版本与捆绑到 IDE 插件 (1.3.72) 中的版本不同” 无论如何,我认为我需要尽快更新 IDE 插件。

      【讨论】:

        【解决方案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
        

        我们使用的解决方案是将包及其所有依赖项直接包含在 Flutter 构建环境中。 !!从长远来看,这可能并不理想,但会在此 AndroidX 迁移发生并干扰您的构建时为您提供帮助。

        pubspec.yaml 中,我们包含了类似的特定版本

        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.
        

        我们的中断发生在 google_api_availability v1.0.6 和 v2.0.0 之间

        您可以按照 Ovidiu sayes 或打开 https://pub.dartlang.org/ 并在搜索栏中输入“dependency:google_api_availability”来查找依赖于 google_api_availability 的包。同样在每个包页面上,您可以看到依赖关系以及谁依赖它们。

        【讨论】:

        • 现在,这是更好的方法。只需将 google_api_availability: 1.0.6 添加到 pubspec.yaml 就足够了。
        【解决方案5】:

        我的问题始于 HTTP 连接提前关闭。然后不知何故,这个问题变成了 Android X 问题。

        为了解决这个 android x 问题,我遵循了https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#not-recommended-manually-migrate-your-app 的步骤,但相反,它导致了另一个版本问题。我使用的是 geolocator 1.6.3,它正在调用在 kotlin 1.2.x 中开发的谷歌 API。当前的 gradle 3.4.1 需要 kotlin 1.3.1 及更高版本,但这是不可能的。所以存在版本瓶颈。

        所以

        • 我将 gradle 降级为 3.3.0,地理定位器问题得到解决。
        • 最后,我将 geolocator 升级到 5.0.1,gradle 升级到 3.4.1,一切都解决了。

        【讨论】:

          【解决方案6】:

          我只需要更改 android/build.gradle 文件中的 kotlin_version:

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

          BuildScript 和依赖项更改后,错误消失了。

          【讨论】:

            【解决方案7】:

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

            【讨论】:

              【解决方案8】:

              问题是您使用的是 Android Gradle 插件的 3.3.1 或更高版本,它强制使用 Kotlin 1.3.0 或更高版本。所以您只有 1 个解决方案 - 将 Android Gradle 插件降级到版本 3.2.1

              【讨论】:

                猜你喜欢
                • 2019-07-03
                • 2020-06-11
                • 2023-02-18
                • 2023-04-11
                • 2019-07-18
                • 1970-01-01
                • 2019-10-24
                • 2022-10-21
                相关资源
                最近更新 更多