EventBus 3.2 with incremental annotation processing

EventBus 3.2.0 is now available on Maven Central. In 2020, seven years since version 1.0, EventBus is still one of the most used Android libraries. This update addresses advancements in the Gradle build system and supporting Android libraries.

EventBus 3.2 adds incremental processing to the EventBus annotation processor. This can greatly reduce build times – if all involved annotation processors play along (e.g. ObjectBox is getting there too).

The EventBus annotation processor is used when building EventBus with a subscriber index. This is now recommended for all Android apps. It improves run time performance and avoids crashes by looking up subscriber methods via reflection.

EventBus 3.2 also improves support for JetPack/AndroidX. When looking for @Subscribe methods, it now ignores all base classes from the androidx package and its subpackages, e.g. AppCompatActivity (from androidx.appcompat.app) or Fragment (from androidx.fragment.app). Before 3.2, those classes were scanned using reflection, regardless if a subscriber index was available or not.

Those two changes make EventBus faster and more resilient and we hope you consider making this update soon.

The EventBus library is free open source software. If you like it, we appreciate a star on GitHub, a tweet, or any feedback to us. If you use EventBus in a cool app that is a great showcase for its usefulness, we would love to share a case study with our community. Please get in touch.

EventBus 3.1 with plain Java support

With over 25% of the top Android apps using it, EventBus is more popular than ever before. So we’re very happy to announce EventBus 3.1 today. Starting with this release, EventBus works with plain Java (non-Android) projects. This has two major benefits: Firstly, it opens up EventBus for all Java developers and makes it usable for server and desktop applications. Secondly, it allows Android developers to use EventBus in local unit tests. Before, you had to use instrumentation tests which are slow and require a device. In contrast to this, plain Java unit tests are blazingly fast as they run directly on your desktop machine.
Continue reading

Avoid NoClassDefFoundError during EventBus registration

There is an obscure scenario causing some older Android versions to throw java.lang.NoClassDefFoundError when trying to register subscribers in EventBus. It was reported often in connection to the class  PersistableBundle, which was introduced in Android API level 21. It seems like an Android bug with reflection, but of course you don’t want your app to crash. Thus, we just added an FAQ entry with covering some background and a couple of solutions. One preferred solution is to update to EventBus 3 along with the subscriber index. Because the index is created during build time, it avoids problematic (and slow) reflection altogether!

EventBus 3 released, now based on @Annotations

EventBus3
Today, we are pleased to release EventBus 3. Previous versions of EventBus rejected to use annotations for performance reasons. Now, version 3 embraces annotations to improve performance. How does that make sense? Unfortunately, Android’s performance did not get any better. Reflection on annotations is still very bad compared to Desktop Java, even on Android 6 and ART. EventBus 3 resolves this problem by introducing a new annotation processor, which will index all annotations at build time. It generates a class containing all the data that would be expensive to get at run time. Build-time indexing makes EventBus 3 the fastest EventBus ever.

Continue reading

Android Architecture with EventBus

Google’s Android Dev Summit 2015 covered a talk on Android Application Architecture. Android Apps often have complex interactions among data models, application logic, UI views and controllers, and networking. A solid architecture is the key to get this right. Watch the two Googlers Yigit Boyar and Adam Powell using EventBus as an important app’s component:

Continue reading