{"record":{"id":"68dbb4c0ff39e966","repo":"greenrobot/EventBus","slug":"it-looks-like-you-are-using-eventbus-on-android-m","errorCode":null,"errorMessage":"It looks like you are using EventBus on Android, make sure to add the \"eventbus\" Android library to your dependencies.","messagePattern":"It looks like you are using EventBus on Android, make sure to add the \"eventbus\" Android library to your dependencies\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"EventBus/src/org/greenrobot/eventbus/EventBus.java","lineNumber":145,"sourceCode":"        sendSubscriberExceptionEvent = builder.sendSubscriberExceptionEvent;\n        sendNoSubscriberEvent = builder.sendNoSubscriberEvent;\n        throwSubscriberException = builder.throwSubscriberException;\n        eventInheritance = builder.eventInheritance;\n        executorService = builder.executorService;\n    }\n\n    /**\n     * Registers the given subscriber to receive events. Subscribers must call {@link #unregister(Object)} once they\n     * are no longer interested in receiving events.\n     * <p/>\n     * Subscribers have event handling methods that must be annotated by {@link Subscribe}.\n     * The {@link Subscribe} annotation also allows configuration like {@link\n     * ThreadMode} and priority.\n     */\n    public void register(Object subscriber) {\n        if (AndroidDependenciesDetector.isAndroidSDKAvailable() && !AndroidDependenciesDetector.areAndroidComponentsAvailable()) {\n            // Crash if the user (developer) has not imported the Android compatibility library.\n            throw new RuntimeException(\"It looks like you are using EventBus on Android, \" +\n                    \"make sure to add the \\\"eventbus\\\" Android library to your dependencies.\");\n        }\n\n        Class<?> subscriberClass = subscriber.getClass();\n        List<SubscriberMethod> subscriberMethods = subscriberMethodFinder.findSubscriberMethods(subscriberClass);\n        synchronized (this) {\n            for (SubscriberMethod subscriberMethod : subscriberMethods) {\n                subscribe(subscriber, subscriberMethod);\n            }\n        }\n    }\n\n    // Must be called in synchronized block\n    private void subscribe(Object subscriber, SubscriberMethod subscriberMethod) {\n        Class<?> eventType = subscriberMethod.eventType;\n        Subscription newSubscription = new Subscription(subscriber, subscriberMethod);\n        CopyOnWriteArrayList<Subscription> subscriptions = subscriptionsByEventType.get(eventType);\n        if (subscriptions == null) {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/EventBus.java#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (Java-only artifact used in Android app)\ndependencies {\n    implementation 'org.greenrobot:eventbus-java:3.3.1' // no Android components\n}\n\n// after\ndependencies {\n    implementation 'org.greenrobot:eventbus:3.3.1' // ships Android support in Android builds\n}","handlingStrategy":"validation","validationCode":"// Before any register() at app startup (e.g. Application.onCreate)\ntry {\n    Class.forName(\"android.os.Build\");\n    // Android runtime present: ensure Android artifact is on the classpath\n    Class.forName(\"org.greenrobot.eventbus.MainThreadSupport\");\n} catch (ClassNotFoundException e) {\n    throw new IllegalStateException(\"EventBus Android components missing from dependencies\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    EventBus.getDefault().register(subscriber);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"eventbus\")) {\n        throw new IllegalStateException(\"Fix build dependencies: add org.greenrobot:eventbus (Android build)\", e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["eventbus","android","dependencies","classpath","setup"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}