美文网首页
android原生集成flutter.aar报错:Failed

android原生集成flutter.aar报错:Failed

作者: Duzzi | 来源:发表于2020-01-12 17:57 被阅读0次

问题

flutter工程如果依赖了第三方插件或本地插件,打包成aar集成到Android原生项目中会报Failed to call observer method,详细日志如下:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx.MainActivity}: java.lang.RuntimeException: Failed to call observer method
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
        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:1831)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6806)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

原因

flutter build aar或者flutter build apk打包aar的时候并没有将第三方插件打包到flutter-release.aar里面

解决

一、初级解决

  1. 首先使用命令flutter build aar

此时flutter工程和依赖的第三方插件会在flutter工程根目录下的build/host/outputs/repo下分别生成aar,如图所示

image.png
  1. 然后将这些aar拷贝到Android原生工程进行依赖即可
image.png

二、高级解决

利用fat-aar将这些aar合并打包成一个aar
参考flutter1.8打包aar上传maven集成到原生android工程这篇文章对打包脚本做了一个简化。

脚本及工程demo:
https://github.com/duzzi/flutter_lib_test

我的运行环境:

os:macOs
gradle plugin: classpath 'com.android.tools.build:gradle:3.2.1'
gradle:gradle-4.10.2-all
java:jdk1.8
flutter:stable, v1.9.1

ps:需要保证flutter工程中.android下的gradlesupport包、minSdkVersion等版本一致。

thanks:
https://www.jianshu.com/p/2258760e9540
https://juejin.im/post/5cd51f61f265da039c056e39
https://github.com/CarGuo/flutter_app_lib

相关文章

网友评论

      本文标题:android原生集成flutter.aar报错:Failed

      本文链接:https://www.haomeiwen.com/subject/ystwactx.html