flutter build_error ai_generated true

Gradle 任务 assembleDebug 失败,退出码 1:NDK 版本不匹配。期望 (23.1.7779620) 但发现 (25.2.9519653)

Gradle task assembleDebug failed with exit code 1: NDK version mismatch. Expected (23.1.7779620) but found (25.2.9519653)

ID: flutter/gradle-ndk-version-mismatch

其他格式: JSON · Markdown 中文 · English
80%修复率
82%置信度
1证据数
2024-06-10首次发现

版本兼容性

版本状态引入弃用备注
Flutter 3.22.0 active
Android Gradle Plugin 8.2.0 active
NDK 23.1.7779620 active

根因分析

系统上安装的 Android NDK 版本与 Flutter 项目原生依赖所需的版本不匹配,导致编译失败。

English

The Android NDK version installed on the system does not match the version required by the Flutter project's native dependencies, causing compilation failures.

generic

官方文档

https://developer.android.com/ndk/downloads

解决方案

  1. Install the required NDK version via Android Studio SDK Manager or command line: sdkmanager 'ndk;23.1.7779620'. Then update android/gradle.properties: android.ndkVersion=23.1.7779620
  2. If you cannot install the exact version, modify the project's build.gradle to use the system NDK version and update any native dependencies that require the specific version. Example: ndkVersion = '25.2.9519653' in android/app/build.gradle, then test compatibility.
  3. Use 'flutter config --android-ndk /path/to/correct/ndk' to point Flutter to a compatible NDK installation.

无效尝试

常见但无效的做法:

  1. Delete the entire .gradle directory and rebuild. 90% 失败

    Deleting .gradle only clears caches; the NDK version mismatch is a system-level configuration issue.

  2. Set the NDK version in local.properties by force to the system version without adjusting dependencies. 70% 失败

    Forcing a different NDK version can break native library compilation if the C++ code relies on specific API levels.