@ContributesAndroidInjector doesn't work with gradle build system
See original GitHub issueDuring :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:
- Created 6 years ago
- Reactions:2
- Comments:7
Top 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 >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 am not the original reporter but had the same problem and it is now fixed with latest snapshot. Thank you
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?