更新到Kotlin 1.3.30时,使用Dagger 2.21中断了构建

时间:2019-04-12 08:06:14

标签: android kotlin dagger-2 dagger

从Kotling 1.3.21更新到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.

转载于对Kotlin,Dagger和Architecture组件具有相似依赖性的两个不同项目。

我怀疑这与kotlin 1.3.30中最近的kapt更新有关: https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/

试图禁用/启用本文中的kapt选项,尝试了gradle clean,使缓存无效,没有任何帮助。 只有降级到1.3.21项目才能成功构建。

2 个答案:

答案 0 :(得分:37)

此错误已由某人on GitHubon YouTrack报告。 Kotlin版本1.3.31发布后,该问题应得到解决。

更新:Kotlin 1.3.31已发布,因此请确保更新您的Kotlin版本!


在GitHub上列出的Kotlin 1.3.30的解决方法是使用Java注释代替ViewModelKey的Kotlin,否则您可以降级回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();
}

答案 1 :(得分:0)

Upgrade dagger versionkotlin versionlatest

annotation class应该可以工作。

当前最新版本是:-

匕首版本:-2.23.2

科特林版本:-1.3.41

相关问题