【发布时间】:2019-08-26 11:58:08
【问题描述】:
让我们从一个问题开始:
> Task :app:kaptAppDebugUnitTestKotlin FAILED
/app/build/tmp/kapt3/stubs/appDebugUnitTest/com/pckg/TestAppComponent.java:77: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract class TestAppComponent extends com.pckg.AppComponent {
^warning: The following options were not recognized by any processor: '[room.schemaLocation, kapt.kotlin.generated, room.incremental]'[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptAppDebugUnitTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
我正在尝试更新我们的大型项目以使用增量 kapt 运行。其中一项要领是更新匕首。我尝试了很多版本,但最后一个工作的是 2.20,上面的所有内容都给出了提到的“错误”。
说实话,我没有看到任何错误。当我只组装应用程序时,构建工作正常,但是当我尝试运行 UnitTest 任务时,它向我显示了该错误。但我找不到任何问题,也找不到 AppComponent 中的 AS 代码检查。甚至没有生成 TestAppComponent。
我相信,我们对 android 使用完全常规的本地单元测试设置。
设置:
/core/src/main/com/pckg/core/Provisions.kt
interface Provisions {
....
}
/app/src/main/com/pckg/AppComponent.kt
@Component(modules=[....])
@Singleton
interface AppComponent : Provisions {
....
}
/app/src/test/com/pckg/TestAppComponent.kt
@Component(modules=[....])
@Singleton
interface TestAppComponent : AppComponent {
....
}
我还尝试使组件成为抽象类而不是接口(因为错误说类扩展了接口,但没有运气 - 同样的问题,只是抽象类)。
当然,我确实尝试过使用 --stacktrace 运行,但这只是更长的毫无意义的异常。
问题:
- 你知道更新到 dagger 2.21 和 上面?
- 你知道如何强制 dagger/kapt/gradle 多说吗 (没有错误信息)?
PS:您可能想到的任何库版本都是最新的。 AGP 3.5.0、Gradle 5.5.1、Kotlin 1.2.50、...
【问题讨论】:
标签: android unit-testing kotlin dagger-2 android-testing