How to include Dagger Debug SubModule for Debug build?

Viewed 1691

I'm create a Dagger AppComponent in my application as below

protected AppComponent createComponent() {
    return DaggerAppComponent.builder().appModule(new AppModule(this)).build();
}

The AppModule includes a `FeatureModule as below.

@Module(includes = {FeatureModule.class})
public class AppModule {
   // All the provides here
}

Now, I plan to have a separate item for Debug build in the FeatureModule. So I create my FeatureDebugModule inheriting from FeatureModule

@Module
public class FeatureDebugModule extends FeatureModule {

    @Override
    protected void debugBuildSpecificConfig() {
         // Something specific to debug
    }
}

With that I also create AppDebugModule inherit from AppModule

@Module(includes = {FeatureDebugModule.class})
public class AppDebugModule : AppModule {
}

And lastly, I made I made AppDebugApplication that setup the Dagger Component as below

protected AppComponent createComponent() {
    return DaggerAppComponent.builder().appModule(new AppDebugModule(this)).build();
}

Somehow, the code doesn't access the FeatureDebugModule in my debug mode, but still on the FeatureModule code. What did I do wrong?

1 Answers

Apparently for Dagger, the loaded module is based on what defined in the Component's modules. Hence in Debug, I use as below.

@Singleton
@Component(modules = {AppDebugModule.class})
public interface AppDebugComponent extends AppComponent {
    // Inject
}

And the dagger component creation

DaggerAppDebugComponent.builder().appDebugModule(new AppDebugModule(this)).build();

In release, I used as below

@Singleton
@Component(modules = {AppReleaseModule.class})
public interface AppReleaseComponent extends AppComponent {
    // Inject
}

And the dagger component creation

DaggerAppReleaseComponent.builder().appReleaseModule(new AppReleaseModule(this)).build();
Related