gpt4 book ai didi

android - 在android中实现hilt库时gradle出错

转载 作者:行者123 更新时间:2023-12-04 12:09:29 24 4
gpt4 key购买 nike

我正在尝试在 android studio 版本 2020.1.1 Canary 1 中实现刀柄但我在gradle中得到这个错误

Unable to find method ''void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)''
'void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
这是 build.gradle水平项目
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.0.0-beta07'
kotlin_version = "1.4.32"
lifecycle_version = "2.3.1"
hilt_version = '2.35'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle级别模块
plugins {
id 'com.android.application'
id 'kotlin-android'
id("kotlin-kapt")
id("kotlin-parcelize")
id("dagger.hilt.android.plugin")
}

android {

compileSdk 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.android.gymexercisestracker"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
dataBinding true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}


}

dependencies {

implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha08'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"

// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'

//Android Room
implementation "androidx.room:room-runtime:2.4.0-alpha02"
implementation "androidx.room:room-ktx:2.4.0-alpha02"
kapt "androidx.room:room-compiler:2.4.0-alpha02"


implementation("com.google.dagger:hilt-android:$hilt_version")
kapt("com.google.dagger:hilt-android-compiler:$hilt_version")


}
gradle-wrapper.properties
#Wed May 26 14:56:53 EET 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

我试图清除缓存并重新启动,但同样的问题

最佳答案

我有同样的问题,来自 GitHub 的答案为我解决了这个问题。关联
dagger github
编辑您的项目级别 build.gradle

   buildscript {

repositories {
google()
mavenCentral()
}

dependencies {
classpath ClassPaths.gradlePlugin
classpath ClassPaths.kotlinPlugin
classpath Libs.Hilt.gradlePlugin
classpath 'com.android.tools.build:gradle:7.1.0-alpha01'
}
}
buildscript {

repositories {
google()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
content {
includeModule("com.google.dagger", "hilt-android-gradle-plugin")
}
}
}

dependencies {
classpath ClassPaths.gradlePlugin
classpath ClassPaths.kotlinPlugin
classpath "com.google.dagger:hilt-android-gradle-plugin:HEAD-SNAPSHOT"
classpath 'com.android.tools.build:gradle:7.1.0-alpha01'

}
}

关于android - 在android中实现hilt库时gradle出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67705710/

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