如何解决Flutter的UnsatisfiedLinkError(找不到libflutter.so)问题?
解决Flutter启动时的UnsatisfiedLinkError(找不到libflutter.so)问题
崩溃信息
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myawesomeapp/com.example.myawesomeapp.MainActivity}: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/base.apk", zip file "/data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.en.apk", zip file "/data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.es.apk", zip file "/data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.x86.apk", zip file "/data/app/com.example.myawesomeapp-zqi6k7PQCL8VlHwCIoANUA==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/lib/x86, /data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/base.apk!/lib/x86, /data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.en.apk!/lib/x86, /data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.es.apk!/lib/x86, /data/app/com.example.myawesomeapp-dghasjbcdcjdfhcn==/split_config.x86.apk!/lib/x86, /data/app/com.example.myawesomeapp-zqi6k7PQCL8VlHwCIoANUA==/split_config.xxhdpi.apk!/lib/x86, /system/lib, /system/vendor/lib]]] couldn't find "libflutter.so" at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
解决方法
配置正确的ABI架构
在android/app/build.gradle的defaultConfig中添加ndk配置,确保覆盖目标设备的主流架构:android { defaultConfig { ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } }避免只指定少数架构,导致部分设备缺失对应库文件。
禁用APK拆分(若启用)
APK拆分可能将native库分散到不同APK中,部分设备下载后无法获取libflutter.so。在android/app/build.gradle中禁用ABI拆分:android { splits { abi { enable false } } }若必须保留拆分,需确保所有拆分APK包含必要的ABI库。
清理缓存并重新构建
执行以下命令清理旧缓存,重新生成完整的编译产物:flutter clean flutter pub get flutter build apk --release升级Flutter SDK
旧版本SDK可能存在编译bug,升级到稳定版:flutter upgrade检查Gradle插件兼容性
确保android/build.gradle中的Gradle插件版本与当前Flutter SDK兼容,比如Flutter 3.x推荐使用7.0及以上版本的Gradle插件。
内容的提问来源于stack exchange,提问作者Israr
相关产品推荐
相关产品推荐

