Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update to Kotlin 1.3.30 breaks build with Dagger 2.21

Build error after update from Kotling 1.3.21 to 1.3.30:

AppComponent.java:16: error: [Dagger/MissingBinding]        java.util.Map<java.lang.Class<? extends androidx.lifecycle.ViewModel>,    javax.inject.Provider<androidx.lifecycle.ViewModel>>     cannot be provided without an @Provides-annotated method. 

Reproduced on two different projects with similar dependencies on Kotlin, Dagger and Architecture components.

I suspect it somehow related to the recent kapt updates in kotlin 1.3.30: https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/

Tried to disable/enable the kapt options from the article, tried gradle clean, invalidate caches, nothing helps. Only downgrading to 1.3.21 projects build successfully.

like image 510
yaroslav Avatar asked Apr 12 '19 08:04

yaroslav


People also ask

Does dagger work with Kotlin?

Dagger is a fully static, compile-time dependency injection framework for Java, Kotlin, and Android.

How do I upgrade my Kotlin?

Update to a new release IntelliJ IDEA and Android Studio suggest updating to a new release once it is out. When you accept the suggestion, it automatically updates the Kotlin plugin to the new version. You can check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.

What is the current version of Kotlin?

Kotlin 1.5 was released in May 2021. Kotlin 1.6 was released in November 2021. Kotlin 1.7 was released in June 2022, including the alpha version of the new Kotlin K2 compiler.

How do I find my Kotlin plugin version?

You can check the Kotlin plugin version in Tools | Kotlin | Configure Kotlin Plugin Updates. If you are migrating to the new feature release, Kotlin plugin's migration tools will help you with the migration.


1 Answers

This bug was already reported by someone on GitHub and on YouTrack. This should be fixed once Kotlin version 1.3.31 gets released.

Update: Kotlin 1.3.31 is out, so make sure to update your Kotlin version!


The workaround for Kotlin 1.3.30 listed on GitHub is to use a Java annotation instead of Kotlin for ViewModelKey, or you may downgrade back to Kotlin 1.3.21.

/**  * Workaround in Java due to Dagger/Kotlin not playing well together as of now  * https://github.com/google/dagger/issues/1478  */ @MapKey @Documented @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface ViewModelKey {     Class<? extends ViewModel> value(); }  
like image 143
David Medenjak Avatar answered Oct 05 '22 18:10

David Medenjak