Dependency injection on Android with dagger-android and Kotlin
1–10 of 19 posts
Re: Dependency injection on Android with dagger-android and Kotlin
#2Re: Dependency injection on Android with dagger-android and Kotlin
#3If you value your build times or your sanity in the slightest, I'd recommend either severely limiting use of Dagger, e.g. by only using it in certain, small Gradle modules, or using a different DI solution.
Re: Dependency injection on Android with dagger-android and Kotlin
#4Unfortunately, using Dagger for DI with Kotlin requires using the Kotlin annotation processor, kapt, which is still incredibly slow, and works non-incrementally. If you value your build times or your sanity in the slightest, I'd recommend either severely limiting use of Dagger, e.g. by only using it in certain, small Gradle modules, or using a different DI solution.
Re: Dependency injection on Android with dagger-android and Kotlin
#5Kapt does bump the clean build time to about 2min, incremental builds take between 10-60s - although actually launching the app on an emulator/device adds another 20s.
The cons of Dagger2 that I've experienced since it's launch are; The documentation and support is useless. You're on your own of you don't use a 3rd party sample project as a template. No one understands scopes and subscopes, subcomponents etc. The new Android dagger api is arcane and weird, no one wants to use it.
The Dagger2 team should (if they aren't already) create a Kotlin extension for it, I believe there are some syntactic optimizations to be offered.
Re: Dependency injection on Android with dagger-android and Kotlin
#6Dagger2 is great when you have it setup, generating the dependency graph during compilation makes it lightning fast during execution. I also like the error messages, as long as you can read Java stack traces all the info for solving errors are in there - I've never seen an unsolvable situation this far. Kapt does bump the clean build time to about 2min, incremental builds take between 10-60s - although actually launc…
https://google.github.io/dagger/semantics/
It's not intended as a tutorial, so perhaps it won't quite meet your needs, but if you're curious how all the pieces fit together, it may help.
Re: Dependency injection on Android with dagger-android and Kotlin
#7Re: Dependency injection on Android with dagger-android and Kotlin
#8I've never quite understood the appeal of Dependency Injection. What's wrong with just using constructors?
Re: Dependency injection on Android with dagger-android and Kotlin
#9Since then we have introduced Kotlin and Dagger and we are super happy with it.
As with Dagger, the learning curve is pretty steep. Having it working with modules + activities + fragments + architecture components has been a real challenge but we love it.
For those who are struggling with Dagger: version 2.10 introduced major changes for Android, for good reasons, but it made much harder to use and understand. Many tutorials focus on Dagger And for those who are going crazy with compilation times, Jrebel for Android is a huge time saver. It has an incremental compiler which works with annotation processors. They will stop supporting it in one year, but even then I think it is worth using it. Who knows: if enough people buy licenses maybe they reconsider killing it.