title: Dagger 2 issue overriding single provides annotated method from a module in a library which app uses
body: <p><strong>GitHub Project Link</strong></p>
  
  <p>I have made a <a href="https://github.com/qazimusab/Dagger2LibraryProject" rel="noreferrer">project on GitHub</a> which is a model of the dagger 2 architecture of my projects actual architecture. This question will be based off of the GitHub project.</p>
  
  <p>I have provided many code snippets in this question, however, it may be easier to just compile the project yourself in Android Studio to understand the problem.</p>
  
  <p>If you check out the code, it won't compile. Go into AppModule.java and comment out both provides methods and it should compile.</p>
  
  <p>The main question is the last line on this post.</p>
  
  <p><a href="https://github.com/qazimusab/Dagger2LibraryProject" rel="noreferrer">https://github.com/qazimusab/Dagger2LibraryProject</a></p>
  
  <p><strong>Architecture</strong></p>
  
  <p>I have a library which contains all the code needed to make the application. The point of this architecture is that each app I create in the project should be able to use the library and ,through dagger 2, be able to provide different implementations for any single class or activity it wants in it's own module. At this point I only have one application in this sample project which uses the library.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>With dagger one, I had the same architecture, and in the app specific module (as opposed to the library module), I was able to add a new provides annotated method to override any implementation which was being provided in the any of the library modules as long as </p>
  
  <ol>
  <li>The method was in a module in the app module</li>
  <li>The method was annotated with @Provides</li>
  <li>The method had the same return type as the one you want to override</li>
  </ol>
  
  <p>With Dagger 2, the architecture works when I either don't override any provides or if I do, when I override every single provides in that module and remove that module from the includes from the Application specific module.</p>
  
  <p>For example, in my project, I have an app and a library. </p>
  
  <p>The app has an AppModule; the library has a CatModule to provide a Cat and CatFood, a dog module to provide a Dog and DogFood, and a LibraryModule to provide the activities. </p>
  
  <p>CatModule.java</p>
  
  <pre><code>package com.example.qaziahmed.library.application.modules;
  
  import com.example.qaziahmed.library.classes.Cat; import
  com.example.qaziahmed.library.classes.CatFood; import
  com.example.qaziahmed.library.classes.contract.ICat; import
  com.example.qaziahmed.library.classes.contract.ICatFood;
  
  import javax.inject.Singleton;
  
  import dagger.Module; import dagger.Provides;
  
  /**  * Created by qaziahmed on 11/23/15.  */ @Module public class
  CatModule {
  
      @Provides
      @Singleton
      ICat provideCat() {
          return new Cat();
      }
  
      @Provides
      ICatFood provideCatFood(){
          return new CatFood();
      } }
  </code></pre>
  
  <p>DogModule.java</p>
  
  <pre><code>package com.example.qaziahmed.library.application.modules;
  
  import com.example.qaziahmed.library.classes.Dog; import
  com.example.qaziahmed.library.classes.DogFood; import
  com.example.qaziahmed.library.classes.contract.IDog; import
  com.example.qaziahmed.library.classes.contract.IDogFood;
  
  import javax.inject.Singleton;
  
  import dagger.Module; import dagger.Provides;
  
  /**  * Created by qaziahmed on 11/23/15.  */ @Module public class
  DogModule {
  
      @Provides
      @Singleton
      IDog provideDog() {
          return new Dog();
      }
  
      @Provides
      IDogFood provideDogFood(){
          return new DogFood();
      }
  
  }
  </code></pre>
  
  <p>So, in my application module, I want to provide a house cat implementation of ICat instead of a generic cat and an AllNaturalDogFood implementation of IDogFood instead of just regular DogFood, then in my AppModule I add two provides to override those</p>
  
  <p>AppModule.java</p>
  
  <pre><code>package com.example.qaziahmed.dagger2libraryproject.application;
  
  import
  com.example.qaziahmed.dagger2libraryproject.classes.AllNaturalDogFood;
  import com.example.qaziahmed.dagger2libraryproject.classes.HouseCat;
  import com.example.qaziahmed.library.application.modules.CatModule;
  import com.example.qaziahmed.library.application.modules.DogModule;
  import
  com.example.qaziahmed.library.application.modules.LibraryModule;
  import com.example.qaziahmed.library.classes.contract.ICat; import
  com.example.qaziahmed.library.classes.contract.IDogFood;
  
  import javax.inject.Singleton;
  
  import dagger.Module; import dagger.Provides;
  
  /**  * Created by ogre on 2015-07-12  */ @Module(includes = {
          LibraryModule.class,
          DogModule.class,
          CatModule.class }) public class AppModule {
  
      @Provides
      @Singleton
      ICat provideHouseCat() {
          return new HouseCat();
      }
  
      @Provides
      IDogFood provideAllNaturalDogFood(){
          return new AllNaturalDogFood();
      } }
  </code></pre>
  
  <p>Now, when I run this setup, this is the error I get:</p>
  
  <blockquote>
    <p>Error:com.example.qaziahmed.library.classes.contract.ICat is bound multiple times:
              @Provides @Singleton com.example.qaziahmed.library.classes.contract.ICat com.example.qaziahmed.dagger2libraryproject.application.AppModule.provideHouseCat()
              @Provides @Singleton com.example.qaziahmed.library.classes.contract.ICat com.example.qaziahmed.library.application.modules.CatModule.provideCat()
    Error:com.example.qaziahmed.library.classes.contract.IDogFood is bound multiple times:
              @Provides com.example.qaziahmed.library.classes.contract.IDogFood com.example.qaziahmed.dagger2libraryproject.application.AppModule.provideAllNaturalDogFood()
              @Provides com.example.qaziahmed.library.classes.contract.IDogFood com.example.qaziahmed.library.application.modules.DogModule.provideDogFood()</p>
  </blockquote>
  
  <p>Now, if in AppModule.java, I also add provides annotated methods to provide Cat Food and Provide Dog and then remove CatModule.class and DogModule.class from the includes in App Module then it works. </p>
  
  <p><strong>However, the whole question is how do I override a single provides method in some module in the library without having to override every provides annotated method inside that specific module and then removing that module from the includes in AppModule.java</strong></p>