未解决的参考:DaggerTestComponent(Kotlin with Dagger for Test)



当我们使用Dagger和Kotlin时,我们在build.gradle依赖项中需要以下内容

kapt 'com.google.dagger:dagger-compiler:2.0'
compile 'com.google.dagger:dagger:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'

如 http://www.beyondtechnicallycorrect.com/2015/12/30/android-kotlin-dagger/所述

当我尝试使用 Dagger 执行测试,并根据 Kotlin 语言 https://labs.ribot.co.uk/fast-and-reliable-ui-tests-on-android-17c261b8220c#.o3efc5knx 甚至 https://medium.com/@fabioCollini/android-testing-using-dagger-2-mockito-and-a-custom-junit-rule-c8487ed01b56#.hxtytfns3 生成DaggerTestComponent.builder()时,但出现以下错误

Error:(14, 25) Unresolved reference: DaggerTestComponent

我找到了 https://stackoverflow.com/a/36231516/3286489 解释如何生成DaggerTestComponent,并尝试将以下内容放在我的依赖项中。

androidTestApt 'com.google.dagger:dagger-compiler:2.0.1'

显然,我认为这是针对 Java 而不是 Kotlin,所以问题仍然存在。有 Kotlin 版本吗?如何在我的 Kotlin 项目中生成我的DaggerTestComponent

从 Kotlin Slack 频道找到了答案。感谢基里尔·拉赫曼。

它是(用于仪器测试)

kaptAndroidTest 'com.google.dagger:dagger-compiler:2.0.2'

或(用于单元测试)

kaptTest 'com.google.dagger:dagger-compiler:2.0.2'

最新更新