Kotlin 中未解决的引用 DaggerAppComponent

问题描述 投票:0回答:1

无法解析以下代码中的引用 DaggerAppComponent 和 CoreInjectHelper:

 DaggerAppComponent.builder()
            .coreComponent(CoreInjectHelper.provideCoreComponent(this))
            .build().inject(this)

下面是Project级别的build.gradle文件:

  dependencies {
        classpath "com.android.tools.build:gradle:7.1.2"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.3.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.1"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0"
        classpath "com.google.gms:google-services:4.3.5"
        classpath "com.appdynamics:appdynamics-gradle-plugin:4.4.3.928"
    }


plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'androidx.navigation.safeargs' version '2.4.2' apply false
}

下面是app级的build.gradle文件:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-parcelize'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs.kotlin'
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
    implementation("androidx.annotation:annotation:1.1.0")
    // To use the Java-compatible @Experimental API annotation
    implementation("androidx.annotation:annotation-experimental:1.1.0")
    implementation "com.google.dagger:dagger:2.27"
    kapt "com.google.dagger:dagger-compiler:2.27"

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

请建议我如何为上述代码导入 DaggerAppComponent 和 CoreInjectHelper。

android kotlin dependency-injection plugins dagger
1个回答
0
投票

正确的依赖关系是:

实现'com.google.dagger:dagger:2.x'

annotationProcessor 'com.google.dagger:dagger-compiler:2.x'

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