美文网首页
Android EventBus打包混淆后运行的问题

Android EventBus打包混淆后运行的问题

作者: 启朗 | 来源:发表于2019-03-27 18:04 被阅读0次

    使用了官方的混淆配置: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!搞定~

    相关文章

      网友评论

          本文标题:Android EventBus打包混淆后运行的问题

          本文链接:https://www.haomeiwen.com/subject/jgrtbqtx.html