[英]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:从 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.
Reproduced on two different projects with similar dependencies on Kotlin, Dagger and Architecture components.在对 Kotlin、Dagger 和 Architecture 组件具有相似依赖关系的两个不同项目中复制。
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/我怀疑它与 kotlin 1.3.30 中最近的 kapt 更新有某种关系: 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.尝试禁用/启用文章中的 kapt 选项,尝试清理 gradle,使缓存无效,但没有任何帮助。 Only downgrading to 1.3.21 projects build successfully.
只有降级到 1.3.21 项目才能成功构建。
This bug was already reported by someone on GitHub and on YouTrack . GitHub和YouTrack上已经有人报告了这个错误。 This should be fixed once Kotlin version 1.3.31 gets released.
一旦 Kotlin 1.3.31 版发布,这应该会得到修复。
Update: Kotlin 1.3.31 is out, so make sure to update your Kotlin version!更新: Kotlin 1.3.31 已经发布,所以一定要更新你的 Kotlin 版本!
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. GitHub 上列出的 Kotlin 1.3.30 的解决方法是对
ViewModelKey
使用 Java 注释而不是 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();
}
Upgrade
dagger version and kotlin version to the latest
Upgrade
dagger 版本和kotlin 版本Upgrade
到latest
annotation class
should work. annotation class
应该可以工作。
Currently the latest version is :-目前最新版本是:-
Dagger version :- 2.23.2
匕首版本:-
2.23.2
Kotlin version :- 1.3.41
Kotlin 版本:-
1.3.41
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.