question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android dagger 2.11 : MainModule must be set

See original GitHub issue

I am working in the new Android dagger 2.11 implemtnation; I am getting this error in runtime :

MainModule must be set.

I have one Activity with it’s presenter injected in mainModule + multiple fragments( bottom view tabs)

I added ArticlesFragment as an example.

MainModule.java

@Module public abstract class MainModule {
 @FragmentScoped 
@ContributesAndroidInjector(modules = ArticlesFragment.class) abstract ArticlesFragment articlesFragment(); 

@Provides 
@ActivityScoped static String provideTaskId(MainActivity activity) {     
return activity.getIntent().getStringExtra(""); }  

@ActivityScoped 
@Provides 
public PresenterFactory<MainContract.Presenter> providePresenterFactory() { return MainPresenter::new; }

ActivityBindingModule.java : addded to the appComponent


@ActivityScoped @ContributesAndroidInjector(modules = MainModule.class)
  abstract MainActivity mainActivity();

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
liminalcommented, Oct 14, 2017

@alouanemed it’ll work if you just make it static. having an instance method means you have to have an instance of the module. If the provider-method is static then dagger can use it without requiring an instance of the module. So just changing it to @ActivityScoped @Provides public static PresenterFactory<MainContract.Presenter> providePresenterFactory() { return MainPresenter::new; }

should work fine

1reaction
vestrel00commented, Oct 19, 2017

Good to see this issue is resolved. This made me realize that there were only 2 places (1, 2) where I demonstrated how to use @Provides instead of @Binds in abstract module classes. Furthermore, I didn’t at all discuss this in my article, which I’ll now update with these discussions.

Thanks for bringing this up @alouanemed. Good eyes there @liminal!

UPDATE:

Someone asked me the same question. I answered the same issue with more in-depth explanations here: link

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module must be set dagger 2 - java - Stack Overflow
Dagger will automatically create Module for dependency graph if that Module has default constructor. If you use custom constructor then you ...
Read more >
Dagger-Hilt in Detail - Full Course - YouTube
In this video you will learn the essential things about Dagger -Hilt.00:00 - Introduction & Dependencies02:11 - Application class03:57 ...
Read more >
Using Dagger in multi-module apps - Android Developers
The app module is a good place to declare your application component (for example, ApplicationComponent in the image below) that can provide ...
Read more >
Dagger 2.11 with Android - Medium
Dagger2 is a fully static, compile-time dependency injection framework for both Java and Android. It is an adaptation of an earlier version ...
Read more >
DaggerMock - Bountysource
Created 2 years ago in fabioCollini/DaggerMock with 0 comments. The Gradle dependencies for Java in the README.md over Repository https://jitpack.io/ are wrong ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found