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.

@ContributesAndroidInjector doesn't work with gradle build system

See original GitHub issue

During :app:compileDebugJavaWithJavac task, following exception is thrown:

:app:compileDebugJavaWithJavac
/app/build/generated/source/apt/debug/pl/kibao/contributesandroidinjector/ContributesAndroidInjectorModule_ContributeMainActivityInjector.java:21: 
error: @dagger.android.ActivityKey methods should bind dagger.android.AndroidInjector.Factory<? extends android.app.Activity>, 
not dagger.android.AndroidInjector.Factory<? extends android.app.Activity>. 
See https://google.github.io/dagger/android
  abstract AndroidInjector.Factory<? extends Activity> bindAndroidInjectorFactory(
                                                       ^
1 error

Generated class:

package pl.kibao.contributesandroidinjector;

import android.app.Activity;
import dagger.Binds;
import dagger.Module;
import dagger.Subcomponent;
import dagger.android.ActivityKey;
import dagger.android.AndroidInjector;
import dagger.multibindings.IntoMap;

@Module(
  subcomponents =
      ContributesAndroidInjectorModule_ContributeMainActivityInjector.MainActivitySubcomponent.class
)
public abstract class ContributesAndroidInjectorModule_ContributeMainActivityInjector {
  private ContributesAndroidInjectorModule_ContributeMainActivityInjector() {}

  @Binds
  @IntoMap
  @ActivityKey(MainActivity.class)
  abstract AndroidInjector.Factory<? extends Activity> bindAndroidInjectorFactory(
      MainActivitySubcomponent.Builder builder);

  @Subcomponent(modules = MainModule.class)
  public interface MainActivitySubcomponent extends AndroidInjector<MainActivity> {
    @Subcomponent.Builder
    abstract class Builder extends AndroidInjector.Builder<MainActivity> {}
  }
}

I’ve created separate app with the same code, then replace @ContributesAndroidInjector with the generated class and that worked. That is why I think the problem is related to integration with gradle build system.

Example project: https://github.com/kibao/dagger-contributes-android-injector Travis build: https://travis-ci.org/kibao/dagger-contributes-android-injector/builds/223293977#L1756

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
Srokacommented, Apr 21, 2017

I am not the original reporter but had the same problem and it is now fixed with latest snapshot. Thank you

0reactions
ronshapirocommented, Apr 21, 2017

The latest snapshot should have a fix for this. It’ll be live in ~15 minutes, can you check if it is in fact working then?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting gradle file when dagger doesn't auto ...
Try the following options: 1) Close the file MyApplication.java and reopen, 2) Run Make Project two times (just to trigger editor update), 3) ......
Read more >
[Solved]-How to generate module consisting ... - appsloveworld
The error you are getting is because @Binds and @ContributesAndroidInjector methods must be abstract because they don't have method bodies.
Read more >
Stop Holding Dagger by the Blade: Use the Hilt | Infinum
Hilt will make your Dagger setup way more readable and much easier to maintain. ... In some ways, Hilt is a remedy for...
Read more >
Android Development: 15 Libraries You Should Be Using
This library, unlike ButterKnife, does not make use annotations. Using Databinding Library. Enable data binding in the app-module build.gradle ...
Read more >
r/androiddev - Weekly Questions Thread - December 03, 2018
What's your version of Gradle? I had this issue with 5.0, it should be fixed for 5.1. For now stick with 4.10.x or...
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