Skip to content
Advertisement

Module in Module Dagger: This module is public, but it includes non-public (or effectively non-public) modules

I am using Dagger 2 for DI and want to inject one Module (module A) inside another one (module B). I am not including module A in any component or anywhere else.

My code looks like this:

@Module 
public class ModuleA {

    @Provides
    @Singleton
    @Named("classA")
    public ClassA classA() {
        return new ClassA();
    }
}
@Module(includes = ModuleA.class)
public class ModuleB {

    @Provides
    @Singleton
    public ClassB classB(@Named("classA") ClassA classA) {
        return new ClassB(classA);
    }
}

I am getting the following error:

ModuleB.java:18: error: This module is public, but it includes non-public (or effectively non-public) modules. Either reduce the visibility of this module or make ModuleA public.
public class ModuleB {
       ^

I need ModuleB to be public because I am injecting it in a Component which is in a different package, so the only option is to make ModuleA public, but it is already public.

How to solve this issue? Also, since I am new to Dagger DI, let me know if I am not following some best practice or if I can make my code better.

Advertisement

Answer

I was able to solve the issue, it was using an older version of Dagger 2. Solved by just upgrading that.

Sorry if anybody got inconvenienced by the question.

Advertisement