0

I'm trying to set up a project with Dagger. Right now when I build,none of the Dagger* classes are generated for the Components.

Heres's my build.gradle config:

dependencies = [
    annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
    provided            'org.glassfish:javax.annotation:10.0-b28'
    compile             'com.google.dagger:dagger:2.11'
]

and the code:

public class Person {
    private String name;

    @Inject
    public Person() {
        name = "summer";
    }

    public String getName() {
        return name;
    }
}

@Component
public interface AboutComponent {

    void inject(AboutActivity activity);
}

In Activity:

public class AboutActivity extends BaseActivity implements OnClickListener {
    @Inject Person mPerson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // I can not find DaggerAboutComponent here
    }
}

I've tried rebuilding the project to see if it will generate the classes.

warpath
  • 11
  • 4
  • 1
    first of all get basic idea about how dagger 2.11 works, once you done. refrence for sample https://github.com/Nimrodda/dagger-androidinjector – Aks4125 Sep 20 '17 at 06:49
  • You are trying to inject a ```Person``` (the dependency) in to an ```Activity```. But who is providing the dependency? You a need a ```Module``` which provides ```Person```. – iceman Sep 20 '17 at 06:50
  • @iceman tks for your comment, but It doesn't work. – warpath Sep 20 '17 at 07:39
  • Please remove @Inject annotations and try to rebuild it. – kimkevin Sep 20 '17 at 08:33
  • Follow this example for better understanding of Dagger https://github.com/burhanrashid52/AndroidDaggerMVPRxArchitecture – Burhanuddin Rashid Sep 20 '17 at 08:49
  • @BurhanuddinRashid tks your feedback. – warpath Sep 21 '17 at 12:29
  • finally I find the reason.I import the Dagger dependencies in a Module "OpenSourceLibrary", which I manager the third party library. If i move the dependency to the Module of AboutLibrary, It works. But do I have to do it in every Module? – warpath Sep 21 '17 at 12:34

1 Answers1

1

Finally I find the reason.I import the Dagger dependencies in a Module "OpenSourceLibrary", which I manager the third party library. If i move the dependency to the Module of AboutLibrary, It works. But do I have to do it in every Module?

warpath
  • 11
  • 4