Dagger2 error: Kotlin: Unresolved reference: DaggerSOMETHINGComponent

Dagger2 error: Kotlin: Unresolved reference: DaggerSOMETHINGComponent

源代码

我正在构建一个 Kotlin 和 Dagger2 的 gradle 项目,半年前在 macOS 中运行良好:

GitHub:Kotlin-Tutorials13

可以通过

获得
git clone https://github.com/enbandari/Kotlin-Tutorials.git
cd Kotlin-Tutorials/code/Kt13

可以在IntelliJ IDEA中打开

建筑环境

我的搭建环境如下:

建筑结果

报错:

C:\Users\xiang\IdeaProjects\Kotlin-Tutorials-master\code\Kt13\src\main\kotlin\net\println\kt13\Service.kt
Error:(3, 25) Kotlin: Unresolved reference: DaggerRESTFulComponent
Error:(19, 9) Kotlin: Unresolved reference: DaggerRESTFulComponent

反编译

所以,我反编译RESTFulComponent.class

它的源文件是RESTFulComponent.kt

package net.println.kt13

import dagger.Component
import net.println.kt13.module.RetrofitModule
import retrofit2.Retrofit
import javax.inject.Singleton

/**
 * Created by benny on 12/11/16.
 */
@Singleton
@Component(modules = arrayOf(RetrofitModule::class))
interface RESTFulComponent {
    fun retrofit(): Retrofit
}

反编译RESTFulComponent.class得到

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package net.println.kt13.module

@dagger.Module public final class RxAdapterModule public constructor() {
    @javax.inject.Singleton @dagger.Provides public final fun adapter(): retrofit2.CallAdapter.Factory { /* compiled code */ }
}

原因

匕首注释的错误导致无法正常工作。

我该如何解决这个错误?

错误操作

我用Ctrl+F9编译出现这个错误。

正确操作

我们应该点击查看 -> 工具Windows -> Gradle 打开 Gradle 个项目 Window

然后点击任务 -> build -> build

原因

Ctrl+F9 没有调用 gradle build,我们应该在 Gradle 项目中使用 gradle buildWindow