user8282703
user8282703

Reputation: 147

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

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. note i rebuild project

Upvotes: 1

Views: 2033

Answers (3)

jenos kon
jenos kon

Reputation: 564

If someone still faced this problem, just use those dependencies below it works for me :

implementation 'com.google.dagger:dagger-android:2.44.2'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.20'
annotationProcessor 'com.google.dagger:dagger-compiler:2.20'

try always to use the latest version of the dagger, use this link to get the latest version: https://github.com/google/dagger/releases

Upvotes: 0

user13651827
user13651827

Reputation:

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.
  3. You can delete cache folder where you installed your android studio.but you have to make sure your android studio closed. Now you can restart it, your problem is gone.
  4. You can rename dagger component and rebuild your project to generate class. This solve your issue.

Here are some quick methods,you can try to solve it.

Upvotes: 0

Công Hải
Công Hải

Reputation: 5261

You have to implementation dagger instead of 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'

Upvotes: 1

Related Questions