一、错误信息
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'
...
}
...
}
不要自己走进泥沼