简体   繁体   中英

Dagger2 Component not generated

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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