Dagger 2 Unable to install module via contributesAndroidInjector for fragment












0















I'm trying to figure out why I am unable to install a module into my fragment subcomponent via @ContributesAndroidInjector. For instance:



The following works (compiles and is properly injected),



@Module(includes = ColumnWidthModule.class)  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector
abstract GalleryFragment bindGalleryFragment();
}


but the following does not compile:



@Module  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector(modules = ColumnWidthModule.class)
abstract GalleryFragment bindGalleryFragment();
}


The compiler error I'm getting is this:



AppComponent.java:24: error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided 
without an @Provides-annotated method.

UPDATE: Here is the full error:

error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided without an @Provides-annotated method.
public interface AppComponent
^
A binding with matching key exists in component: GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent
@javax.inject.Named("columnWidth") java.lang.Integer is injected at
GalleryFragment.columnWidth
javax.inject.Provider<GalleryFragment> is injected at
GalleryActivity.galleryFragmentProvider GalleryActivity is injected at
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent]
It is also requested at: GalleryFragment.AutoFitGridLayoutManager(…, columnWidth)
The following other entry points also depend on it:
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent → GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent]
1 error


The module itself looks like this:



@Module
public class ColumnWidthModule
{
@Provides
@Named("columnWidth")
static int columnWidth()
{
return 300;
}
}


and here is where I inject the variable:



public class GalleryFragment extends Fragment
{
@Inject
@Named("columnWidth")
int columnWidth;

@Override
public void onAttach(Context context)
{
AndroidSupportInjection.inject(this);
super.onAttach(context);
}

// rest of code not shown
}


Any help would be appreciated.










share|improve this question

























  • Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

    – David Medenjak
    Nov 18 '18 at 11:34











  • @Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

    – Vairavan
    Nov 18 '18 at 15:16











  • @DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

    – Vinnie
    Nov 19 '18 at 18:01











  • @Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

    – Vinnie
    Nov 19 '18 at 18:02













  • @Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

    – David Medenjak
    Nov 19 '18 at 18:04


















0















I'm trying to figure out why I am unable to install a module into my fragment subcomponent via @ContributesAndroidInjector. For instance:



The following works (compiles and is properly injected),



@Module(includes = ColumnWidthModule.class)  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector
abstract GalleryFragment bindGalleryFragment();
}


but the following does not compile:



@Module  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector(modules = ColumnWidthModule.class)
abstract GalleryFragment bindGalleryFragment();
}


The compiler error I'm getting is this:



AppComponent.java:24: error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided 
without an @Provides-annotated method.

UPDATE: Here is the full error:

error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided without an @Provides-annotated method.
public interface AppComponent
^
A binding with matching key exists in component: GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent
@javax.inject.Named("columnWidth") java.lang.Integer is injected at
GalleryFragment.columnWidth
javax.inject.Provider<GalleryFragment> is injected at
GalleryActivity.galleryFragmentProvider GalleryActivity is injected at
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent]
It is also requested at: GalleryFragment.AutoFitGridLayoutManager(…, columnWidth)
The following other entry points also depend on it:
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent → GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent]
1 error


The module itself looks like this:



@Module
public class ColumnWidthModule
{
@Provides
@Named("columnWidth")
static int columnWidth()
{
return 300;
}
}


and here is where I inject the variable:



public class GalleryFragment extends Fragment
{
@Inject
@Named("columnWidth")
int columnWidth;

@Override
public void onAttach(Context context)
{
AndroidSupportInjection.inject(this);
super.onAttach(context);
}

// rest of code not shown
}


Any help would be appreciated.










share|improve this question

























  • Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

    – David Medenjak
    Nov 18 '18 at 11:34











  • @Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

    – Vairavan
    Nov 18 '18 at 15:16











  • @DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

    – Vinnie
    Nov 19 '18 at 18:01











  • @Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

    – Vinnie
    Nov 19 '18 at 18:02













  • @Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

    – David Medenjak
    Nov 19 '18 at 18:04
















0












0








0








I'm trying to figure out why I am unable to install a module into my fragment subcomponent via @ContributesAndroidInjector. For instance:



The following works (compiles and is properly injected),



@Module(includes = ColumnWidthModule.class)  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector
abstract GalleryFragment bindGalleryFragment();
}


but the following does not compile:



@Module  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector(modules = ColumnWidthModule.class)
abstract GalleryFragment bindGalleryFragment();
}


The compiler error I'm getting is this:



AppComponent.java:24: error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided 
without an @Provides-annotated method.

UPDATE: Here is the full error:

error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided without an @Provides-annotated method.
public interface AppComponent
^
A binding with matching key exists in component: GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent
@javax.inject.Named("columnWidth") java.lang.Integer is injected at
GalleryFragment.columnWidth
javax.inject.Provider<GalleryFragment> is injected at
GalleryActivity.galleryFragmentProvider GalleryActivity is injected at
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent]
It is also requested at: GalleryFragment.AutoFitGridLayoutManager(…, columnWidth)
The following other entry points also depend on it:
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent → GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent]
1 error


The module itself looks like this:



@Module
public class ColumnWidthModule
{
@Provides
@Named("columnWidth")
static int columnWidth()
{
return 300;
}
}


and here is where I inject the variable:



public class GalleryFragment extends Fragment
{
@Inject
@Named("columnWidth")
int columnWidth;

@Override
public void onAttach(Context context)
{
AndroidSupportInjection.inject(this);
super.onAttach(context);
}

// rest of code not shown
}


Any help would be appreciated.










share|improve this question
















I'm trying to figure out why I am unable to install a module into my fragment subcomponent via @ContributesAndroidInjector. For instance:



The following works (compiles and is properly injected),



@Module(includes = ColumnWidthModule.class)  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector
abstract GalleryFragment bindGalleryFragment();
}


but the following does not compile:



@Module  
public abstract class GalleryFragmentModule
{
@ContributesAndroidInjector(modules = ColumnWidthModule.class)
abstract GalleryFragment bindGalleryFragment();
}


The compiler error I'm getting is this:



AppComponent.java:24: error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided 
without an @Provides-annotated method.

UPDATE: Here is the full error:

error: [Dagger/MissingBinding] @javax.inject.Named("columnWidth") java.lang.Integer cannot be provided without an @Provides-annotated method.
public interface AppComponent
^
A binding with matching key exists in component: GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent
@javax.inject.Named("columnWidth") java.lang.Integer is injected at
GalleryFragment.columnWidth
javax.inject.Provider<GalleryFragment> is injected at
GalleryActivity.galleryFragmentProvider GalleryActivity is injected at
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent]
It is also requested at: GalleryFragment.AutoFitGridLayoutManager(…, columnWidth)
The following other entry points also depend on it:
dagger.android.AndroidInjector.inject(T) [AppComponent → ActivityBindingModule_BindGalleryActivity.GalleryActivitySubcomponent → GalleryFragmentModule_BindGalleryFragment.GalleryFragmentSubcomponent]
1 error


The module itself looks like this:



@Module
public class ColumnWidthModule
{
@Provides
@Named("columnWidth")
static int columnWidth()
{
return 300;
}
}


and here is where I inject the variable:



public class GalleryFragment extends Fragment
{
@Inject
@Named("columnWidth")
int columnWidth;

@Override
public void onAttach(Context context)
{
AndroidSupportInjection.inject(this);
super.onAttach(context);
}

// rest of code not shown
}


Any help would be appreciated.







android dependency-injection dagger-2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 23:55







Vinnie

















asked Nov 18 '18 at 2:45









VinnieVinnie

1,95821839




1,95821839













  • Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

    – David Medenjak
    Nov 18 '18 at 11:34











  • @Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

    – Vairavan
    Nov 18 '18 at 15:16











  • @DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

    – Vinnie
    Nov 19 '18 at 18:01











  • @Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

    – Vinnie
    Nov 19 '18 at 18:02













  • @Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

    – David Medenjak
    Nov 19 '18 at 18:04





















  • Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

    – David Medenjak
    Nov 18 '18 at 11:34











  • @Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

    – Vairavan
    Nov 18 '18 at 15:16











  • @DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

    – Vinnie
    Nov 19 '18 at 18:01











  • @Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

    – Vinnie
    Nov 19 '18 at 18:02













  • @Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

    – David Medenjak
    Nov 19 '18 at 18:04



















Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

– David Medenjak
Nov 18 '18 at 11:34





Seems like you'd inject columnWidth in your activity (or something else higher scoped) as well, but you didn't include the full error printed after ..cannot be provided.., so it's hard to say

– David Medenjak
Nov 18 '18 at 11:34













@Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

– Vairavan
Nov 18 '18 at 15:16





@Vinnie Can you try some other dependency (like a random class SomeObject) without @Named? If that works, this seems like an issue

– Vairavan
Nov 18 '18 at 15:16













@DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

– Vinnie
Nov 19 '18 at 18:01





@DavidMedenjak Is there a reason why I would need to inject columnWidth in my activity/higher scope when it's only needed by the fragment?

– Vinnie
Nov 19 '18 at 18:01













@Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

– Vinnie
Nov 19 '18 at 18:02







@Vairavan It doesn't work with a random class either. Seems like an issue with @ContributesAndroidInjector for fragments?

– Vinnie
Nov 19 '18 at 18:02















@Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

– David Medenjak
Nov 19 '18 at 18:04







@Vinnie I didn't say you should inject it there, I said it seems something there requires it. Either you also inject it in your activity, or one of the classes that needs it is @ActivityScope If you include the full error it would be listed there

– David Medenjak
Nov 19 '18 at 18:04














1 Answer
1






active

oldest

votes


















0














I was able to fix this one of two ways:







  1. I noticed that my activity injects a provider for my fragment, like so:



    public class GalleryActivity extends AppCompatActivity implements HasSupportFragmentInjector
    {
    @Inject
    DispatchingAndroidInjector<Fragment> fragmentInjector;

    @Inject
    Provider<GalleryFragment> galleryFragmentProvider;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    AndroidInjection.inject(this);
    // ...

    getSupportFragmentManager()
    .beginTransaction()
    .add(R.id.fragment_container, galleryFragmentProvider.get(), null)
    .commit();

    }
    }


    The GalleryActivity has a Provider<GalleryFragment>, which means that it is also dependent on columnWidth. In other words, columnWidth is a dependency of GalleryFragment, and GalleryFragment in turn is a dependency of GalleryActivity. Removing the galleryFragmentProvider and changing the fragment transaction to just use a new GalleryFragment() will fix this:



        getSupportFragmentManager().beginTransaction()
    .add(R.id.fragment_container, new GalleryFragment(), null).commit();







  1. Another way to fix this and continue using the Provider<GalleryFragment> in the activity is to install the ColumnWidthModule to the activity's contributesAndroidInjector instead, namely this:



    public abstract class ActivityBindingModule
    {
    @ActivityScope
    @ContributesAndroidInjector(modules = {
    GalleryFragmentModule.class,
    ColumnWidthModule.class })
    abstract GalleryActivity bindGalleryActivity();
    }


    I guess the reason why it worked is because it's pretty much equivalent to what I posted above:



    @Module(includes = ColumnWidthModule.class)  
    public abstract class GalleryFragmentModule
    {
    @ContributesAndroidInjector
    abstract GalleryFragment bindGalleryFragment();
    }







share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357442%2fdagger-2-unable-to-install-module-via-contributesandroidinjector-for-fragment%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I was able to fix this one of two ways:







    1. I noticed that my activity injects a provider for my fragment, like so:



      public class GalleryActivity extends AppCompatActivity implements HasSupportFragmentInjector
      {
      @Inject
      DispatchingAndroidInjector<Fragment> fragmentInjector;

      @Inject
      Provider<GalleryFragment> galleryFragmentProvider;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
      AndroidInjection.inject(this);
      // ...

      getSupportFragmentManager()
      .beginTransaction()
      .add(R.id.fragment_container, galleryFragmentProvider.get(), null)
      .commit();

      }
      }


      The GalleryActivity has a Provider<GalleryFragment>, which means that it is also dependent on columnWidth. In other words, columnWidth is a dependency of GalleryFragment, and GalleryFragment in turn is a dependency of GalleryActivity. Removing the galleryFragmentProvider and changing the fragment transaction to just use a new GalleryFragment() will fix this:



          getSupportFragmentManager().beginTransaction()
      .add(R.id.fragment_container, new GalleryFragment(), null).commit();







    1. Another way to fix this and continue using the Provider<GalleryFragment> in the activity is to install the ColumnWidthModule to the activity's contributesAndroidInjector instead, namely this:



      public abstract class ActivityBindingModule
      {
      @ActivityScope
      @ContributesAndroidInjector(modules = {
      GalleryFragmentModule.class,
      ColumnWidthModule.class })
      abstract GalleryActivity bindGalleryActivity();
      }


      I guess the reason why it worked is because it's pretty much equivalent to what I posted above:



      @Module(includes = ColumnWidthModule.class)  
      public abstract class GalleryFragmentModule
      {
      @ContributesAndroidInjector
      abstract GalleryFragment bindGalleryFragment();
      }







    share|improve this answer






























      0














      I was able to fix this one of two ways:







      1. I noticed that my activity injects a provider for my fragment, like so:



        public class GalleryActivity extends AppCompatActivity implements HasSupportFragmentInjector
        {
        @Inject
        DispatchingAndroidInjector<Fragment> fragmentInjector;

        @Inject
        Provider<GalleryFragment> galleryFragmentProvider;

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
        AndroidInjection.inject(this);
        // ...

        getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.fragment_container, galleryFragmentProvider.get(), null)
        .commit();

        }
        }


        The GalleryActivity has a Provider<GalleryFragment>, which means that it is also dependent on columnWidth. In other words, columnWidth is a dependency of GalleryFragment, and GalleryFragment in turn is a dependency of GalleryActivity. Removing the galleryFragmentProvider and changing the fragment transaction to just use a new GalleryFragment() will fix this:



            getSupportFragmentManager().beginTransaction()
        .add(R.id.fragment_container, new GalleryFragment(), null).commit();







      1. Another way to fix this and continue using the Provider<GalleryFragment> in the activity is to install the ColumnWidthModule to the activity's contributesAndroidInjector instead, namely this:



        public abstract class ActivityBindingModule
        {
        @ActivityScope
        @ContributesAndroidInjector(modules = {
        GalleryFragmentModule.class,
        ColumnWidthModule.class })
        abstract GalleryActivity bindGalleryActivity();
        }


        I guess the reason why it worked is because it's pretty much equivalent to what I posted above:



        @Module(includes = ColumnWidthModule.class)  
        public abstract class GalleryFragmentModule
        {
        @ContributesAndroidInjector
        abstract GalleryFragment bindGalleryFragment();
        }







      share|improve this answer




























        0












        0








        0







        I was able to fix this one of two ways:







        1. I noticed that my activity injects a provider for my fragment, like so:



          public class GalleryActivity extends AppCompatActivity implements HasSupportFragmentInjector
          {
          @Inject
          DispatchingAndroidInjector<Fragment> fragmentInjector;

          @Inject
          Provider<GalleryFragment> galleryFragmentProvider;

          @Override
          protected void onCreate(Bundle savedInstanceState)
          {
          AndroidInjection.inject(this);
          // ...

          getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.fragment_container, galleryFragmentProvider.get(), null)
          .commit();

          }
          }


          The GalleryActivity has a Provider<GalleryFragment>, which means that it is also dependent on columnWidth. In other words, columnWidth is a dependency of GalleryFragment, and GalleryFragment in turn is a dependency of GalleryActivity. Removing the galleryFragmentProvider and changing the fragment transaction to just use a new GalleryFragment() will fix this:



              getSupportFragmentManager().beginTransaction()
          .add(R.id.fragment_container, new GalleryFragment(), null).commit();







        1. Another way to fix this and continue using the Provider<GalleryFragment> in the activity is to install the ColumnWidthModule to the activity's contributesAndroidInjector instead, namely this:



          public abstract class ActivityBindingModule
          {
          @ActivityScope
          @ContributesAndroidInjector(modules = {
          GalleryFragmentModule.class,
          ColumnWidthModule.class })
          abstract GalleryActivity bindGalleryActivity();
          }


          I guess the reason why it worked is because it's pretty much equivalent to what I posted above:



          @Module(includes = ColumnWidthModule.class)  
          public abstract class GalleryFragmentModule
          {
          @ContributesAndroidInjector
          abstract GalleryFragment bindGalleryFragment();
          }







        share|improve this answer















        I was able to fix this one of two ways:







        1. I noticed that my activity injects a provider for my fragment, like so:



          public class GalleryActivity extends AppCompatActivity implements HasSupportFragmentInjector
          {
          @Inject
          DispatchingAndroidInjector<Fragment> fragmentInjector;

          @Inject
          Provider<GalleryFragment> galleryFragmentProvider;

          @Override
          protected void onCreate(Bundle savedInstanceState)
          {
          AndroidInjection.inject(this);
          // ...

          getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.fragment_container, galleryFragmentProvider.get(), null)
          .commit();

          }
          }


          The GalleryActivity has a Provider<GalleryFragment>, which means that it is also dependent on columnWidth. In other words, columnWidth is a dependency of GalleryFragment, and GalleryFragment in turn is a dependency of GalleryActivity. Removing the galleryFragmentProvider and changing the fragment transaction to just use a new GalleryFragment() will fix this:



              getSupportFragmentManager().beginTransaction()
          .add(R.id.fragment_container, new GalleryFragment(), null).commit();







        1. Another way to fix this and continue using the Provider<GalleryFragment> in the activity is to install the ColumnWidthModule to the activity's contributesAndroidInjector instead, namely this:



          public abstract class ActivityBindingModule
          {
          @ActivityScope
          @ContributesAndroidInjector(modules = {
          GalleryFragmentModule.class,
          ColumnWidthModule.class })
          abstract GalleryActivity bindGalleryActivity();
          }


          I guess the reason why it worked is because it's pretty much equivalent to what I posted above:



          @Module(includes = ColumnWidthModule.class)  
          public abstract class GalleryFragmentModule
          {
          @ContributesAndroidInjector
          abstract GalleryFragment bindGalleryFragment();
          }








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 23:57

























        answered Nov 18 '18 at 3:20









        VinnieVinnie

        1,95821839




        1,95821839






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357442%2fdagger-2-unable-to-install-module-via-contributesandroidinjector-for-fragment%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?