[英]Cannot use newer Dagger 2.11 API in Android
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
我试图将Dagger 2导入Android Studio上的全新项目中,并查看各种指南和文档,所以我无法使用
DaggerAppComponent
My Gradle settings are as follows: 我的Gradle设置如下:
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: 在我的
TodolistApplication.java
类中:
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);
}
However Android Studio shows the following error: 但是,Android Studio显示以下错误:
Error:(21, 5) error: cannot find symbol variable DaggerAppComponent
错误:(21,5)错误:找不到符号变量DaggerAppComponent
I have tried rebuilding the project and importing various dagger
files, however nothing seems to have worked. 我尝试重建项目并导入各种
dagger
文件,但是似乎没有任何效果。
Error:(21, 5) error: cannot find symbol variable DaggerAppComponent
错误:(21,5)错误:找不到符号变量DaggerAppComponent
The above error is not a dependency error. 上面的错误不是依赖性错误。 AppComponent must be first created before using it like below
必须先创建AppComponent,然后再使用,如下所示
@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 查看此参考资料以全面了解https://medium.com/@isoron/a-friendly-introduction-to-dagger-2-part-1-dbdf2f3fb17b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.