After the consecutive release of Dagger 2.15 and 2.16 in May earlier this year, Dagger 2.17 was released with enhanced performance and bug fixes. This dependency injection framework for Java and Android allows developers to focus on the interesting classes (the classes that actually do stuff!). You just need to declare the dependencies, specify how to satisfy them, and ship your app.
What’s new in Dagger 2.17?
Bug fixes and error improvements:
- Previously, when a @Binds method in a parent was used only from a child, whose dependency was missing in the parent but present in the child, it used to result in a valid graph. Dagger now reports an error in such cases.
- An error is reported for binding methods that have more than one scope annotation, instead of throwing an exception.
- If two entry point methods with different keys are inherited from different supertypes of a component type, Dagger reports an error.
- Dagger reports an error for scope annotations on @BindsOptionalOf methods. Apply scope to the non-optional binding that satisfies the optional binding, instead of the @BindsOptionalOf method.
- You should install AndroidInjectionModule or AndroidSupportInjectionModule when using dagger.android, otherwise Dagger 2.17 will throw a missing binding error.
- Bug fixed to report cycles if some components have no entry points that depend on the cycle.
- Bug fixed where scope annotations in error messages were missing annotation attributes.
Additions and deprecations:
- An option is added to use string keys for dagger.android and allow the keys to be obfuscated. You can enable this mode with the -Adagger.android.experimentalUseStringKeys flag.
- experimentalAndroidMode is renamed to fastInit.
- dagger.android.DaggerFragment is deprecated, use dagger.android.support.DaggerFragment instead. This is done to match Android Pie’s deprecation of framework fragments.
Checkout Dagger’s Github page for more on the 2.17 release.