Failed resolution of: Lio/flutter/plugins/imagepicker/ImagePickerPlugin$LifeCycleObserver

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lio/flutter/plugins/imagepicker/ImagePickerPlugin$LifeCycleObserver;
        at io.flutter.plugins.imagepicker.ImagePickerPlugin.a(ImagePickerPlugin.java:190)
        at io.flutter.plugins.imagepicker.ImagePickerPlugin.a(ImagePickerPlugin.java:156)
        at io.flutter.embedding.engine.FlutterEnginePluginRegistry.a(FlutterEnginePluginRegistry.java:315)
        at com.idlefish.flutterboost.containers.FlutterActivityAndFragmentDelegate.a(FlutterActivityAndFragmentDelegate.java:116)
        at com.idlefish.flutterboost.containers.BoostFlutterActivity.onCreate(BoostFlutterActivity.java:146)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at com.qiyukf.unicorn.m.a.callActivityOnCreate(QiyuInstrumentation.java:258)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

最近 项目中android端app遇到一闪退问题,测试同学反馈一打开电商模块就闪退,闪退log如上。看log可发现与ImagePicker有关,ImagePicker为电商模块中引用的一flutter插件,目前电商模块整体使用flutter开发,但自己本地打包测试无法复现,使用jenkins上的包可以必现。查了下代码,jenkins上打包时,是引用fat-aar把flutter项目中用的插件和我们自己的flutter模块打包到一个aar中,所以就怀疑是不是打包方式的问题。
用jadx-gui拆包看后,发现是这有个类的

ImagePickerPlugin.png

看到这就有点迷糊了,明明是有这个类的吗,为何报找不到异常呢?直接Google输入关键异常信息"Failed resolution of: Lio/flutter/plugins/imagepicker/ImagePickerPlugin$LifeCycleObserver",一看搜索结果还真有人遇到过这样的情况,异常信息都一样(匹配搜索结果),完整的看了下,发现其中和我遇到的情况也不一样啊,解决办法要么是降级gradle,要么是混淆的(我这边gradle是3.5.0,混淆之类的也都处理过了),没什么参考价值。
最后还是从头开始搞起,既然ImagePickerPlugin$LifeCycleObserver存在,为何会有NoClassDefFoundError异常呢?再看一遍ImagePickerPlugin$LifeCycleObserver,发现其实现接口ActivityLifecycleCallbacks和 DefaultLifecycleObserver,那么会不会是这两个类找不到呢?
其中ActivityLifecycleCallbacks在包android.app.Application中,这个肯定是存在的。而DefaultLifecycleObserver呢,从import androidx.lifecycle.DefaultLifecycleObserver;可看出其是androidx中的,会不会是因为没有引入这个依赖呢?
分别看拆包后的代码中androidx.lifecycle下的类,截图如下。可见闪退的包中是不存在DefaultLifecycleObserver的

闪退的包androidx.png
正常包androidx.png

目前解决办法:
项目的build.gradle中添加依赖implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'

至于为何通过fat-aar打包后引入的方式没有DefaultLifecycleObserver,但本地maven引入方式却有,还需要继续跟进了解。

你可能感兴趣的:(Failed resolution of: Lio/flutter/plugins/imagepicker/ImagePickerPlugin$LifeCycleObserver)