Плагин Hilt Android Gradle применяется, но нет com.google.найден кинжал: зависимость от эфеса-Android

#android #gradle #gradle-kotlin-dsl #dagger-hilt

#Android #gradle #gradle-kotlin-dsl #кинжал-эфес

Вопрос:

я получаю эту ошибку синхронизации gradle — плагин Hilt Android Gradle применяется, но нет com.google.найден кинжал: зависимость от эфеса-Android. может кто-нибудь помочь, пожалуйста? 🙂

я использую kotlin dsl, у меня есть libs.kt в buildSrc

buildSrc — build.gradle.kts:

 plugins {
    `kotlin-dsl`
}

repositories {
    jcenter()
}
 

libs.kt в buildSrc

 object libs {
        object hilt {
            private const val dagger_hilt_version = "2.30.1-alpha"
            private const val jetpack_hilt_version = "1.0.0-alpha02"

            const val gradlePlugin = "com.google.dagger:hilt-android-gradle-plugin:$dagger_hilt_version"
            const val android = "com.google.dagger:hilt-android:$dagger_hilt_version"
            const val android_compiler = "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"

            const val jetpack_viewmodel = "androidx.hilt:hilt-lifecycle-viewmodel:$jetpack_hilt_version"
            const val jetpack_compiler = "androidx.hilt:hilt-compiler:$jetpack_hilt_version"
        }

        /* more objects   more constants */

    }
 

мое приложение build.gradle.kts выглядит так:

 plugins {
    id("com.android.application")
    id("kotlin-android")
    id("kotlin-kapt")
    id("dagger.hilt.android.plugin")
    id("androidx.navigation.safeargs.kotlin")
    id("com.google.firebase.crashlytics")
    id("com.google.gms.google-services")

    id("com.google.firebase.firebase-perf")
}

android {
    useLibrary("org.apache.http.legacy")

    compileSdkVersion = "30"

    dependenciesInfo {
        includeInApk = true
        includeInBundle = true
    }

    buildFeatures {
        dataBinding = true
        compose = true
    }

    defaultConfig {   
        vectorDrawables.useSupportLibrary = true

        applicationId = "aa.bb.cc"

        targetSdkVersion(30)
        minSdkVersion(21)

        versionCode = 1
        versionName = "1.0.0"
    }

    signingConfigs {
        register("configReleaseCZ").configure {
            /*hidden part*/
        }
    }

    bundle {
        language {
            enableSplit = false
        }
    }

    buildTypes {
        named("debug").configure {
            isDebuggable = true
            extra.set("enableCrashlytics", false)
        }
        named("release").configure {
            isShrinkResources = true
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            isDebuggable = false
            extra.set("enableCrashlytics", true)
            signingConfig = signingConfigs.getByName("configReleaseCZ")
        }
    }

    composeOptions {
        kotlinCompilerVersion = libs.kotlin.version
        kotlinCompilerExtensionVersion = libs.compose.version
    }

    lintOptions {
        isAbortOnError = false
    }
}

kapt {
    correctErrorTypes = true
}

dependencies {
    //implementation("com.google.dagger:hilt-android:2.30.1-alpha") 
    //kapt ("com.google.dagger:hilt-android-compiler:2.30.1-alpha") //this doesnt work wither

    implementation(libs.hilt.android)
    kapt(libs.hilt.android_compiler)

    implementation(libs.hilt.jetpack_viewmodel)
    kapt(libs.hilt.jetpack_compiler)

    /* many more dependencies */

}
kapt {
    correctErrorTypes = true
}
 

мой проект build.gradle.kts:

 buildscript {
    repositories {
        google()
        mavenCentral()
        maven(url = "https://jitpack.io")
        maven(url = "https://repo1.maven.org/maven2/")
        maven(url = "https://plugins.gradle.org/m2/")
        maven(url = "https://github.com/userxpro/userx/raw/maven/")
        maven(url = "https://dl.bintray.com/kotlin/kotlin-eap/")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx/")
        maven(url = "https://kotlin.bintray.com/kotlinx")
        maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
        maven(url = "http://storage.googleapis.com/r8-releases/raw")
        gradlePluginPortal()
    }

    dependencies {
        classpath(libs.r8)

        classpath(libs.androidGradlePlugin)
        classpath(libs.kotlin.gradlePlugin)
        classpath(libs.hilt.gradlePlugin)

        classpath("com.google.gms:google-services:4.3.4")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.4.1")
        classpath("com.google.firebase:perf-plugin:1.3.4")
    }
}

subprojects {
    repositories {
        google()
        mavenCentral()
        maven(url = "https://jitpack.io")
        maven(url = "https://repo1.maven.org/maven2/")
        maven(url = "https://plugins.gradle.org/m2/")
        maven(url = "https://dl.bintray.com/kotlin/kotlin-eap/")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx/")
        maven(url = "https://kotlin.bintray.com/kotlinx")
        maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
        maven(url = "https://github.com/userxpro/userx/raw/maven/")
        jcenter()
    }

    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions {
            // Treat all Kotlin warnings as errors
            //useIR = true

            //allWarningsAsErrors = true

            freeCompilerArgs  = "-Xopt-in=kotlin.RequiresOptIn"

            // Enable experimental coroutines APIs, including Flow
            freeCompilerArgs  = "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
            freeCompilerArgs  = "-Xopt-in=kotlinx.coroutines.FlowPreview"
            freeCompilerArgs  = "-Xopt-in=kotlin.Experimental"
            freeCompilerArgs  = "-Xallow-jvm-ir-dependencies"

            // Set JVM target to 1.8
            jvmTarget = "1.8"
        }
    }
}
 

Комментарии:

1. кстати, в других модулях плагин работает

Ответ №1:

удалить id("dagger.hilt.android.plugin")

синхронизация gradle

Добавить id("dagger.hilt.android.plugin")

Комментарии:

1. Перепробовал все. Это единственное решение, которое сработало. Не могли бы вы сказать мне, почему это сработало?

2. @RahulMishra у вас есть какая-то ошибка в зависимостях перед зависимостью от эфеса.

Ответ №2:

В моем случае проблема была связана с несовместимой версией библиотеки / плагина Hilt и плагина Android Gradle, которая возникла после того, как я обновился до плагина Android Gradle 7.0.1 .

Я обновил Hilt из 2.35 -> 2.38.1 , и приложение снова скомпилировалось.

Комментарии:

1. И какова ваша версия оболочки gradle? ( distributionUrl )

2. Привет, @Dr.jacky, с тех пор я перешел на 7.0.2 . Оболочка Gradle: distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip .

3. По-прежнему не работает; Unresolved reference: versionCode , Unresolved reference: versionName , The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.

4. @Dr.jacky похоже, что это другая ошибка в вашей конфигурации Gradle. versionCode и versionName это не должно быть затронуто. Возможно, отсутствует фигурная скобка ?.

5. Да. Это было другое дело. У меня были такие поля в других модулях, которые app . Новый gradle (или AS) их не допускает.