无法在 Android 中使用较新的 Dagger 2.11 API

Cannot use newer Dagger 2.11 API in Android

我正在尝试将 Dagger 2 导入到 Android Studio 上的一个全新项目中,并查看了各种指南和文档,但我无法使用 DaggerAppComponent

我的Gradle设置如下:

构建(项目)

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(模块: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'
}

我的 TodolistApplication.java class:我有这个:

      @Override
  public void onCreate() {
    super.onCreate();

    DaggerAppComponent
            .builder()
            .application(this)
            .build()
            .inject(this);
  }

但是 Android Studio 显示以下错误:

Error:(21, 5) error: cannot find symbol variable DaggerAppComponent

我曾尝试重建项目并导入各种 dagger 文件,但似乎没有任何效果。

Error:(21, 5) error: cannot find symbol variable DaggerAppComponent

以上错误不是依赖错误。 必须先创建 AppComponent,然后才能像下面这样使用它

@Module public class ApplicationModule {
   //all dependency provides here
}

@Component(modules = ApplicationModule.class) 
public interface ApplicationComponent {
}

查看此参考以获得完整的理解https://medium.com/@isoron/a-friendly-introduction-to-dagger-2-part-1-dbdf2f3fb17b