混淆报错,super classes have no public methods with the @Subscribe annotation

首先看一下错误Log

01-10 09:57:17.061 8649-8649/com.aaa.bbb E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.aaa.bbb, PID: 8649
                                                               org.greenrobot.eventbus.EventBusException: Subscriber class com.aaa.bbb.ccc.b.a and its super classes have no public methods with the @Subscribe annotation
                                                                   at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(Unknown Source:52)
                                                                   at org.greenrobot.eventbus.EventBus.register(Unknown Source:6)
                                                                   at com.icbc.bjmain.view.b.a.onCreate(Unknown Source:37)
                                                                   at android.support.v4.app.Fragment.performCreate(Unknown Source:15)
                                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source:440)
                                                                   at android.support.v4.app.FragmentTransition.addToFirstInLastOut(Unknown Source:76)
                                                                   at android.support.v4.app.FragmentTransition.calculateFragments(Unknown Source:18)
                                                                   at android.support.v4.app.FragmentTransition.startTransitions(Unknown Source:39)
                                                                   at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(Unknown Source:100)
                                                                   at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(Unknown Source:97)
                                                                   at android.support.v4.app.FragmentManagerImpl.execSingleAction(Unknown Source:31)
                                                                   at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(Unknown Source:6)
                                                                   at android.support.v4.app.FragmentPagerAdapter.finishUpdate(Unknown Source:6)
                                                                   at android.support.v4.view.ViewPager.populate(Unknown Source:388)
                                                                   at android.support.v4.view.ViewPager.populate(Unknown Source:2)
                                                                   at android.support.v4.view.ViewPager.onMeasure(Unknown Source:207)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                                                                   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.support.design.widget.CoordinatorLayout.onMeasureChild(Unknown Source:0)
                                                                   at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(Unknown Source:82)
                                                                   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(Unknown Source:0)
                                                                   at android.support.design.widget.CoordinatorLayout.onMeasure(Unknown Source:246)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.support.v4.widget.DrawerLayout.onMeasure(Unknown Source:204)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                                                                   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                   at android.support.v7.widget.ContentFrameLayout.onMeasure(Unknown Source:125)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1539)
                                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:823)
                                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:702)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1539)
                                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:823)
                                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:702)
                                                                   at android.view.View.measure(View.java:22281)
                                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
                                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                   at com.android.internal.policy.DecorView.onMeasure(DecorView.java:834)

项目中为了安全考虑,添加了混淆。没想到开启混淆后,在proguard-rules.pro文件写了一些混淆规则。但是没想到,还是出现了问题。原来是我项目中的EventBus出现的问题,然而,我已经将EventBus防混淆规则写了,为啥还是出现问题。百思不得其解。看了一下log。发现原来是没有@Subscribe这个注解。我明明已经添加上去了啊。我想,很有可能是混淆将我的注解给混淆掉了。怎么办呢。这时,我看到了一篇帖子:https://stackoverflow.com/questions/35874055/eventbus-subscriber-class-and-its-super-classes-have-no-public-methods-with-th  

大神上面有一个防止这个@Subscribe注解被混淆的一个规则

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

感谢大佬,添加完这个规则后,我的项目正常运行了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值