greenrobot/EventBus · critical · RuntimeException
It looks like you are using EventBus on Android, make sure t
Error message
It looks like you are using EventBus on Android, make sure to add the "eventbus" Android library to your dependencies.
What it means
Thrown by EventBus.register(Object) when the Android SDK is detected on the classpath but the EventBus Android compatibility components are not. The check is done via AndroidDependenciesDetector.isAndroidSDKAvailable() && !areAndroidComponentsAvailable(): EventBus core detects it is running inside an Android environment (java.lang.NoClassDefFoundError-based probing of android classes) but the main-thread support classes (HandlerPoster etc., shipped in the eventbus-android artifact / greenrobot eventbus with android classifier) are missing. It deliberately crashes at register time instead of failing later during event delivery on the main thread.
Source
Thrown at EventBus/src/org/greenrobot/eventbus/EventBus.java:145
sendSubscriberExceptionEvent = builder.sendSubscriberExceptionEvent;
sendNoSubscriberEvent = builder.sendNoSubscriberEvent;
throwSubscriberException = builder.throwSubscriberException;
eventInheritance = builder.eventInheritance;
executorService = builder.executorService;
}
/**
* Registers the given subscriber to receive events. Subscribers must call {@link #unregister(Object)} once they
* are no longer interested in receiving events.
* <p/>
* Subscribers have event handling methods that must be annotated by {@link Subscribe}.
* The {@link Subscribe} annotation also allows configuration like {@link
* ThreadMode} and priority.
*/
public void register(Object subscriber) {
if (AndroidDependenciesDetector.isAndroidSDKAvailable() && !AndroidDependenciesDetector.areAndroidComponentsAvailable()) {
// Crash if the user (developer) has not imported the Android compatibility library.
throw new RuntimeException("It looks like you are using EventBus on Android, " +
"make sure to add the \"eventbus\" Android library to your dependencies.");
}
Class<?> subscriberClass = subscriber.getClass();
List<SubscriberMethod> subscriberMethods = subscriberMethodFinder.findSubscriberMethods(subscriberClass);
synchronized (this) {
for (SubscriberMethod subscriberMethod : subscriberMethods) {
subscribe(subscriber, subscriberMethod);
}
}
}
// Must be called in synchronized block
private void subscribe(Object subscriber, SubscriberMethod subscriberMethod) {
Class<?> eventType = subscriberMethod.eventType;
Subscription newSubscription = new Subscription(subscriber, subscriberMethod);
CopyOnWriteArrayList<Subscription> subscriptions = subscriptionsByEventType.get(eventType);
if (subscriptions == null) {View on GitHub (pinned to 0194926b3b)
Solutions
- Add the EventBus Android library to the Android module dependencies: dependencies { implementation 'org.greenrobot:eventbus:3.3.1' } (the Gradle Android artifact ships the Android components) — or with Maven use org.greenrobot:eventbus with the android classifier
- If mixing Java and Android modules, depend on the plain Java artifact only in pure-JVM modules and on the Android artifact in app/com.android.* modules
- If packaging manually (fat jars), verify org.greenrobot.eventbus.android.MainThreadSupport/HandlerPoster classes end up in the final artifact
- In non-Android JVM tests, make sure a stubbed android.jar does not leak onto the test classpath so the SDK-available detection returns false
Example fix
// before (Java-only artifact used in Android app)
dependencies {
implementation 'org.greenrobot:eventbus-java:3.3.1' // no Android components
}
// after
dependencies {
implementation 'org.greenrobot:eventbus:3.3.1' // ships Android support in Android builds
} Defensive patterns
Strategy: validation
Validate before calling
// Before any register() at app startup (e.g. Application.onCreate)
try {
Class.forName("android.os.Build");
// Android runtime present: ensure Android artifact is on the classpath
Class.forName("org.greenrobot.eventbus.MainThreadSupport");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("EventBus Android components missing from dependencies", e);
} Try / catch
try {
EventBus.getDefault().register(subscriber);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("eventbus")) {
throw new IllegalStateException("Fix build dependencies: add org.greenrobot:eventbus (Android build)", e);
}
throw e;
} Prevention
- Use the org.greenrobot:eventbus Gradle dependency in Android modules, not the plain-java jar
- Run a smoke test that registers one subscriber in CI for every Android variant
- Document which artifact each module depends on when mixing JVM and Android targets
When it happens
Trigger: Calling EventBus.getDefault().register(subscriber) in a project where the compile classpath contains android.jar (Android SDK detected) but the dependency only includes the plain Java artifact org.greenrobot:eventbus without its Android components (e.g. missing eventbus-android library or the eventbus-3.x .jar instead of the Android build). Also happens in unit tests run on a JVM that partially mocks the Android SDK (Robolectric misconfiguration) or when a build script strips the android classifier dependency.
Common situations: Maven/Gradle projects that pull org.greenrobot:eventbus for a Java module and then reuse it in an Android module; upgrading from EventBus 2.x where a single jar worked; using a plain JVM artifact inside an Android build; fat-jar/shadowJar packaging that drops the Android classes.
Related errors
- Subscriber ${subscriber.getClass()} already registered to ev
- Unexpected exception
- Could not inspect methods of ${clazz.getName()}. Please make
- Could not find subscriber method in ${subscriberClass}. Mayb
- Could not send handler message
AI-assisted analysis of greenrobot/EventBus@0194926b3b (2026-08-14).
Data as JSON: /api/errors/68dbb4c0ff39e966.
Report an issue: GitHub.