使用了官方的混淆配置:ProGuard - Open Source by greenrobot
如下:
-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);
}
但是打包运行程序后报错:
de.greenrobot.event.EventBusException: Subscriber class xxx and its super classes have no public methods with the @Subscribe annotation
检查程序发现明明每个接收方法都写了@Subscribe,为什么还会报错?
后来发现混淆配置中还需要增加一行(接收方法)
-keepclassmembers class ** {
public void onEvent*(**);
}
注(还有一个坑):程序所有的接收方法名必须都是onEvent(),否则将接收不到EventBus发的消息(当然,你也可以将你的接收方法名添加到混淆配置中,不进行混淆)
OK!搞定~
网友评论