android - Unresolved reference DaggerApplicationCo

我正在尝试创建我的应用组件,但 Dagger 没有生成我的应用组件。 这是 MyApplication

class MyApplication : Application() {

companion object {
    @JvmStatic lateinit var graph: ApplicationComponent
}
@Inject
lateinit var locationManager : LocationManager

override fun onCreate() {
    super.onCreate()
    graph = DaggerApplicationComponent.builder().appModule(AppModule(this)).build()
    graph.inject(this)
  }
}

这是我的 AppComponent

@Singleton
@Component(modules = arrayOf(AppModule::class))
interface ApplicationComponent {
    fun inject(application: MyApplication)
}

这是截图

这是我的 project在 github

这是错误日志

Error:(7, 48) Unresolved reference: DaggerApplicationComponent
Error:(28, 17) Unresolved reference: DaggerApplicationComponent
Error:Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
Information:BUILD FAILED
Information:Total time: 21.184 secs
Error:e: .../MyApplication.kt: (7, 48): Unresolved reference: DaggerApplicationComponent
e: Unresolved reference: DaggerApplicationComponent
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Information:4 errors
Information:0 warnings
Information:See complete output in console

最佳答案

我的解决方案是添加

apply plugin: 'kotlin-kapt'

并删除

kapt {
    generateStubs = true
}

关于android - Unresolved reference DaggerApplicationComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833242/

相关文章:

android - Android 中的 AsyncTask 与 Kotlin

kotlin - Kotlin 中的交换函数

kotlin - 无需额外对象分配的数组/列表迭代

input - 在 Kotlin 中读取控制台输入

kotlin - 'by' 关键字在 Kotlin 中的作用是什么?

android - 如何在 kotlin 中使用 Android Support typedef 注

properties - Kotlin 中是否有 didSet/willSet 模拟?

java - 为 Kotlin 创建 POJO 类

android - 如何像在 Swift 中一样从 Kotlin 中的函数返回多个值?

android - kotlin 和 ArgumentCaptor - IllegalStateEx