I am trying to import Dagger 2 into a brand new project on Android Studio and having a look at the various guides and documentation, I am unable to use DaggerAppComponent
My Gradle settings are as follows:
build (Project)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.raywenderlich.todolist"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
//Dagger 2
compile 'com.google.dagger:dagger:2.11'
compile 'com.google.dagger:dagger-android:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
}
The in my TodolistApplication.java
class: I have this:
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);
}
However Android Studio shows the following error:
Error:(21, 5) error: cannot find symbol variable DaggerAppComponent
I have tried rebuilding the project and importing various dagger
files, however nothing seems to have worked.
Error:(21, 5) error: cannot find symbol variable DaggerAppComponent
The above error is not a dependency error. AppComponent must be first created before using it like below
@Module public class ApplicationModule {
//all dependency provides here
}
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
}
Check this reference for complete understanding https://medium.com/@isoron/a-friendly-introduction-to-dagger-2-part-1-dbdf2f3fb17b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.