Flutter Android:一个或多个插件需要更高的 Android NDK 版本

sos*_*nus 4 android gradle build.gradle gradle-plugin flutter

一个或多个插件需要更高的 Android NDK 版本。

通过将以下内容添加到 /Users/qqq/data/github/qqq/qqq/android/app/build.gradle 来修复此问题: android { ndkVersion 21.3.6528147 ... }

但是如果我添加ndkVersion并且我的文件看起来像这样:


android {
    compileSdk 31

    ndkVersion 21.3.6528147

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
...

Run Code Online (Sandbox Code Playgroud)

我收到不同的错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/qqq/data/qqq/qqq/qqq/android/app/build.gradle' line: 61

* What went wrong:
Could not compile build file '/Users/qqq/data/github/qqq/qqq/android/app/build.gradle'.
> startup failed:
  build file '/Users/qqq/data/github/qqq/qqq/android/app/build.gradle': 61: Unexpected input: '{' @ line 61, column 9.
     android {
             ^

  1 error
Run Code Online (Sandbox Code Playgroud)

Ruc*_*hit 15

根据官方文档(https://developer.android.com/ndk/downloads),最新的 ndk 版本只是25.0.8775105更新到最新版本,错误应该消失了。

2022年的解决方案:

android {
    ndkVersion "25.0.8775105" <-- add this line
}
Run Code Online (Sandbox Code Playgroud)

2023 年 3 月的解决方案:

android {
    ndkVersion "25.2.9519653"
}
Run Code Online (Sandbox Code Playgroud)