flutter build_error ai_generated true

Invalid argument(s): Could not load native library: /data/app/.../lib/arm64/libflutter.so: incompatible ABI version

ID: flutter/incompatible-abi-version

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.16.0 active
Flutter 3.22.0 active
Android NDK r25c active

Root Cause

The Flutter engine native library (libflutter.so) was compiled for a different Android ABI than the device's CPU architecture, often due to building with an incorrect target platform or using a mismatched NDK version.

generic

中文

Flutter 引擎原生库 (libflutter.so) 是为与设备 CPU 架构不同的 Android ABI 编译的,通常是由于使用错误的目标平台构建或 NDK 版本不匹配。

Official Documentation

https://docs.flutter.dev/deployment/android#abi-splitting

Workarounds

  1. 85% success Run 'flutter clean' and rebuild with the correct target platform. For ARM64 devices, use 'flutter build apk --target-platform android-arm64'. Example: flutter clean flutter build apk --target-platform android-arm64 --release
    Run 'flutter clean' and rebuild with the correct target platform. For ARM64 devices, use 'flutter build apk --target-platform android-arm64'. Example:
      flutter clean
      flutter build apk --target-platform android-arm64 --release
  2. 80% success Update the Android NDK version to match Flutter's requirements. In android/app/build.gradle, set: ndkVersion "25.1.8937393" Then run 'flutter clean' and rebuild.
    Update the Android NDK version to match Flutter's requirements. In android/app/build.gradle, set:
      ndkVersion "25.1.8937393"
    Then run 'flutter clean' and rebuild.
  3. 75% success Enable ABI splitting in android/app/build.gradle to generate separate APKs for each ABI: android { splits { abi { enable true reset() include 'arm64-v8a', 'armeabi-v7a', 'x86_64' } } }
    Enable ABI splitting in android/app/build.gradle to generate separate APKs for each ABI:
      android {
        splits {
          abi {
            enable true
            reset()
            include 'arm64-v8a', 'armeabi-v7a', 'x86_64'
          }
        }
      }

中文步骤

  1. 运行 'flutter clean' 并使用正确的目标平台重新构建。对于 ARM64 设备,使用 'flutter build apk --target-platform android-arm64'。示例:
      flutter clean
      flutter build apk --target-platform android-arm64 --release
  2. 更新 Android NDK 版本以匹配 Flutter 要求。在 android/app/build.gradle 中设置:
      ndkVersion "25.1.8937393"
    然后运行 'flutter clean' 并重新构建。
  3. 在 android/app/build.gradle 中启用 ABI 分割,为每个 ABI 生成单独的 APK:
      android {
        splits {
          abi {
            enable true
            reset()
            include 'arm64-v8a', 'armeabi-v7a', 'x86_64'
          }
        }
      }

Dead Ends

Common approaches that don't work:

  1. Set 'android:extractNativeLibs="true"' in AndroidManifest.xml 80% fail

    This flag controls APK packaging but does not fix the ABI mismatch; the library still has the wrong ABI.

  2. Add all ABIs to the build.gradle abiFilters 60% fail

    Including all ABIs increases APK size but doesn't resolve an incompatible ABI; the device still gets the wrong library if the build targets a different ABI.

  3. Delete the build folder and rebuild without cleaning 70% fail

    Without cleaning, the stale library persists; 'flutter clean' is required to remove the cached native libraries.