我正在升级我的项目以使用 Kotlin 2.0.0 和相同版本的 Compose 编译器。我运行了 AGP 升级助手,将 Gradle 版本升级到 8.7,将
com.android.application
插件升级到 8.5 版本。我的build.gradle.kts
文件如下:
项目
build.gradle.kts
:
plugins {
id("com.android.application") version "8.5.0" apply false
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
id("com.google.dagger.hilt.android") version "2.51" apply false
id("com.google.devtools.ksp") version "2.0.0-1.0.22" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10" apply false
}
应用程序
build.gradle.kts
:
import com.google.protobuf.gradle.id
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("com.google.protobuf") version "0.9.4"
id("com.google.dagger.hilt.android")
id("com.google.devtools.ksp")
id("kotlinx-serialization")
}
android {}
composeCompiler {
enableStrongSkippingMode = true
reportsDestination = layout.buildDirectory.dir("compose_compiler")
stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}
dependencies {
// Other dependencies omitted
implementation("com.google.protobuf:protobuf-javalite:3.24.1")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.24.1"
}
generateProtoTasks {
all().configureEach {
builtins {
id("java") {
option("lite")
}
}
}
}
}
Gradle 任务
:app:kspDebugKotlin
失败并出现以下错误:
e: [ksp] InjectProcessingStep was unable to process 'UserPreferencesRepositoryImpl(androidx.datastore.core.DataStore<error.NonExistentClass>)' because 'error.NonExistentClass' could not be resolved.
Dependency trace:
=> element (CLASS): com.codejockie.wani.wk.data.repository.UserPreferencesRepositoryImpl
=> element (CONSTRUCTOR): UserPreferencesRepositoryImpl(androidx.datastore.core.DataStore<error.NonExistentClass>)
=> type (EXECUTABLE constructor): (androidx.datastore.core.DataStore<error.NonExistentClass>)void
=> type (DECLARED parameter type): androidx.datastore.core.DataStore<error.NonExistentClass>
=> type (ERROR type argument): error.NonExistentClass
If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: [ksp] ModuleProcessingStep was unable to process 'com.codejockie.wani.di.DataStoreModule' because 'error.NonExistentClass' could not be resolved.
可能出了什么问题?
我在网上搜索了几个小时后才解决了这个问题。我遇到了一个 GitHub 问题,其中有人提到了与我类似的问题。 该修复需要将以下代码片段添加到我的应用程序模块
build.gradle.kts
文件中。
androidComponents {
onVariants(selector().all()) { variant ->
afterEvaluate {
val capName = variant.name.capitalized()
tasks.getByName<KotlinCompile>("ksp${capName}Kotlin") {
setSource(tasks.getByName("generate${capName}Proto").outputs)
}
}
}
}
这是我引用的 GitHub 问题的链接。