未解决的参考:DaggerTestComponent(Kotlin用匕首测试)
当我们使用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进行测试时,按照https://labs.ribot.co.uk/fast-and-reliable-ui-tests-on-android-17c261b8220c#.o3efc5knx生成DaggerTestComponent.builder()
甚至https://medium.com/@fabioCollini/android-testing-using-dagger-2-mockito-and-a-custom-junit-rule-c8487ed01b56#.hxtytfns3,Kotlin语言,但有以下错误
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
?
- 将自定义类的响应主体改造2
- Kotlin + Dagger2 @模块提供者方法用法中的注释
- 参数不匹配; SimpleXML的
- Kotlin:Dagger2 @Inject context var始终为空
- 改进泛型类型的调用方法
从Kotlin Slack Channel找到答案。 感谢Kirill Rakhman。
这是(器乐测试)
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.0.2'
或(单元测试)
kaptTest 'com.google.dagger:dagger-compiler:2.0.2'
- 匕首2在单元测试与Kotlin
- 使用@ Component.Builder和构造函数参数
- 匕首2在Kotlin未解决的参考DaggerXXXSub
- 匕首2,不能在我的活动中注入演示者
- Android Dagger:我无法提供没有@Inject构造函数的外部类
- 错误:com.app.android.dagger.component.AppComponent(unscoped)可能不引用作用域绑定:
- 匕首和Kotlin。 匕首不生成组件类
- Android Kotlin匕首2 ViewModel注入错误
- 错误:未找到注释处理器'__gen.AnnotationProcessorWrapper_debug_android_databinding_annotationprocessor_ProcessDataBinding'