@ContributesAndroidInjector: Cannot be provided without an @Provides-annotated method.
See original GitHub issue“@ContributesAndroidInjector” could not inject the fragment view interface on presenter constructor (MVP) but the same approach works fine with activity flow.
Error.
error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] com.jega.android.example.dagger2.login.LoginView cannot be provided without an @Provides-annotated method.
com.jega.android.example.dagger2.login.LoginView is injected at
com.jega.android.example.dagger2.login.LoginPresenter.<init>(…, callback)
com.jega.android.example.dagger2.login.LoginPresenter is injected at
com.jega.android.example.dagger2.login.LoginFragment.presenter
com.jega.android.example.dagger2.login.LoginFragment is injected at
com.jega.android.example.dagger2.MainActivity.login
com.jega.android.example.dagger2.MainActivity is injected at
dagger.android.AndroidInjector.inject(T)
component path: com.jega.android.example.dagger2.di.MyAppComponent → com.jega.android.example.dagger2.di.MyActivityModule_AccountActivityInjector.MainActivitySubcomponent
@Module
public abstract class MainActivityModule {
@ContributesAndroidInjector(modules = LoginFragmentModule.class)
abstract LoginFragment LoginFragmentInjector();
@Binds
abstract MainActivityView bindMainActivityView(MainActivity mainActivity);
@Binds
abstract Activity activity(MainActivity mainActivity);
}
public class LoginFragment extends BaseFragment implements LoginView {
@Inject
LoginPresenter presenter;
@Inject // If we comment this code and create a instance from activity it works fine.
public LoginFragment() {
}
}
@Module
public abstract class LoginFragmentModule {
@Binds
abstract LoginView activityLoginFragment(LoginFragment login);
}
public class LoginPresenter {
private AccountManager accountManager;
private LoginView callback;
@Inject
public LoginPresenter(AccountManager accountManager, LoginView callback) {
this.accountManager = accountManager;
this.callback = callback;
}
public void login() {
accountManager.login();
callback.onSuccess();
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Android dagger cannot be provided without ... - Stack Overflow
In this way this application instance is bound inside the component. ... class ActivityModule { @ContributesAndroidInjector public abstract ...
Read more >cannot be provided without an @Provides-annotated method ...
Coding example for the question cannot be provided without an @Provides-annotated method, A binding with matching key exists in component-kotlin.
Read more >dagger/missing binding cannot be provided without an ...
WorkerParameters cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract interface AppComponent extends dagger.
Read more >Dagger by Tutorials, Chapter 16: Dagger & Android | Kodeco ...
Activity cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract interface ApplicationComponent { ^ android.app.
Read more >Dagger 2 annotations: can @Provides and @Binds coexist?
Theoretically, Dagger modules cannot simultaneously contain abstract and ... Note: @Provides annotated methods require a concrete class in order to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i didn’t get chance to get deeper into this issue. In my case, i just removed @Inject constructor annotation on all the fragments, later it’s started working fine.
On Sat, Oct 20, 2018 at 6:19 PM SQSong notifications@github.com wrote:
– Jegadeesan M
@jega-ms Thanks for your reply, bro.
Yes, my fragment’s constructor has
@Inject
annotation, but it didn’t work. here are my code: The application component:Then
ActivityBindingModule
:The
MainModule
for theHomeActivity
,HomeActivity
has fourFragment
:The
HomeModule
for the firstHomeFragment
:HomeFragment
implementHomeContract.HomeView
, and the constructor has@Inject
annotation:BaseFragment
inject thePresenter
:HomePresenter
code:But when i build the project, it still tips:
HomeContract.HomeView cannot be provided without an @Provides-annotated method.
Like you said, the
Activity
injectView
is ok. but in the fragment, it was compile error, i don’t know why?