2

我发布了一些事件,订阅的代码在调试 apk 上正常工作,但是当我用我的密钥库签署 apk 并安装应用程序时,相同的代码会崩溃。

java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.example.friendz/com.example.friendz.shivaraj.activities.MainActivity}: 
a.a.a.h: Subscriber class com.example.friendz.shivaraj.activities.MainActivity
 and its super classes have no public methods with the @Subscribe annotation

但我的主要活动有定义了@Subscribe 的订阅者

我的活动中有此订阅者

@Subscribe
public void updateLocationEvent(String isStartLoc) {
    Log.d("eventbuus", "stop event rcvd");
 if (isStartLoc.equals("start")) {
    startLocationUpdates();
 } else {
    stopLocationUpdates();
 }
}

我正在像这样注册和注销

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
    EventBus.getDefault().register(this);
}

@Override
protected void onStop() {
    super.onStop();
    EventBus.getDefault().unregister(this);
}    
4

1 回答 1

5

将此添加到您的 proguard 配置文件中

ProGuard 会混淆方法名称,并且可能会删除未被调用的方法(死代码删除)。因为没有直接调用订阅者方法,所以 ProGuard 将它们误认为是未使用的。因此,如果您启用 ProGuard 缩小,您必须告诉 ProGuard 保留这些订阅者方法。在您的 ProGuard 配置文件 (proguard.cfg) 中使用以下片段来防止订阅者被删除:

-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);
}
于 2016-07-26T06:04:39.003 回答