未解决的参考:DaggerTestComponent(带有Dagger的Kotlin用于测试) [英] Unresolved reference: DaggerTestComponent (Kotlin with Dagger for Test)

查看:85
本文介绍了未解决的参考:DaggerTestComponent(带有Dagger的Kotlin用于测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When we use Dagger and Kotlin, we'll need the following in our build.gradle dependency

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执行测试并根据 https ://medium.com/@fabioCollini/android-testing-using-dagger-2-mockito-and-a-custom-junit-rule-c8487ed01b56#.hxtytfns3 (使用Kotlin语言),但出现以下错误

When I try to perform testing using Dagger, and generate the DaggerTestComponent.builder() as per https://labs.ribot.co.uk/fast-and-reliable-ui-tests-on-android-17c261b8220c#.o3efc5knx or even https://medium.com/@fabioCollini/android-testing-using-dagger-2-mockito-and-a-custom-junit-rule-c8487ed01b56#.hxtytfns3, in Kotlin language, but have the below error

Error:(14, 25) Unresolved reference: DaggerTestComponent

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

I found https://stackoverflow.com/a/36231516/3286489 which explain how to get DaggerTestComponent generated, and try put the below in my dependency.

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

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

Apparently, I think this is for Java and not Kotlin, so the issue persist. Is there a Kotlin version of it? How to get my DaggerTestComponent generated in my Kotlin project?

推荐答案

从Kotlin Slack Channel找到了答案.感谢Kirill Rakhman.

Found the answer from Kotlin Slack Channel. Thanks to Kirill Rakhman.

是(用于乐器测试)

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

或(用于单元测试)

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

这篇关于未解决的参考:DaggerTestComponent(带有Dagger的Kotlin用于测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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