Flutter android 构建需要更新版本的 Kotlin Gradle 插件

问题描述 投票:0回答:1

我正在尝试使用 flutter 3.24.3 构建我的 flutter 应用程序。早些时候,该应用程序使用 flutter 版本 < 3. With flutter > 3 成功构建,但我收到此错误:

┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                                 │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update the  │
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of            │
│ /home/ncd/AndroidStudioProjects/netr/android/settings.gradle.                                          │
│                                                                                                        │
│ Alternatively (if your project was created before Flutter 3.19), update                                │
│ /home/ncd/AndroidStudioProjects/netr/android/build.gradle                                              │
│ ext.kotlin_version = '<latest-version>'                                                                │
└────────────────────────────────────────────────────────────────────────────────────────────────────────┘

我已经像这样更新了settings.gradle:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "2.0.21" apply false
}

我在代码中搜索了org.jetbrains.kotlin.android


grep -iIRn org.jetbrains.kotlin.android .
./android/settings.gradle:22:    id "org.jetbrains.kotlin.android" version "2.0.21" apply false
./windows/flutter/ephemeral/.plugin_symlinks/wakelock_plus/example/android/settings.gradle:22:    id 'org.jetbrains.kotlin.android' version '1.8.22' apply false
./windows/flutter/ephemeral/.plugin_symlinks/package_info_plus/example/android/settings.gradle:22:    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
./linux/flutter/ephemeral/.plugin_symlinks/wakelock_plus/example/android/settings.gradle:22:    id 'org.jetbrains.kotlin.android' version '1.8.22' apply false
./linux/flutter/ephemeral/.plugin_symlinks/package_info_plus/example/android/settings.gradle:22:    id "org.jetbrains.kotlin.android" version "1.9.23" apply false

我认为上述内容不应成为问题的原因,因为这些文件是示例

并在代码中搜索ext.kotlin_version


grep -iIRn ext.kotlin_version .
./windows/flutter/ephemeral/.plugin_symlinks/wakelock_plus/android/build.gradle:5:    ext.kotlin_version = '1.7.22'
./windows/flutter/ephemeral/.plugin_symlinks/media_kit_video/example/android/build.gradle:2:    ext.kotlin_version = '1.7.10'
./windows/flutter/ephemeral/.plugin_symlinks/package_info_plus/android/build.gradle:5:    ext.kotlin_version = '1.7.22'
./linux/flutter/ephemeral/.plugin_symlinks/wakelock_plus/android/build.gradle:5:    ext.kotlin_version = '1.7.22'
./linux/flutter/ephemeral/.plugin_symlinks/media_kit_video/example/android/build.gradle:2:    ext.kotlin_version = '1.7.10'
./linux/flutter/ephemeral/.plugin_symlinks/package_info_plus/android/build.gradle:5:    ext.kotlin_version = '1.7.22'

但是,我不确定上述内容是否导致问题,因为这些文件存在于 linux 和 windows 目录中,而 android 构建失败。

有人可以帮我了解如何解决这个问题吗?

我正在使用命令 flutter build apk 进行构建。并期望构建成功。另请注意,上述应用程序的 Linux 构建成功了。

android flutter kotlin
1个回答
0
投票

我遇到了这个问题,并通过添加到 app/build.gradle 的代码来解决它

    allprojects {
               .
               .
               .       
          } // keep all project and under it add this code
    ext {
        compileSdkVersion   = 34
        targetSdkVersion    = 34
        appCompatVersion    = "1.7.0" }

并在:

rootProject.buildDir = '../build'

添加这行代码:

subprojects {
    afterEvaluate {
        android {
            compileSdkVersion 34
        }
    }
}

然后再次运行

flutter build apk
© www.soinside.com 2019 - 2024. All rights reserved.