Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...