Flutter|Android Gradle插件仅支持KotlinGradle插件版本1.3.0及更高版本

qkf9rpyu  于 2023-06-27  发布在  Android
关注(0)|答案(9)|浏览(260)

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

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

Pubscec.yaml

  1. dependencies:
  2. flutter:
  3. sdk: flutter
  4. firebase_auth: ^0.8.1
  5. google_sign_in: ^4.0.1
  6. cloud_firestore: ^0.9.0+1
  7. firebase_core: ^0.3.0+1
  8. firebase_storage: ^2.0.1
  9. cupertino_icons: ^0.1.2
  10. font_awesome_flutter: ^8.0.1
  11. country_code_picker: ^1.1.0
  12. fluttertoast: ^2.0.7
  13. image_picker: ^0.4.6
  14. shared_preferences: ^0.4.2
  15. cached_network_image: ^0.4.1
  16. intl: ^0.15.7
  17. geolocator: ^2.1.1
  18. http: ^0.11.3+14
  19. flutter_google_places: ^0.1.4+1
  20. location: ^1.1.6
  21. uuid: ^1.0.3
  22. auto_size_text: 0.3.0

build.gradle

  1. buildscript {
  2. repositories {
  3. google()
  4. jcenter()
  5. }
  6. dependencies {
  7. classpath 'com.android.tools.build:gradle:3.3.1'
  8. classpath 'com.google.gms:google-services:4.2.0'
  9. }
  10. }
  11. allprojects {
  12. repositories {
  13. google()
  14. jcenter()
  15. }
  16. }
  17. rootProject.buildDir = '../build'
  18. subprojects {
  19. project.buildDir = "${rootProject.buildDir}/${project.name}"
  20. }
  21. subprojects {
  22. project.evaluationDependsOn(':app')
  23. }
  24. task clean(type: Delete) {
  25. delete rootProject.buildDir
  26. }

app/build.gradle

  1. def localProperties = new Properties()
  2. def localPropertiesFile = rootProject.file('local.properties')
  3. if (localPropertiesFile.exists()) {
  4. localPropertiesFile.withReader('UTF-8') { reader ->
  5. localProperties.load(reader)
  6. }
  7. }
  8. def flutterRoot = localProperties.getProperty('flutter.sdk')
  9. if (flutterRoot == null) {
  10. throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
  11. }
  12. apply plugin: 'com.android.application'
  13. apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
  14. android {
  15. compileSdkVersion 28
  16. lintOptions {
  17. disable 'InvalidPackage'
  18. }
  19. defaultConfig {
  20. // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  21. applicationId "com.example.myapp"
  22. minSdkVersion 16
  23. targetSdkVersion 28
  24. versionCode 1
  25. versionName "1.0"
  26. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  27. }
  28. buildTypes {
  29. release {
  30. // TODO: Add your own signing config for the release build.
  31. // Signing with the debug keys for now, so `flutter run --release` works.
  32. signingConfig signingConfigs.debug
  33. }
  34. }
  35. }
  36. flutter {
  37. source '../..'
  38. }
  39. dependencies {
  40. testImplementation 'junit:junit:4.12'
  41. androidTestImplementation 'com.android.support.test:runner:1.0.2'
  42. androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  43. }
  44. apply plugin: 'com.google.gms.google-services' // Gradle plugin
ztyzrc3y

ztyzrc3y1#

你可以通过在项目的根目录下运行flutter packages pub deps来找到哪个包依赖于google_api_availability-这将在树状视图中列出项目的所有直接和传递依赖项。
我找不到一种方法来显示一个包的插件依赖关系-我想你只有在尝试构建它时才会发现。
问题是您正在使用Android Gradle插件的3.3.1版本,该版本强制执行Kotlin1.3.0或更高版本。与此同时,geolocator包依赖于google_api_availability,它似乎使用了Kotlin1.2.71。目前没有使用Kotlin1.3.0或更高版本的google_api_availability版本,因此您只有一个解决方案-将Android Gradle插件降级到3.2.1版本。

uyhoqukh

uyhoqukh2#

  1. buildscript {
  2. ext.kotlin_version = '1.6.10' //-> i added
  3. repositories {
  4. google()
  5. mavenCentral()
  6. }
  7. dependencies {
  8. classpath 'com.android.tools.build:gradle:4.1.3'
  9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"//->added
  10. }

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

3df52oht

3df52oht3#

在android文件夹中,您将看到名为build.gradle的文件
你会看到一段代码

  1. buildscript {
  2. ext.kotlin_version = 'x.x.xx'
  3. repositories {
  4. google()
  5. jcenter()
  6. }

通过将x.x.xx替换为1.3.10来编辑属性ext.Kotlin_version的版本
这将帮助您解决错误

wi3ka0sx

wi3ka0sx4#

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

我们使用的解决方案是将包及其所有依赖项直接包含在flutter构建环境中。!!从长远来看,这可能不是理想的,但会帮助你,而这个AndroidX迁移正在发生,并扰乱你的构建。
pubspec.yaml中,我们包含了如下的特定版本

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

我们的中断发生在google_API_availability v1.0.6和v2.0.0之间
你可以按照Ovidiu说的那样或者打开https://pub.dartlang.org/并在搜索栏中输入“dependency:google_api_availability”来找到哪个包依赖于google_API_availability。在每个包页面上,您还可以看到依赖关系以及依赖它们的人。

nbysray5

nbysray55#

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

  1. buildscript {
  2. // change here:
  3. ext.kotlin_version = '1.3.21'
  4. dependencies {
  5. // kotlin version is used here:
  6. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  7. }
  8. }

在BuildScript和依赖项中进行更改后,错误消失了。

webghufk

webghufk6#

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

busg9geu

busg9geu7#

我的问题开始于一个HTTP连接提前关闭。然后这个问题变成了Android X问题。
为了解决这个android x问题,我遵循了www.example.com的步骤https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#not-recommended-manually-migrate-your-app,但相反,它导致了另一个版本问题。我使用的是geolocator 1.6.3,它调用了在Kotlin1.2.x中开发的Google API。当前的gradle 3.4.1需要Kotlin1.3.1及更高版本,但这是不可能的。因此出现了版本瓶颈。
所以呢

  • 我把gradle降级到3.3.0,地理定位器问题解决了。
  • 最后,我把geolocator升级到5.0.1,把gradle升级到3.4.1,所有的问题都解决了。
uklbhaso

uklbhaso8#

ext.Kotlin_version = '1.3.50' => ext.kotlin_version = '1.6.0'这对我来说很好。我希望这可以解决你的问题。

xam8gpfp

xam8gpfp9#

问题是您使用的是3.3.1或更高版本的Android Gradle插件,它强制要求使用Kotlin1.3.0或更高版本。所以你只有一个解决方案-将Android Gradle插件降级到版本3.2.1

相关问题