EventBus - Subscriber class 及其超级 classes 没有带有 @subscribe 注释的 public 方法
EventBus - Subscriber class and its super classes have no public methods with the @subscribe annotation
我正在创建一个 Android 应用程序,使用 EventBus 将异步广播发布到其他 类,但我 运行 在执行过程中出错。
MainActivity.java
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class MainActivity extends AppCompatActivity {
//Globals
public String uname = null;
public double lat = 0;
public double lng = 0;
//Get GUI handles
public Button sendButton; //
public EditText username;
public Button MapButton; //
public EditText LatBox;
public EditText LngBox;
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//register EventBus
EventBus.getDefault().register(this);
super.onCreate(savedInstanceState);
//set GUI for MainActivity
setContentView(R.layout.activity_main);
//get handlers
LatBox = (EditText)findViewById(R.id.LatBox);
LngBox = (EditText)findViewById(R.id.LngBox);
MapButton = (Button)findViewById(R.id.locationButton);
//Call the class which will handle finding coordinates
MapButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent MapIntent = new Intent(getApplicationContext(), MapClass.class);
startActivityForResult(MapIntent, 0);
}
});
sendButton = (Button)findViewById(R.id.Submit);
//Set action for Button
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Get username from user
username = (EditText)findViewById(R.id.UsernameText);
uname = username.getText().toString();
//Generate intent to start IntentService
Intent i = new Intent(getApplicationContext(), Register.class);
//Put the extra field of username
i.putExtra("username", uname);
i.putExtra("latitude", lat);
i.putExtra("longitude", lng);
i.putExtra("type", "meetup.be2015.gcm_meetup.MAIN_ACTIVITY");
//Start the IntentService on a different thread
startService(i);
}
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(LatLng currentPos){
LatBox.setText(String.valueOf(currentPos.latitude));
LngBox.setText(String.valueOf(currentPos.longitude));
lat = currentPos.latitude;
lng = currentPos.longitude;
}
}
MapClass.java
import android.app.IntentService;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
public class MapClass extends AppCompatActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private GoogleMap mgoogleMap;
private LatLng latLng;
private GoogleApiClient client;
@Override
public void onMapReady(GoogleMap googleMap) {
mgoogleMap = googleMap;
mgoogleMap.setMyLocationEnabled(true); //Sets location to current position
buildGoogleApiClient();
mGoogleApiClient.connect();
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onDestroy() {
super.onDestroy();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
}
@Override
public void onConnected(Bundle bundle) {
Location MLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (MLastLocation != null) {
latLng = new LatLng(MLastLocation.getLatitude(), MLastLocation.getLongitude());
//Post the LatLng to MainActivity
EventBus.getDefault().post(latLng);
//Send sticky event to Register and MyGcmListenerService
EventBus.getDefault().postSticky(latLng);
} else {
Log.d("onConnected", "Value of LatLng is NULL");
latLng = new LatLng(0, 0); //equator
}
}
@Override
public void onConnectionSuspended(int i) {
//Notify
Log.d("ConnectionSuspended", "Connection Suspended. Status: " + i);
mgoogleMap.clear();
mGoogleApiClient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
//Notify
Log.d("ConnectionFailed", "Connection Failed. Status: " + connectionResult.toString());
mgoogleMap.clear();
mGoogleApiClient.disconnect();
}
@Subscribe
public void onEvent() {
Log.d("EVENT", "EVENT");
}
@Override
public void onStart() {
super.onStart();
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
}
}
LogCat 显示如下:
03-08 22:54:56.970 8570-8570/meetup.be2015.gcm_meetup E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{meetup.be2015.gcm_meetup/meetup.be2015.gcm_meetup.MapClass}:
org.greenrobot.eventbus.EventBusException: Subscriber class meetup.be2015.gcm_meetup.MapClass
and its super classes have no public methods with the @Subscribe annotation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
at android.app.ActivityThread.access0(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class meetup.be2015.gcm_meetup.MapClass
and its super classes have no public methods with the @Subscribe annotation
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:67)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:136)
at meetup.be2015.gcm_meetup.MapClass.onStart(MapClass.java:91)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
at android.app.Activity.performStart(Activity.java:5198)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2091)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
at android.app.ActivityThread.access0(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
为什么会这样?我做错了什么吗?
我觉得是因为MapClass.java里面的onEvent没有参数。你能试试预期的参数吗?
如果您在构建中使用混淆器,请确保这些行在您的混淆器配置文件中。
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
在我的情况下,我收到此错误是因为我没有在注册 EventBus 的 class 上写 @Subscribe。
我遇到了同样的问题,经过长时间的研究,我找到了每个案例的解决方案。此问题是由于在您尝试将事件总线注册为的 class 中缺少 @Subscribe public 方法 onEvent()
EventBus.getDefault().register(this)
。如果您使用事件总线
注册 class,则必须存在此函数
这可能有两种情况
使用 progruad:progruad 可能会修改方法 onEvent() 的名称,因为事件总线无法找到它。
将这些行放在您的程序规则中
-keepattributes 注释
-保留class成员class ** {
@org.greenrobot.eventbus.Subscribe;
}
-保持枚举 org.greenrobot.eventbus.ThreadMode { *;
}
- 如果您没有使用 progruard,那么您的 class 肯定缺少带有 @Subscribe 注释的 onEvent() 方法。这个带有方法的注解对于 EventBus 版本 3.0.0 是强制性的,所以仔细检查你的 class.
中是否存在这个方法
以防万一你的代码和我的一样:p
我必须将方法设置为 public
,因为它当前是 private
。
在我的例子中 onEvent()
是 private 并放置在 child class.
但是 register()
和 unregister()
在 parent class.
中被调用了
解决方案是 onEvent()
public.
在旁注中,从 EventBus 的 Google's implementation 切换到这个后,我遇到了同样的错误。这个错误让我抓狂,因为 Google 的 EventBus 也有一个 @Subscribe 注释,我使用的是那个注释而不是 greenrobot 提供的注释。
好吧,这对我来说是一个非常愚蠢的错误,但如果我能帮助像我这样的一个人,我会很高兴。
以防万一它会对某些人有所帮助,就我而言,我忘记将参数传递给接收方法,其他一切都很好。
当没有参数传递给接收方时 function/method,在这种情况下会抛出此异常。
ProGuard
ProGuard 混淆方法名称并可能删除未调用的方法(删除死代码)。因为不直接调用 Subscriber 方法,所以 ProGuard 假定它们未被使用。因此,如果启用 ProGuard 缩小,则必须告诉 ProGuard 保留那些订阅者方法。
在 ProGuard 配置文件 (proguard.cfg) 中使用以下规则来防止订阅者被删除:
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you usenter code heree AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
如果您使用混淆器,您将不会在调试模式下遇到这个问题。我在发行版中遇到了这个问题。在 proguard-rules.pro 文件中添加以下代码后,解决了我的问题。
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
我使用了来自错误包的 Subscribe 注释。
应该是
import org.greenrobot.eventbus.Subscribe
我在用
import com.squareup.otto.Subscribe
可以为某人提供帮助!
我的情况,我忘了在下面添加一行 buildTypes
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
更新答案,因为混淆器不再是默认设置。它变成了R8。关闭 R8 以确保。在 flutter 中,这将是:
flutter 构建 apk --no-shrink ...
只需从私人娱乐切换到 public,您就会看到奇迹。
1. 转到导入并删除此行:
import com.google.common.eventbus.Subscribe;
2. 并添加:
import org.greenrobot.eventbus.Subscribe;
3.删除@订阅重新添加。
4. 添加时确保您正在使用 org.greenrobot.eventbus 导入@Subscribe.
如果您使用的是 flutter,请将其添加到您应用的发布构建类型中 build.gradle
minifyEnabled false
shrinkResources false
我正在创建一个 Android 应用程序,使用 EventBus 将异步广播发布到其他 类,但我 运行 在执行过程中出错。
MainActivity.java
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class MainActivity extends AppCompatActivity {
//Globals
public String uname = null;
public double lat = 0;
public double lng = 0;
//Get GUI handles
public Button sendButton; //
public EditText username;
public Button MapButton; //
public EditText LatBox;
public EditText LngBox;
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//register EventBus
EventBus.getDefault().register(this);
super.onCreate(savedInstanceState);
//set GUI for MainActivity
setContentView(R.layout.activity_main);
//get handlers
LatBox = (EditText)findViewById(R.id.LatBox);
LngBox = (EditText)findViewById(R.id.LngBox);
MapButton = (Button)findViewById(R.id.locationButton);
//Call the class which will handle finding coordinates
MapButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent MapIntent = new Intent(getApplicationContext(), MapClass.class);
startActivityForResult(MapIntent, 0);
}
});
sendButton = (Button)findViewById(R.id.Submit);
//Set action for Button
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Get username from user
username = (EditText)findViewById(R.id.UsernameText);
uname = username.getText().toString();
//Generate intent to start IntentService
Intent i = new Intent(getApplicationContext(), Register.class);
//Put the extra field of username
i.putExtra("username", uname);
i.putExtra("latitude", lat);
i.putExtra("longitude", lng);
i.putExtra("type", "meetup.be2015.gcm_meetup.MAIN_ACTIVITY");
//Start the IntentService on a different thread
startService(i);
}
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(LatLng currentPos){
LatBox.setText(String.valueOf(currentPos.latitude));
LngBox.setText(String.valueOf(currentPos.longitude));
lat = currentPos.latitude;
lng = currentPos.longitude;
}
}
MapClass.java
import android.app.IntentService;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
public class MapClass extends AppCompatActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private GoogleMap mgoogleMap;
private LatLng latLng;
private GoogleApiClient client;
@Override
public void onMapReady(GoogleMap googleMap) {
mgoogleMap = googleMap;
mgoogleMap.setMyLocationEnabled(true); //Sets location to current position
buildGoogleApiClient();
mGoogleApiClient.connect();
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onDestroy() {
super.onDestroy();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
}
@Override
public void onConnected(Bundle bundle) {
Location MLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (MLastLocation != null) {
latLng = new LatLng(MLastLocation.getLatitude(), MLastLocation.getLongitude());
//Post the LatLng to MainActivity
EventBus.getDefault().post(latLng);
//Send sticky event to Register and MyGcmListenerService
EventBus.getDefault().postSticky(latLng);
} else {
Log.d("onConnected", "Value of LatLng is NULL");
latLng = new LatLng(0, 0); //equator
}
}
@Override
public void onConnectionSuspended(int i) {
//Notify
Log.d("ConnectionSuspended", "Connection Suspended. Status: " + i);
mgoogleMap.clear();
mGoogleApiClient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
//Notify
Log.d("ConnectionFailed", "Connection Failed. Status: " + connectionResult.toString());
mgoogleMap.clear();
mGoogleApiClient.disconnect();
}
@Subscribe
public void onEvent() {
Log.d("EVENT", "EVENT");
}
@Override
public void onStart() {
super.onStart();
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
}
}
LogCat 显示如下:
03-08 22:54:56.970 8570-8570/meetup.be2015.gcm_meetup E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{meetup.be2015.gcm_meetup/meetup.be2015.gcm_meetup.MapClass}:
org.greenrobot.eventbus.EventBusException: Subscriber class meetup.be2015.gcm_meetup.MapClass
and its super classes have no public methods with the @Subscribe annotation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
at android.app.ActivityThread.access0(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class meetup.be2015.gcm_meetup.MapClass
and its super classes have no public methods with the @Subscribe annotation
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:67)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:136)
at meetup.be2015.gcm_meetup.MapClass.onStart(MapClass.java:91)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
at android.app.Activity.performStart(Activity.java:5198)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2091)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
at android.app.ActivityThread.access0(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
为什么会这样?我做错了什么吗?
我觉得是因为MapClass.java里面的onEvent没有参数。你能试试预期的参数吗?
如果您在构建中使用混淆器,请确保这些行在您的混淆器配置文件中。
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
在我的情况下,我收到此错误是因为我没有在注册 EventBus 的 class 上写 @Subscribe。
我遇到了同样的问题,经过长时间的研究,我找到了每个案例的解决方案。此问题是由于在您尝试将事件总线注册为的 class 中缺少 @Subscribe public 方法 onEvent()
EventBus.getDefault().register(this)
。如果您使用事件总线
这可能有两种情况
使用 progruad:progruad 可能会修改方法 onEvent() 的名称,因为事件总线无法找到它。 将这些行放在您的程序规则中
-keepattributes 注释
-保留class成员class ** {
@org.greenrobot.eventbus.Subscribe;
}
-保持枚举 org.greenrobot.eventbus.ThreadMode { *;
}
- 如果您没有使用 progruard,那么您的 class 肯定缺少带有 @Subscribe 注释的 onEvent() 方法。这个带有方法的注解对于 EventBus 版本 3.0.0 是强制性的,所以仔细检查你的 class. 中是否存在这个方法
以防万一你的代码和我的一样:p
我必须将方法设置为 public
,因为它当前是 private
。
在我的例子中 onEvent()
是 private 并放置在 child class.
但是 register()
和 unregister()
在 parent class.
解决方案是 onEvent()
public.
在旁注中,从 EventBus 的 Google's implementation 切换到这个后,我遇到了同样的错误。这个错误让我抓狂,因为 Google 的 EventBus 也有一个 @Subscribe 注释,我使用的是那个注释而不是 greenrobot 提供的注释。
好吧,这对我来说是一个非常愚蠢的错误,但如果我能帮助像我这样的一个人,我会很高兴。
以防万一它会对某些人有所帮助,就我而言,我忘记将参数传递给接收方法,其他一切都很好。 当没有参数传递给接收方时 function/method,在这种情况下会抛出此异常。
ProGuard
ProGuard 混淆方法名称并可能删除未调用的方法(删除死代码)。因为不直接调用 Subscriber 方法,所以 ProGuard 假定它们未被使用。因此,如果启用 ProGuard 缩小,则必须告诉 ProGuard 保留那些订阅者方法。
在 ProGuard 配置文件 (proguard.cfg) 中使用以下规则来防止订阅者被删除:
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you usenter code heree AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
如果您使用混淆器,您将不会在调试模式下遇到这个问题。我在发行版中遇到了这个问题。在 proguard-rules.pro 文件中添加以下代码后,解决了我的问题。
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
我使用了来自错误包的 Subscribe 注释。
应该是
import org.greenrobot.eventbus.Subscribe
我在用
import com.squareup.otto.Subscribe
可以为某人提供帮助!
我的情况,我忘了在下面添加一行 buildTypes
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
更新答案,因为混淆器不再是默认设置。它变成了R8。关闭 R8 以确保。在 flutter 中,这将是:
flutter 构建 apk --no-shrink ...
只需从私人娱乐切换到 public,您就会看到奇迹。
1. 转到导入并删除此行:
import com.google.common.eventbus.Subscribe;
2. 并添加:
import org.greenrobot.eventbus.Subscribe;
3.删除@订阅重新添加。
4. 添加时确保您正在使用 org.greenrobot.eventbus 导入@Subscribe.
如果您使用的是 flutter,请将其添加到您应用的发布构建类型中 build.gradle
minifyEnabled false
shrinkResources false