title: ContributesAndroidInjector Module must be set
body: <p>I'm trying to inject activity dependencies into fragment presenter.
  App structure is very simple.</p>
  
  <p><strong>TabsActivity</strong> - viewpager</p>
  
  <p>-- <strong>TabFragment</strong> - page item</p>
  
  <p>-- [...] </p>
  
  <p><strong>TabsActivity</strong> shows view
  <strong>TabsActivityModule</strong> - provides <strong>FragmentManager</strong> (for example) and some stuff for <strong>TabsActivity</strong></p>
  
  <p><strong>TabFragmentModule</strong> provides stuff for <strong>TabFragment</strong>.
  Every <strong>TabFragment</strong> has own <strong>Presenter</strong>. <strong>Presenter</strong> injects <strong>TabActivityModule</strong>  dependencies. </p>
  
  <p>In my case - Presenter injects <strong>FragmentManager</strong></p>
  
  <p>Here is code:</p>
  
  <p><em>Application class</em></p>
  
  <pre><code>class App extends Application implements HasActivityInjector {
      @Inject
      DispatchingAndroidInjector&lt;Activity&gt; dispatchingAndroidInjector;
  
      @Override
      public AndroidInjector&lt;Activity&gt; activityInjector() {
          return dispatchingAndroidInjector;
      }
     /*
     blah blah creating app component onCreate() ...
         DaggerAppComponent
              .builder()
              .context(this)
              .build()
              .inject(this);
     */ 
  }
  </code></pre>
  
  <p><em>Root application component</em></p>
  
  <pre><code>@Singleton
  @Component(modules = {InjectorsModule.class})
  public interface AppComponent {
  
      @Component.Builder
      interface Builder {
          @BindsInstance
          Builder context(Context context);
  
          AppComponent build();
      }
  
      void inject(App app);
  }
  </code></pre>
  
  <p>Here is android views contributors <strong>InjectorsModule</strong></p>
  
  <pre><code>@Module(includes = {AndroidSupportInjectionModule.class})
  public abstract class InjectorsModule {
  
      @ActivityScope
      @ContributesAndroidInjector(modules = {TabsActivityModule.class})
      abstract TabsActivity tabsActivityInjector();
  }
  </code></pre>
  
  <p>Activity <em>TabsActivityModule</em></p>
  
  <pre><code>@Module
  public abstract class TabsActivityModule {
  
      @Provides
      @ActivityScope
      public FragmentManager provideFragmentManager(TabsActivity activity) {
          return activity.getFragmentManager();
      }
  
      @Provides @Named("activity")
      @ActivityScope
      public Context provideActivityContext(TabsActivity activity) {
          return activity;
      }
  
      // Here contributes tab fragment
      @FragmentScope
      @ContributesAndroidInjector(modules = {TabFragmentModule.class})
      public abstract TabFragment tabFragment();
  }
  </code></pre>
  
  <p>Fragment <em>TabFragmentModule</em></p>
  
  <pre><code>@Module
  public abstract class TabFragmentModule {
      @Provides @Named("answer")
      @FragmentScope
      public int provideSomeInt() {
          return 42;
      }
  }
  </code></pre>
  
  <p>And last, just for example - <em>TabPresenter</em></p>
  
  <pre><code>public class TabPresenter {
      @Inject @Named("answer") int mAnswer;
      @Inject @Named("activity") mActivityContext;
      @Inject FragmentManager mFragmentManager;
  
      @Inject
      public TabPresenter() {}
  
      public void doNothingWithAnswerAndContextAndFragmentManager() {
          mAnswer *= 1;
      }
  }
  </code></pre>
  
  <p>After this all, build finishes with success status. But at runtime, i'm getting InvalidStateException immediately while fragment injects:</p>
  
  <pre><code>onAttach(Activity activity) {
      AndroidInjection.inject(this);
      super.onAttach(activity);
  } 
  </code></pre>
  
  <p>Exception stacktrace:</p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.example.drive.dagger2new, PID: 3064
   java.lang.RuntimeException: 
  Unable to start activity 
  ComponentInfo{com.example.drive.dagger2new/com.example.ui.TabsActivity}:
  java.lang.IllegalStateException:
  com.example.dagger.modules.main.TabsActivityModule must be set
  
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2680)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
   at android.app.ActivityThread.-wrap12(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6169)
   at java.lang.reflect.Method.invoke(Native Method)
   at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
  
  Caused by: java.lang.IllegalStateException: com.example.dagger.modules.main.TabsActivityModule must be set
   at com.example.dagger.components.DaggerAppComponent$TabsActivitySubcomponentBuilder.build(DaggerAppComponent.java:116)
   at com.example.dagger.components.DaggerAppComponent$TabsActivitySubcomponentBuilder.build(DaggerAppComponent.java:106)
   at dagger.android.AndroidInjector$Builder.create(AndroidInjector.java:68)
   at dagger.android.DispatchingAndroidInjector.maybeInject(DispatchingAndroidInjector.java:79)
   at     dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:104)
   at dagger.android.AndroidInjection.inject(AndroidInjection.java:61)
   at com.example.base.BaseActivity.onCreate(BaseActivity.java:35)
   at com.example.ui.TabsActivity.onCreate(TabsActivity.java:13)
   at android.app.Activity.performCreate(Activity.java:6679)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
   at     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741) 
   at android.app.ActivityThread.-wrap12(ActivityThread.java) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:154) 
   at android.app.ActivityThread.main(ActivityThread.java:6169) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) 
  </code></pre>
  
  <p>After looking at this, i though, that i just forget to set some new module instance. But, I don't doing this, because @ContributesAndroidInjector do it for me. 
  Ok, when i look at generated code, i saw that <strong>TabsActivitySubcomponentBuilder</strong> does not have a setter for TabsActivityModule. </p>
  
  <pre><code>private final class TabsActivitySubcomponentBuilder
    extends InjectorsModule_TabsActivityInjector.TabsActivitySubcomponent.Builder {
      private TabsActivityModule tabsActivityModule;
  
  private TabsActivity seedInstance;
  
  @Override
  public InjectorsModule_TabsActivityInjector.TabsActivitySubcomponent build() {
    if (tabsActivityModule == null) {
  // Exceptions throws here
          throw new IllegalStateException(
              TabsActivityModule.class.getCanonicalName() + " must be set");
        }
        if (seedInstance == null) {
          throw new IllegalStateException(TabsActivity.class.getCanonicalName() + " must be set");
        }
        return new TabsActivitySubcomponentImpl(this);
      }
  
      // here we seeing setter for activity
      @Override
      public void seedInstance(TabsActivity arg0) {
        this.seedInstance = Preconditions.checkNotNull(arg0);
      }
  
     // and for module??
    }
  </code></pre>
  
  <p>And finally, <strong>AndroidInjector.Builder</strong> sets only activity instance:</p>
  
  <pre><code>abstract class Builder&lt;T&gt; implements AndroidInjector.Factory&lt;T&gt; {
      @Override
      public final AndroidInjector&lt;T&gt; create(T instance) {
  // here
        seedInstance(instance);
  // and here must be seedModule(module), but nothing
        return build();
      }
  
      /**
       * Provides {@code instance} to be used in the binding graph of the built {@link
       * AndroidInjector}. By default, this is used as a {@link BindsInstance} method, but it may be
       * overridden to provide any modules which need a reference to the activity.
       *
       * &lt;p&gt;This should be the same instance that will be passed to {@link #inject(Object)}.
       */
      @BindsInstance
      public abstract void seedInstance(T instance);
  
      /** Returns a newly-constructed {@link AndroidInjector}. */
      public abstract AndroidInjector&lt;T&gt; build();
    }
  </code></pre>
  
  <p>Maybe i don't understand something? 
  Thanks!</p>