gpt4 book ai didi

java - 刀柄不同步

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

我知道之前有人问过这个问题,但我看到的解决方案似乎都不适合我。我是 hilt 的新手,我正在尝试在 android studio 中使用 java 时学习它。我去了 android 文档并复制/粘贴了它们提供的依赖项、插件和类路径。但是当我尝试同步项目时失败并说:

org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to org.codehaus.groovy.ast.expr.ArgumentListExpression
org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to org.codehaus.groovy.ast.expr.ArgumentListExpression

这是我的顶级构建 gradle:

       // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这是我的应用级构建等级:

    plugins {
id 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

}

android {
compileSdkVersion 30
buildToolsVersion "29.0.3"

buildFeatures {
dataBinding = true
}

defaultConfig {
applicationId "com.example.blogs"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation "com.github.bumptech.glide:glide:4.12.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
implementation "com.google.code.gson:gson:2.8.6"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.7.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.1"
implementation "androidx.lifecycle:lifecycle-livedata:2.3.1"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "com.google.android.material:material:1.3.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
testImplementation "junit:junit:4.+"
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-compiler:2.28-alpha"
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

我改变了:

plugins {
id 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

}

到:

plugins {
id 'com.android.application'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

}

但这失败并说:

A problem occurred evaluating project ':app'.
> Could not find method kapt() for arguments [com.google.dagger:hilt-compiler:2.28-alpha] on
object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

然后我看到一个解决方案,它说在“com.google.dagger:hilt-compiler:2.28-alpha”依赖项的依赖项中使用 annotationProcessor 而不是 kapt。我得到:

 A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> Configuration with name 'kapt' not found.
> The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android-compiler dependency was found.

当我使用实现时,同样的事情发生了。

请帮我解决这个问题,谢谢。

最佳答案

好的。我想通了。

我需要改变:

    kapt "com.google.dagger:hilt-compiler:2.28-alpha"

到:

annotationProcessor "com.google.dagger:hilt-android-compiler:2.28-alpha"

第一个是我从此处的 android 文档中获得的 https://developer.android.com/training/dependency-injection/hilt-android#java

我在这里找到了这个解决方案 https://github.com/google/dagger/issues/2086 .

关于java - 刀柄不同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68012091/

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