简体   繁体   English

Dagger2错误:Kotlin:未解析的参考:DaggerSOMETHINGComponent

[英]Dagger2 error: Kotlin: Unresolved reference: DaggerSOMETHINGComponent

source code 源代码

I'm building a gradle project of Kotlin and Dagger2 which runs well half year ago in macOS: 我正在构建Kotlin和Dagger2的gradle项目,该项目在半年前在macOS中运行良好:

GitHub:Kotlin-Tutorials13 GitHub的:科特林-Tutorials13

you can get it by 你可以得到它

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

you can open it in IntelliJ IDEA 您可以在IntelliJ IDEA中打开它

building enviroment 建筑环境

My building enviroment is listed as below: 我的建筑环境如下:

  • IntelliJ IDEA 2017.1.3 IntelliJ IDEA 2017.1.3
  • JRE: 1.8.0_112-release-736-b21 amd64 JRE:1.8.0_112-release-736-b21 amd64
  • JVM: OpenJDK 64-Bit Server VM by JetBrains sro JVM:JetBrains sro的OpenJDK 64位服务器VM
  • Windows 10 10.0 Windows 10 10.0

building result 建设成果

It tuens out an error: 它指出了一个错误:

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

decompile 反编译

So, I decompile RESTFulComponent.class 所以,我反编译RESTFulComponent.class

the source file of it is RESTFulComponent.kt 它的源文件是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
}

decompile RESTFulComponent.class we get 反编译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 */ }
}

reason 原因

The error result from annotation of dagger 's not working. 该错误是由于dagger注释无效而导致的。

How can I fix this error? 如何解决此错误?

wrong operation 错误的操作

I use Ctrl+F9 to compile and this error arises。 我使用Ctrl + F9进行编译,并且出现此错误。

right operation 正确的操作

We should click View -> Tool Windows -> Gradle to open Gradle projects Window 我们应该单击查看 -> 工具窗口 -> Gradle打开Gradle项目窗口

Then click Tasks -> build -> build 然后单击任务 -> 构建 -> 构建

正确的构建

reason 原因

Ctrl+F9 isn't invoking gradle build , we should use gradle build in Gradle projects Window Ctrl + F9不调用gradle build ,我们应该在Gradle项目窗口中使用gradle build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM