签名apk中的Eventbus错误

Shi*_*til 2 java android greenrobot-eventbus-3.0

我发布一些事件和订阅代码在调试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
Run Code Online (Sandbox Code Playgroud)

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

我的活动中有这个订阅者

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

我正在注册和取消注册这样的

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

@Override
protected void onStop() {
    super.onStop();
    EventBus.getDefault().unregister(this);
}    
Run Code Online (Sandbox Code Playgroud)

Shi*_*til 5

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

ProGuard模糊了方法名称,可能会删除未调用的方法(死代码删除).由于不直接调用Subscriber方法,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);
}
Run Code Online (Sandbox Code Playgroud)