title: How to @Inject an abstract BaseActivity and its subclasses using dagger.android?
body: <p>I'm using the new <code>dagger.android</code> package from <a href="https://google.github.io/dagger/" rel="noreferrer">Dagger 2</a> to inject Android dependencies in my project.</p>
  
  <ul>
  <li>I need all my Activities to be a subclass of an abstract <code>BaseActivity</code></li>
  <li><p>In my <code>BaseActivity</code> I have member variables to be injected. This way:</p>
  
  <pre><code>abstract class BaseActivity : AppCompatActivity() {
      @Inject
      lateinit var prefs: MyPreferenceDataStore
      ...// more @Injected members
  }
  </code></pre></li>
  <li><p>I do it because I want subclasses of <code>BaseActiviy</code> can have access to injected members of <code>BaseActivity</code>:</p>
  
  <pre><code>class SubClassActivity : BaseActivity() {
      override fun onCreate(savedInstanceState: Bundle) {                
          val x = prefs.getXXX //use prefs variable from parent class
      }
  }
  </code></pre></li>
  <li><p>This is my ApplicationComponent:</p>
  
  <pre><code>@Singleton @Component(modules = arrayOf(
                  ApplicationModule::class,
                  ActivityBindingModule::class,
                  AndroidSupportInjectionModule::class
              ))
  interface ApplicationComponent {
      @Component.Builder interface Builder {
          @BindsInstance
          fun application(application: Application): Builder
          fun build(): ApplicationComponent
      }
      fun inject(app: AndroidApplication)
  }
  </code></pre></li>
  <li><p>The <code>ApplicationModule</code> class has simple <code>@Provides</code> annotated methods:</p>
  
  <pre><code>@Module
  class ApplicationModule {
      @Singleton @Provides
      fun providesMyPreferenceDataStore(context: Context): MyPreferenceDataStore {
          return MyPreferenceDataStoreImpl(context)
      }
      // more @Provides annotated methods
  }
  </code></pre>
  
  <p>I think the problem is in my <code>ActivityBindingModule</code></p>
  
  <pre><code>@Module
  abstract class ActivityBindingModule {
  
      @PerActivity
      @ContributesAndroidInjector(
          modules = arrayOf(BaseActivityModule::class
      ))
      abstract fun bindBaseActivity(): BaseActivity
  
      @PerActivity
      @ContributesAndroidInjector(
          modules = arrayOf(
              BaseActivityModule::class
      ))
      abstract fun bindSubClassActivity(): SubClassActivity
  }
  </code></pre></li>
  </ul>
  
  <p>This is what I have tried so far:</p>
  
  <ul>
  <li><p>Make the <code>bindSubClassActivity()</code> method not to depend of <code>BaseActivityModule::class</code>, didn't work.</p></li>
  <li><p>Move the <code>providesMyPreferenceDataStore</code> from <code>ApplicationModule</code> to the <code>BaseActivityModule</code>, so that the class is:</p>
  
  <pre><code>@Module
  class BaseActivityModule {
      @PerActivity @Provides
      fun providesMyPreferenceDataStore(context: Context): MyPreferenceDataStore {
          return MyPreferenceDataStoreImpl(context)
      }
  }
  </code></pre></li>
  </ul>
  
  <p>And this is the error I'm getting:</p>
  
  <pre><code>Error: [dagger.android.AndroidInjector.inject(T)] com.example.BaseActivity cannot
  be provided without an @Provides-annotated method.
  This type supports members injection but cannot
  be implicitly provided.
  </code></pre>