今天在生成发布版,添加混淆的时候出现了bug,这也是预料中的事,猜想也知道是混淆的问题,EventBus一直报错:Caused by: c.a.a.e: Subscriber class **** and its super classes have no public methods with the @Subscribe annotation ,网上的解答都是没有加@Subscribe在订阅方法,其实我的都有加,而且debug版本都是可用的,只有release版本有问题,那就是proguard-rules.pro的问题,加上
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
不混淆eventbus中的类和方法。之前我只加了:
-keepclassmembers class ** {
public void onEvent*(**);
}
并不全面,就换成了上面的代码。完美解决!