我将 Dagger2 与 java 一起使用,但出现“无法解析我的应用程序中的符号 DaggerApplicationComponent 错误”。似乎依赖性有问题。任何帮助将非常感激。 我的完整代码在这里- https://github.com/rohitku860/AndroidMvpDagger2
这是我的带有依赖项的应用程序:
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
}
最佳答案
此错误与您的 Gradle 配置无关。
DaggerApplicationComponent
是 Dagger 为您定义的 ApplicationComponent
接口(interface)生成的类。如果在代码生成期间出现任何错误(例如缺少 @Provides
方法),Dagger 将不会生成 DaggerApplicationComponent
,您将收到此错误。
您需要做的是阅读 AndroidStudio 中的整个错误输出并尝试理解 Dagger 失败的原因。
当项目文件中缺少一些导入语句时,我还遇到了一个非常讨厌的行为。在这些情况下,Dagger 会失败,但不会告诉您确切的问题所在,您需要自己寻找。
如果您需要进一步的帮助 - 将构建错误输出附加到问题。
关于android - 无法解析符号 DaggerApplicationComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49602150/