title: Dagger Module Inclusion Cycle
body: <p>I'm still new to Dagger and trying to get a hang of things. I wanted to split my modules into logical groups which each provide their own functionality, yet basically would act the same as if it were in one Module.</p>
  
  <p>For instance, let's say I have my main application module defined as follows:</p>
  
  <pre><code>//com.example.android.MyAppModule.java
  @Module(
     includes = AnalyticsModule.class,
     injects = { &lt;snip&gt; }
  )
  public class MyAppModule {
     // various provides
  }
  </code></pre>
  
  <p>And I have another module defined like this which sets up an ErrorReporter interface and provides the concrete implementation to it.</p>
  
  <pre><code>// com.example.android.analytics.AnalyticsModule.java
  @Module(
     addsTo = MyAppModule.class,
     injects = { MyApp.class }
  )
  public class AnalyticsModule(){
  
      // ErrorReporter is a public interface and ErrorReporterImpl is a package-local final concrete class that implements it
      @Provides @Singleton
      ErrorReporter providesErrorReporter(ErrorReporterImpl reporter) { return reporter };
  }
  </code></pre>
  
  <p>In my Application class I set up the object graph like this:</p>
  
  <pre><code>// com.example.android.MyApp.java
  public class MyApp extends Application {
      @Inject ErrorReporter errorReporter;
  
      @Override
      public void onCreate() {
          super.onCreate();
          applicationGraph = ObjectGraph
              .create(new MyAppModule())
              .plus(new AnalyticsModule());
          applicationGraph.inject(this);
          errorReporter.initialize();
      }
  }
  </code></pre>
  
  <p>When I run the dagger compiler I get something like this:</p>
  
  <pre><code>Graph validation failed: Module Inclusion Cycle:
  0. com.example.android.analytics.AnalyticsModule included by com.example.android.MyAppModule
  1. com.example.android.modules.MyAppModule included by com.example.android.analytics.AnalyticsModule
  0. com.example.android.analytics.AnalyticsModule
  </code></pre>
  
  <p>What am I doing wrong here? I assume it has something to do with includes/addsTo, but when I remove those I get other errors.</p>
  
  <p>If I remove includes = AnalyticsModule.class from MyAppModule I get something like this:</p>
  
  <pre><code>com.example.android.analytics.ErrorReporter could not be bound with key com.example.android.analytics.ErrorReporter required by com.example.android.MyApp for com.example.android.MyAppModule
  </code></pre>
  
  <p>Everything is fine if I completely forgo an AnalyticsModule and then hand off the providesErrorReporter to MyAppModule, but then I have to make my concrete impl class public so I can use it in the other module.</p>