无法解析符号DaggerApplicationComponent

问题描述 投票:5回答:2

我在Java中使用Dagger2,并且“无法在我的应用程序中解析符号DaggerApplicationComponent错误”。似乎依赖项存在问题。任何帮助将非常感激。我的完整代码在这里 - https://github.com/rohitku860/AndroidMvpDagger2

这是我的app gradle with dependencies:

 apply plugin: 'com.android.application'
    android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.android.androidmvpdagger2"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
       }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso- 
    core:3.0.1'
    implementation 'com.google.dagger:dagger:2.13'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
    implementation 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

}

这是项目一:

        buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.0'
        }
    }

        allprojects {
        repositories {
            google()
            jcenter()
        }
    }



           task clean(type: Delete) {
            delete rootProject.buildDir
        }
android dagger-2
2个回答
5
投票

此错误与Gradle配置无关。

DaggerApplicationComponent是Dagger为您定义的ApplicationComponent界面生成的类。如果在代码生成过程中出现任何错误(例如缺少@Provides方法),Dagger将不会生成DaggerApplicationComponent,您将收到此错误。

您需要做的是阅读Android Studio中的整个错误输出,并尝试理解Dagger失败的原因。

当项目文件中缺少某些import语句时,我也遇到了非常讨厌的行为。在这些情况下,Dagger会失败,但不会告诉你究竟是什么问题,你需要自己寻找它。

如果您需要进一步的帮助 - 将构建错误输出附加到问题。


1
投票

有一个简单的解决方案,只需重建项目,它可能会工作

© www.soinside.com 2019 - 2024. All rights reserved.