flutter build_error ai_generated true

Invalid argument(s): 无法加载原生库: /data/app/.../lib/arm64/libflutter.so: ABI 版本不兼容

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

ID: flutter/incompatible-abi-version

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

版本兼容性

版本状态引入弃用备注
Flutter 3.16.0 active — — —
Flutter 3.22.0 active — — —
Android NDK r25c active — — —

根因分析

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

English

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

官方文档

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

解决方案

  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'
          }
        }
      }

无效尝试

常见但无效的做法:

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

    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% 失败

    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% 失败

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