Reputation: 62529
I cant seem to use the injects word when trying to define classes that will use my injections.
Here is my MainModule.java class:
import dagger.Module;
import dagger.Provides;
@Module()
public class MainModule {
private Context context;
public MainModule(Context context) {
this.context = context;
}
@Provides
Object provideSomething(Context context) {
return new Object();
}
}
@Module()
class SubModule1 {
private Context context;
public SubModule1(Context context) {
this.context = context;
}
@Provides
Object provideSomethingElse(Context context) {
return new Object();
}
}
Here is my MainApplication class that extends application in android:
public class MainApplication extends Application {
private ObjectGraph objectGraph;
@Override
public void onCreate() {
super.onCreate();
objectGraph = ObjectGraph.create(new MainModule(this));
objectGraph = ObjectGraph.create(new SubModule1(this));
objectGraph = ObjectGraph.create(new ActivityModule());
objectGraph.inject(this);
}
}
And here is the issue im having below, android studio wont see the injects keyword so i cant use it.
The ActivityModule.java class is below:
@Module(
injects=
ListPageActivity.class
)
public class ActivityModule { }
Again its the injects keyword in ActiveModule that is not recognized in my IDE. Here is my gradle build dependency:
dependencies {
compile files('libs/volley.jar')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.squareup:dagger:0.9.1'
}
Upvotes: 0
Views: 589
Reputation: 1531
If you need to use 0.9.1 version, use entryPoints
keyword instead. That's because injects
is renamed entryPoints
and exists in newer versions.
I recommend you to use the last, 1.2.2 version from Square which have injects
:
http://square.github.io/dagger/
apt "com.squareup.dagger:dagger-compiler:1.2.2"
compile "com.squareup.dagger:dagger:1.2.2"
Or the newest Dagger 2 from Google. It's still snapshot but I hope not for long.:
http://google.github.io/dagger/.
apt "com.google.dagger:dagger-compiler:2.0-SNAPSHOT"
compile "com.google.dagger:dagger:2.0-SNAPSHOT"
Upvotes: 1