使用 android gradle 插件版本 7.0.0-alpha15 时无法使用 kotlin-gradle-dsl 脚本
Cannot use kotlin-gradle-dsl scripts while using android gradle plugin version 7.0.0-alpha15
我将我的 Android Studio Canary 更新到版本 2020 3.1 Canary 15
,这也要求我将我的 AGP 更新到版本 7.0.0-alpha15
。我正在使用 kotlin-gradle-dsl
作为我的 gradle 构建文件,这些文件现在无法使用 Unresolved reference
.
构建
请注意,gradle 在更新到版本 7.0.0-alpha15
之前已成功构建。
我的应用等级build.gradle.kts
如下:
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
val apiKey: String = gradleLocalProperties(rootDir).getProperty("API_KEY")
android {
compileSdkVersion(30)
buildToolsVersion("30.0.3")
defaultConfig {
applicationId("com.training.flicker")
minSdkVersion(21)
targetSdkVersion(30)
versionCode(1)
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
buildConfigField("String", "API_KEY", apiKey)
}
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
composeOptions.kotlinCompilerExtensionVersion = Version.compose
}
dependencies {
implementation(Android.coreKtx)
implementation(Android.appCompat)
implementation(Android.material)
implementation(Retrofit.retrofit)
implementation(Retrofit.convertorGson)
implementation(Hilt.hiltAndroid)
kapt(Hilt.hiltKapt)
implementation(Compose.material)
implementation(Compose.tooling)
implementation(Compose.ui)
implementation(Compose.activity)
implementation(Coroutines.android)
implementation(Arch.runtime)
implementation(Arch.viewModel)
implementation(Arch.liveData)
testImplementation(Test.junit)
androidTestImplementation(Test.androidJunit)
androidTestImplementation(Test.espressoCore)
androidTestImplementation(Test.composeUi)
}
这是我遇到的错误
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <T : Any, C : NamedDomainObjectContainer<TypeVariable(T)>> TypeVariable(C).invoke(configuration: Action<NamedDomainObjectContainerScope<TypeVariable(T)>>): TypeVariable(C) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(x: Any?): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(vararg xs: Any?): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <V> Callable<TypeVariable(V)>.invoke(): TypeVariable(V) defined in org.gradle.kotlin.dsl
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
...
实际上 AGP
有一个 issue,因此 gradle 崩溃了。
此问题已在 AGP
的下一版本中修复。目前我在 android studio Arctic Fox 中使用 AGP 7.0.0
和匕首刀柄版本 2.37
,没有任何问题。
// project level build.gradle
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
...
// app level build.gradle
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
...
我将我的 Android Studio Canary 更新到版本 2020 3.1 Canary 15
,这也要求我将我的 AGP 更新到版本 7.0.0-alpha15
。我正在使用 kotlin-gradle-dsl
作为我的 gradle 构建文件,这些文件现在无法使用 Unresolved reference
.
请注意,gradle 在更新到版本 7.0.0-alpha15
之前已成功构建。
我的应用等级build.gradle.kts
如下:
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
val apiKey: String = gradleLocalProperties(rootDir).getProperty("API_KEY")
android {
compileSdkVersion(30)
buildToolsVersion("30.0.3")
defaultConfig {
applicationId("com.training.flicker")
minSdkVersion(21)
targetSdkVersion(30)
versionCode(1)
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
buildConfigField("String", "API_KEY", apiKey)
}
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
composeOptions.kotlinCompilerExtensionVersion = Version.compose
}
dependencies {
implementation(Android.coreKtx)
implementation(Android.appCompat)
implementation(Android.material)
implementation(Retrofit.retrofit)
implementation(Retrofit.convertorGson)
implementation(Hilt.hiltAndroid)
kapt(Hilt.hiltKapt)
implementation(Compose.material)
implementation(Compose.tooling)
implementation(Compose.ui)
implementation(Compose.activity)
implementation(Coroutines.android)
implementation(Arch.runtime)
implementation(Arch.viewModel)
implementation(Arch.liveData)
testImplementation(Test.junit)
androidTestImplementation(Test.androidJunit)
androidTestImplementation(Test.espressoCore)
androidTestImplementation(Test.composeUi)
}
这是我遇到的错误
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <T : Any, C : NamedDomainObjectContainer<TypeVariable(T)>> TypeVariable(C).invoke(configuration: Action<NamedDomainObjectContainerScope<TypeVariable(T)>>): TypeVariable(C) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(x: Any?): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <T> Closure<TypeVariable(T)>.invoke(vararg xs: Any?): TypeVariable(T) defined in org.gradle.kotlin.dsl
public operator fun <V> Callable<TypeVariable(V)>.invoke(): TypeVariable(V) defined in org.gradle.kotlin.dsl
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
...
实际上 AGP
有一个 issue,因此 gradle 崩溃了。
此问题已在 AGP
的下一版本中修复。目前我在 android studio Arctic Fox 中使用 AGP 7.0.0
和匕首刀柄版本 2.37
,没有任何问题。
// project level build.gradle
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
...
// app level build.gradle
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
...