2017-07-21 59 views
0

我試圖導入匕首2成在Android Studio中的一個全新的項目,使用較新的匕首2.11 API並具有看看各種指南和文件,我無法使用DaggerAppComponent無法在Android的

我的搖籃設置如下:

構建(項目)

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() 
    } 
} 

構建(模塊: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' 
} 

的在我0​​類:我有這樣的:

 @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文件,但似乎沒有任何工作。

回答

2

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

+0

感謝之前先創建。它解決了我的一些問題,DaggerAppComponent現在正在工作,但是,編譯器沒有找到該代碼的'.application(this)'部分。另一個)錯誤:無法找到符號方法應用程序(ToDoListApplication) - 我覺得我在這裏錯過了一些小東西。 – Tander

+0

好的,沒關係。我發現了錯誤。這是我的AppComponent類中缺少的方法。謝謝您的幫助! – Tander

+1

@Tander您應該將此方法添加到您的'ApplicationComponent'中。你是否複製了一些教程的代碼? – DeKaNszn