Java 有符号apk中的Eventbus错误
我发布了一些事件,订阅的代码在debug apk上正常工作,但当我使用密钥库签署apk并安装应用程序时,相同的代码崩溃Java 有符号apk中的Eventbus错误,java,android,greenrobot-eventbus-3.0,Java,Android,Greenrobot Eventbus 3.0,我发布了一些事件,订阅的代码在debug 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.
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);
}
将其添加到proguard配置文件中 ProGuard会混淆方法名称,并可能删除未调用的方法(死代码删除)。因为订户方法不是直接调用的,所以ProGuard将它们误认为未使用。因此,如果启用ProGuard缩小,则必须告诉ProGuard保留这些订户方法。在您的ProGuard配置文件(ProGuard.cfg)中使用以下snip以防止删除订阅服务器:
-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);
}
-keepclassmembers类**{
@org.greenrobot.eventbus.Subscribe;
}
-保持枚举org.greenrobot.eventbus.ThreadMode{*;}
#仅当使用AsyncExecutor时才需要
-keepclassmembers类*扩展org.greenrobot.eventbus.util.ThrowableFailureEvent{
(java.lang.Throwable);
}
可以尝试将字符串包装到您自己的自定义POJO中。(创建一个简单的类,其中包含一个字符串类型的字段和一个getter)。看看它是否有区别。您是否在发布版本中使用proguard?