flutter build_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
1Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.22.0 active
Android Gradle Plugin 8.2.0 active
NDK 23.1.7779620 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 85% success 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
    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. 75% success 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.
    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. 80% success Use 'flutter config --android-ndk /path/to/correct/ndk' to point Flutter to a compatible NDK installation.
    Use 'flutter config --android-ndk /path/to/correct/ndk' to point Flutter to a compatible NDK installation.

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. Delete the entire .gradle directory and rebuild. 90% fail

    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% fail

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