繁体   English   中英

无法在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()
    }
}

构建(模块:应用)

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类中:

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

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

但是,Android Studio显示以下错误:

错误:(21,5)错误:找不到符号变量DaggerAppComponent

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

错误:(21,5)错误:找不到符号变量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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM