[英]Java/IntelliJ not recognising the “Dagger” keyword for Dagger2 Components
我可能在这里遗漏了一些非常基本的东西,所以希望这不是一个难题。
我相当于
CoffeeShop coffeeShop = DaggerCoffeeShop.create();
IDE(IntelliJ)无法识别。 这是一个本机Java项目 。 “ Dagger CoffeShop”部分全是红色。
该组件使用以下语法:
@Component(modules = <ModuleClassName>.class)
public interface CoffeeShop {
// some methods.
// does it matter what goes in here for it to recognise the component?
}
“ModuleClassName”是使用@Module注释的模块的名称,包括@Provides方法。
为了获得libs我在Gradle中使用它:
compile 'com.google.dagger:dagger:2.4'
compile 'com.google.dagger:dagger-compiler:2.4'
这就是我需要的吗? 对于任何注释我都没有任何错误,只是这个Dagger关键字无法识别。 我错过了什么?
任何帮助或方向赞赏。 对于像我这样的初学者,我没有找到那么棒的文档。
您的注释处理可能未启用。
在Settings
- > Compiler
- > Annotation Processor
- > Enable annotation processing
之后, Rebuild Project
如果它仍然认为文件不存在(尽管应用程序正常运行),您将必须将生成的源文件夹添加为源文件夹: File
- > Project Structure
- > Modules
- >选择您的项目 - > Sources
- >右键单击生成的文件夹,其中包含Dagger内容 - > Sources
compile 'com.google.dagger:dagger-compiler:2.4'
应该是apt
scoped或annotationProcessor
scoped。 如果你使用Kotlin,那么kapt
scoped
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.