更新到Kotlin 1.3.30时会中断Dagger 2.21的构建 [英] Update to Kotlin 1.3.30 breaks build with Dagger 2.21

查看:63
本文介绍了更新到Kotlin 1.3.30时会中断Dagger 2.21的构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Kotling 1.3.21更新到1.3.30后生成错误:

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.

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

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

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

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/

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

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.

推荐答案

此错误已由某人在GitHub 上和在YouTrack上. Kotlin版本1.3.31发布后,该问题应得到解决.

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

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

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

GitHub上列出的Kotlin 1.3.30的解决方法是使用Java批注而不是ViewModelKey的Kotlin,否则您可以降级回Kotlin 1.3.21.

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

这篇关于更新到Kotlin 1.3.30时会中断Dagger 2.21的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆