Android UI片段<-&燃气轮机;事件总线<-&燃气轮机;服务

Android UI片段<-&燃气轮机;事件总线<-&燃气轮机;服务,android,android-fragments,greenrobot-eventbus,Android,Android Fragments,Greenrobot Eventbus,我在UI片段和后台服务之间进行了交互。 我使用EventBus。 当然,如果活动被停止/终止,则没有订阅服务器 以下是代码,您可以理解: public class LocationService extends Service { //... EventBus.getDefault().post(new MessageEventLocationClient(data)); } public class ClientFragment extends Fragment {

我在UI片段和后台服务之间进行了交互。 我使用EventBus。 当然,如果活动被停止/终止,则没有订阅服务器

以下是代码,您可以理解:

public class LocationService extends Service {
    //...
    EventBus.getDefault().post(new MessageEventLocationClient(data));
}


public class ClientFragment extends Fragment {
    //...
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEventLocationClient event) {
        // update UI
        textViewLastSentData.setText(event.trackData.lastLatLon());
    }
}
一切都好

然而,以下是从Google Play开发者控制台发送给我的报告:

Devices with errors 14:
Google Nexus 7 (flo) - Android 5.0
Google Nexus 9 (flounder) - Android 5.0
Google Pixel (sailfish) - Android 7.1
Motorola XT1096 (victara) - Android 4.4
...


Exceptions:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.tim4dev.imokhere/com.tim4dev.imokhere.MainActivity}: org.a.a.e:
Subscriber class com.tim4dev.imokhere.c and its super 
classes have no public methods with the @Subscribe annotation
...
这是什么意思

这真的是个问题吗

那怎么办呢

类似的问题也存在


UPD。感谢大家。

如前所述,您需要指示proguard不要删除带有@Subscribe注释的方法。如果它们未使用,Proguard将删除它们,因为EventBus将使用反射查找它们,所以它们很可能未使用。您可以从以下位置向proguard配置文件添加一些指令:

EventBus 3.0.x的新规则## # http://greenrobot.org/eventbus/documentation/proguard/ -keepattributes*注释* -keepclassmembers类**{ @org.greenrobot.eventbus.Subscribe; } -保持枚举org.greenrobot.eventbus.ThreadMode{*;} #仅当使用AsyncExecutor时才需要 -keepclassmembers类*扩展org.greenrobot.eventbus.util.ThrowableFailureEvent{ (java.lang.Throwable); }
如果这种情况一直发生,可能ProGuard正在删除
onMessageEvent()
,因为没有任何东西直接调用它。
## New rules for EventBus 3.0.x ##
# http://greenrobot.org/eventbus/documentation/proguard/

-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);
}