Я обновляю свой проект для использования 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, на которую я ссылался.