当前位置:   article > 正文

混淆报错,super classes have no public methods with the @Subscribe annotation_subscriber class and its super classes have no pub

subscriber class and its super classes have no public methods with the @subs

首先看一下错误Log

  1. 01-10 09:57:17.061 8649-8649/com.aaa.bbb E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.aaa.bbb, PID: 8649
  3. org.greenrobot.eventbus.EventBusException: Subscriber class com.aaa.bbb.ccc.b.a and its super classes have no public methods with the @Subscribe annotation
  4. at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(Unknown Source:52)
  5. at org.greenrobot.eventbus.EventBus.register(Unknown Source:6)
  6. at com.icbc.bjmain.view.b.a.onCreate(Unknown Source:37)
  7. at android.support.v4.app.Fragment.performCreate(Unknown Source:15)
  8. at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source:440)
  9. at android.support.v4.app.FragmentTransition.addToFirstInLastOut(Unknown Source:76)
  10. at android.support.v4.app.FragmentTransition.calculateFragments(Unknown Source:18)
  11. at android.support.v4.app.FragmentTransition.startTransitions(Unknown Source:39)
  12. at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(Unknown Source:100)
  13. at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(Unknown Source:97)
  14. at android.support.v4.app.FragmentManagerImpl.execSingleAction(Unknown Source:31)
  15. at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(Unknown Source:6)
  16. at android.support.v4.app.FragmentPagerAdapter.finishUpdate(Unknown Source:6)
  17. at android.support.v4.view.ViewPager.populate(Unknown Source:388)
  18. at android.support.v4.view.ViewPager.populate(Unknown Source:2)
  19. at android.support.v4.view.ViewPager.onMeasure(Unknown Source:207)
  20. at android.view.View.measure(View.java:22281)
  21. at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
  22. at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
  23. at android.view.View.measure(View.java:22281)
  24. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  25. at android.support.design.widget.CoordinatorLayout.onMeasureChild(Unknown Source:0)
  26. at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(Unknown Source:82)
  27. at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(Unknown Source:0)
  28. at android.support.design.widget.CoordinatorLayout.onMeasure(Unknown Source:246)
  29. at android.view.View.measure(View.java:22281)
  30. at android.support.v4.widget.DrawerLayout.onMeasure(Unknown Source:204)
  31. at android.view.View.measure(View.java:22281)
  32. at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
  33. at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
  34. at android.view.View.measure(View.java:22281)
  35. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  36. at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
  37. at android.view.View.measure(View.java:22281)
  38. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  39. at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
  40. at android.support.v7.widget.ContentFrameLayout.onMeasure(Unknown Source:125)
  41. at android.view.View.measure(View.java:22281)
  42. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  43. at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1539)
  44. at android.widget.LinearLayout.measureVertical(LinearLayout.java:823)
  45. at android.widget.LinearLayout.onMeasure(LinearLayout.java:702)
  46. at android.view.View.measure(View.java:22281)
  47. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  48. at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
  49. at android.view.View.measure(View.java:22281)
  50. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  51. at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1539)
  52. at android.widget.LinearLayout.measureVertical(LinearLayout.java:823)
  53. at android.widget.LinearLayout.onMeasure(LinearLayout.java:702)
  54. at android.view.View.measure(View.java:22281)
  55. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6668)
  56. at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
  57. 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注解被混淆的一个规则

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/251271
推荐阅读
相关标签
  

闽ICP备14008679号