Dagger 2:使用子组件/相关组件时找不到符号类

时间:2016-05-31 13:16:12

标签: java android dagger-2

我在添加依赖/子组件时遇到Dagger 2的问题会让我无法找到DaggerAppComponent / DaggerBComponent / DaggerCComponent的查找符号类。

组件如:

public class ApplicationComponent {
@Singleton
@Component(modules= {...})
public interface AppComponent {
    SomeManager someManager();
    void inject(Application application);
}
}

@UserScope
@Component(modules = {...}, dependencies = ApplicationComponent.AppComponent.class)
public interface BComponent{
    CComponent plus (AModule aModule, BModule bModule);
    void inject (SomeActivity someActivity);
}

@PerFragment
@Subcomponent (modules = {AModule.class,BModule.class})
public interface CComponent {
    void inject (SomeFragment someFragment);
}

每当我向BComponent添加plus方法时,每当我尝试构建时,我都会发现错误找不到所有3个Dagger生成的类的符号类。如果我注释掉plus方法,它确实会构建。我有什么不对的吗?

1 个答案:

答案 0 :(得分:1)

当子组件在库项目中时,我遇到了同样的问题,我忘了将这些行放在library / build.gradle中

apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
...
...
dependencies {
    ...
    apt 'com.google.dagger:dagger-compiler:2.5'
}

希望这会对你有所帮助