简体   繁体   English

Dagger2组件未生成

[英]Dagger2 Component not generated

I'm trying to set up a project with Dagger. 我正在尝试与Dagger建立一个项目。 Right now when I build,none of the Dagger* classes are generated for the Components. 现在,当我构建时,没有为组件生成Dagger *类。

Heres's my build.gradle config: 这是我的build.gradle配置:

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. 最后,我找到了原因。我将Dagger依赖项导入到模块“ OpenSourceLibrary”中,该模块由第三方库负责管理。 If i move the dependency to the Module of AboutLibrary, It works. 如果我将依赖项移到AboutLibrary的模块中,它将起作用。 But do I have to do it in every Module? 但是我必须在每个模块中都这样做吗?

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

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