欢迎光临
我们一直在努力

flutter 编译打包真机打开闪退报couldn’t find “libflutter.so”

记录一次使用flutter开发完毕执行编译打包后出现的问题进行排查的步骤

使用flutter 开发app时真机调试一般都是使用vscode 运行命令

flutter run

然后在手机上进行调试一切正常

但是当使用vscode通过一下命令编译成正式版app时

yaudeMacBook-Pro:flutter_shop yau$ flutter build apk
Initializing gradle...                                              3.9s
Resolving dependencies...                                           1.8s
Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      59.1s
Built build/app/outputs/apk/release/app-release.apk (21.3MB).

然后手机安装app后无法打开直接闪退

具体操作步骤如下图

然后我们找到了错误日志具体如下:

2019-04-30 14:12:41.004 7858-7858/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.jokui.toyshungry, PID: 7858
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.jokui.toyshungry-Js73lG5fFyDYCvuRs7PTAw==/base.apk"],nativeLibraryDirectories=[/data/app/com.jokui.toyshungry-Js73lG5fFyDYCvuRs7PTAw==/lib/arm64, /data/app/com.jokui.toyshungry-Js73lG5fFyDYCvuRs7PTAw==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]] couldn't find "libflutter.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
        at java.lang.System.loadLibrary(System.java:1672)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:159)
        at io.flutter.view.FlutterMain.startInitialization(FlutterMain.java:134)
        at io.flutter.app.FlutterApplication.onCreate(FlutterApplication.java:22)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1162)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6566)
        at android.app.ActivityThread.access$1900(ActivityThread.java:267)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1963)
        at android.os.Handler.dispatchMessage(Handler.java:109)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:7470)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
2019-04-30 14:12:41.036 1985-3085/? E/AwareLog: SPKSchedFeature: Uid has been sent, ignore.
2019-04-30 14:12:41.049 1286-9846/? E/ReportTools: This is not beta user build

问题就是因为打包时没有引入arm64的libflutter的so文件导致在arm64架构手机上出现“兼容”问题。主要是引用so库的问题arm64cpu架构是可以像下兼容的,简单点就是arm64架构的cpu可以使用arm32的.so文件。出现问题真正原因是我们在引用so库时(引用的三方库中引用了so库)。

我们在app下的gradle文件加入如下代码

buildTypes {
     release {
         ndk{
             abiFilters "armeabi-v7a"
         }
     }
     debug {
         ndk {
             //这里要加上,否则debug包会出问题,后面三个为可选,x86建议加上不然部分模拟器回报错
             abiFilters "armeabi", "armeabi-v7a", "arm64-v8a",  "x86"
         }
     }
 }

至此问题解决

赞(0) 打赏
未经允许不得转载:卧龙岗 » flutter 编译打包真机打开闪退报couldn’t find “libflutter.so”
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏