Unresolved reference: DaggerTestComponent (Kotlin with Dagger for Test)

空扰寡人 提交于 2020-01-11 06:43:07

问题


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'

As stated in http://www.beyondtechnicallycorrect.com/2015/12/30/android-kotlin-dagger/

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

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'

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?


回答1:


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

It is (for instrumental test)

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

or (for unit test)

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


来源:https://stackoverflow.com/questions/38097149/unresolved-reference-daggertestcomponent-kotlin-with-dagger-for-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!