简体   繁体   English

Dagger 2 组件 class 未生成

[英]Dagger 2 Component class not generated

i'm currently learn dagger2 but i have problem is daggercomponent class not generated and i can't know the reason我目前正在学习 dagger2 但我有问题是 daggercomponent class 没有生成,我不知道原因

implementation 'com.google.dagger:dagger-android:2.27'
implementation 'com.google.dagger:dagger-android-support:2.27'  
annotationProcessor 'com.google.dagger:dagger-android-processor:2.27'

public class Nugets {
    @Inject
    public Nugets() {
    }
}

public class Water {

    @Inject
    public Water() {
    }
}

public class Coffee {

    Nugets nugets;
    Water water;

    @Inject
    public Coffee(Nugets nugets, Water water) {
        this.nugets = nugets;
        this.water = water;
    }
}

@Component
public interface CoffeeComponent {
    Coffee getCoffee();
}

when i tried to to find DaggerCoffeeComponent class i didn't find it.当我试图找到 DaggerCoffeeComponent class 时,我没有找到它。 note i rebuild project注意我重建项目

You have to implementation dagger instead of dagger-android .你必须实现dagger而不是dagger-android Don't forget to make project or rebuild不要忘记制作项目或重建

implementation 'com.google.dagger:dagger:2.27'
annotationProcessor 'com.google.dagger:dagger-compiler:2.27'

Question you asked i encountered many times, And the lucky thing is i know how to solve it.你问的问题我遇到过很多次,幸运的是我知道如何解决它。 here are simple methods you can follow to solve it.以下是您可以遵循的简单方法来解决它。

  1. You can clean/rebuild project to solve it.您可以清理/重建项目来解决它。
  2. You can invalidate/cache restart your android studio to solve it.您可以使 android 工作室无效/缓存重新启动来解决它。
  3. You can delete cache folder where you installed your android studio.but you have to make sure your android studio closed.您可以删除安装 android 工作室的缓存文件夹。但您必须确保 android 工作室已关闭。 Now you can restart it, your problem is gone.现在您可以重新启动它,您的问题就消失了。
  4. You can rename dagger component and rebuild your project to generate class.您可以重命名 dagger 组件并重新构建项目以生成 class。 This solve your issue.这解决了你的问题。

Here are some quick methods,you can try to solve it.这里有一些快速的方法,你可以尝试解决它。

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

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