简体   繁体   English

Java / IntelliJ无法识别Dagger2组件的“Dagger”关键字

[英]Java/IntelliJ not recognising the “Dagger” keyword for Dagger2 Components

I'm probably missing something very basic here, so hopefully it's not a hard question. 我可能在这里遗漏了一些非常基本的东西,所以希望这不是一个难题。

My equivalent of 我相当于

CoffeeShop coffeeShop = DaggerCoffeeShop.create();

is not being recognised by the IDE (IntelliJ). IDE(IntelliJ)无法识别。 This is a native Java project . 这是一个本机Java项目 The " Dagger CoffeShop" part is all red. Dagger CoffeShop”部分全是红色。

The component is using this syntax: 该组件使用以下语法:

@Component(modules = <ModuleClassName>.class)
public interface CoffeeShop {
    // some methods.
    // does it matter what goes in here for it to recognise the component?
}

The "ModuleClassName" is the name of a module annotated with @Module and includes @Provides methods. “ModuleClassName”是使用@Module注释的模块的名称,包括@Provides方法。

To get the libs I'm using this in Gradle: 为了获得libs我在Gradle中使用它:

compile 'com.google.dagger:dagger:2.4'
compile 'com.google.dagger:dagger-compiler:2.4'

Is that all I need? 这就是我需要的吗? I don't get any errors for any of the annotations, it's just this Dagger keyword it can't recognise. 对于任何注释我都没有任何错误,只是这个Dagger关键字无法识别。 What am I missing? 我错过了什么?

Any help or direction appreciated. 任何帮助或方向赞赏。 I'm not finding the documentation to be that great for beginners like me. 对于像我这样的初学者,我没有找到那么棒的文档。

Your annotation processing is probably not enabled. 您的注释处理可能未启用。

In Settings - > Compiler -> Annotation Processor -> Enable annotation processing Settings - > Compiler - > Annotation Processor - > Enable annotation processing

Afterwards, Rebuild Project 之后, Rebuild Project

If it still thinks the files don't exist (despite the app running properly), you'll have to add the generated source folder as a source folder: File -> Project Structure -> Modules -> select your project -> Sources -> right click on the generated folder with the Dagger stuff in it -> Sources 如果它仍然认为文件不存在(尽管应用程序正常运行),您将必须将生成的源文件夹添加为源文件夹: File - > Project Structure - > Modules - >选择您的项目 - > Sources - >右键单击生成的文件夹,其中包含Dagger内容 - > Sources


And compile 'com.google.dagger:dagger-compiler:2.4' should be either apt scoped or annotationProcessor scoped. compile 'com.google.dagger:dagger-compiler:2.4'应该是apt scoped或annotationProcessor scoped。 If you use Kotlin, then kapt scoped 如果你使用Kotlin,那么kapt scoped

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

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