I am trying to use Dagger 2 in my application. I keep getting this error:
Error: execution completed for task ': app: compileDebugJavaWithJavac'. java.lang.IllegalArgumentException: @ dagger.Module does not define subcomponents of element ()
I do not use subcomponents in the application at all, so I have no idea why this error occurs. I have one module and one component. Module:
@Singleton
@Module
public class ApplicationModule {
private final WSTApplication application;
public ApplicationModule(WSTApplication application) {
this.application = application;
}
@Provides
public WSTApplication application() {
return this.application;
}
@Provides
public Context applicationContext() {
return this.application;
}
@Provides
Realm provideRealm() {
return Realm.getDefaultInstance();
}
@Provides
RealmHelper providesRealmHelper(final Realm realm) {
return new RealmHelper(realm);
}
@Provides
@Singleton
public WorkoutPresenter providesWorkoutPresenter(final RealmHelper helper) {
return new WorkoutPresenter(helper);
}
}
And my component:
@Singleton
@Component(modules={ApplicationModule.class})
public interface ApplicationComponent {
void inject (MainActivity activity);
WSTApplication application();
Context applicationContext();
Realm provideRealm();
RealmHelper providesRealmHelper(Realm realm);
WorkoutPresenter providesWorkoutPresenter(RealmHelper helper);
}
And here is the onCreate from my application:
@Override
public void onCreate() {
super.onCreate();
component = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
}
DaggerApplicationComponent , , , - ? (Dagger_ApplicationComponent), .
Google, , , , . . .
, , build.gradle:
buildscript:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
build.gradle:
apply plugin: 'com.neenbedankt.android-apt'
:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.dagger:dagger:2.1'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
apt 'com.google.dagger:dagger-compiler:2.7'
provided 'org.glassfish:javax.annotation:10.0-b28'
}
, ! Dagger2, , ( , ... , ). , .