未解决的错误参考

未解决的错误参考

本文介绍了Android Kotlin:未解决的错误参考:DaggerAppComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天已经将Kotlin插件安装到了带有Dagger 2的现有项目中.在安装Kotlin之前,我对Dagger没有任何问题.但是,现在编译器抱怨:

I have installed Kotlin plugin today into an existing project with Dagger 2. Before Kotlin was installed I had no issues with Dagger. However, now the compiler complains :

Error:(5, 32) Unresolved reference: DaggerAppComponent
Error:Execution failed for task ':app:compileDebugKotlinAfterJava'.
> Compilation error. See log for more details
Error:(12, 21) Unresolved reference: DaggerAppComponent

项目gradle:

ext.kotlin_version = '1.1.1'

    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

模块gradle:

kapt {
    generateStubs = true
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    testCompile 'junit:junit:4.12'

    compile 'com.google.dagger:dagger:2.7'
    kapt 'com.google.dagger:dagger-compiler:2.7'

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"


}

DaggerAppComponent文件是自动生成的,因此我对为什么抛出未解决的参考错误感到困惑.

The DaggerAppComponent file IS auto generated, so I'm confused as to why there is an un resolved reference error thrown.

推荐答案

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

在您的依赖项中:

implementation "com.google.dagger:dagger:2.x"
implementation "com.google.dagger:dagger-android:2.x"
implementation "com.google.dagger:dagger-android-support:2.x"
kapt "com.google.dagger:dagger-compiler:2.x"
kapt "com.google.dagger:dagger-android-processor:2.x"

这篇关于Android Kotlin:未解决的错误参考:DaggerAppComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:22