android混淆后崩溃:EventBus报错

一、错误信息

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xx/com.xx.xx.MainActivity}: m.a.b.e: Subscriber class com.xx.xx.MainActivity and its super classes have no public methods with the @Subscribe annotation

Caused by: m.a.b.e: Subscriber class com.xx.xx.MainActivity and its super classes have no public methods with the @Subscribe annotation

二、错误分析

       根据错误信息提示:MainActivity这个Subscribe类及其父类中都没有使用@Subscribe注解修饰的公共方法。

        1、检查是否有@Subscribe注解修饰的方法,当前类和其父类中至少有一个;

        2、检查该方法是否为公共方法,即用public修饰;

        3、检查该方法是否带有参数;

        4、若混淆前无报错,混淆后崩溃,即需要EventBus混淆配置;

三、EventBus混淆配置

        仅针对EventBus3.0及其后版本。

1、在proguard-rules.pro文件中添加以下内容

-keepattributes *Annotation*
-keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { 
    *; 
}

# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    <init>(java.lang.Throwable);
}

2、修改build.gradle文件

buildTypes {
    //根据你自己打包类型添加
    debug {
        ...
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        ...
    }
    ...
}

 不要自己走进泥沼  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值