[英]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.