gpt4 book ai didi

android - 错误 : Unresolved reference: DaggerAppComponent

转载 作者:行者123 更新时间:2023-12-02 13:14:17 29 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Unresolved reference DaggerApplicationComponent

(14 个回答)


4年前关闭。




我已经面临这个问题3个小时了。我找不到任何合乎逻辑的理由来解释正在发生的事情。问题是,只有当我使用生成的 Dagger类,及之后 GradleBuild对这些类的每个引用都变成了红色,我得到了错误:

Error: Unresolved reference: DaggerAppComponent



但是,如果我注释掉 App 中的每一行类引用任何这些生成的 Dagger类。构建过程成功完成。我试着做干净/重建/制作项目。但它不起作用。
关于我的环境的一些信息: Build.gradle :
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
defaultConfig {
applicationId "xxxxx"
minSdkVersion 19
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'
}
}
dataBinding {
enabled = true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "android.arch.lifecycle:extensions:1.1.0"
implementation "android.arch.lifecycle:viewmodel:1.1.0"
implementation "android.arch.lifecycle:livedata:1.1.0"
implementation "android.arch.persistence.room:runtime:1.0.0"
implementation "android.arch.lifecycle:runtime:1.1.0"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'


kapt "android.arch.lifecycle:compiler:1.1.0"
kapt "android.arch.persistence.room:compiler:1.0.0"

kapt "com.google.dagger:dagger-compiler:2.8"
compile "com.google.dagger:dagger:2.8"
compile "com.google.dagger:dagger-android:2.8"

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'
}

Kotlin 版本: ext.kotlin_version = '1.1.51'Android Studio 版本: 3.0.1 Build.Gradle 中的依赖项部分项目文件(不是应用程序模块):
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
App类(class):
class App:Application() {
private val component:AppComponent by lazy {
DaggerAppComponent.builder()
.build()
}
override fun onCreate() {
super.onCreate()
component.inject(this)
}
}

如果有人能找出问题所在,将不胜感激。
附言我还在学习 Dagger2我是 Kotlin 的新手和 Native总体发展。我来自 C#Xamarin背景。

最佳答案

您似乎缺少 kapt Gradle 插件的应用程序,如 kapt documentation 中所述。 .基本上,在现有插件之后添加:

apply plugin: 'kotlin-kapt'

(如果这有帮助,这个问题应该被标记为 this one 的副本)

关于android - 错误 : Unresolved reference: DaggerAppComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49284027/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com