I am upgrading my project to use Kotlin 2.0.0 with the Compose Compiler of the same version. I ran the AGP upgrade assistant which upgraded the Gradle version to 8.7 and the com.android.application
plugin to version 8.5. My build.gradle.kts
files are as follows:
Project 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
}
App 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")
}
}
}
}
}
The Gradle task :app:kspDebugKotlin
is failing with the following error:
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.
What could be wrong?
I was able to solve this issue after several hours of searching the internet. I came across a GitHub issue where someone mentioned a similar issue to mine. The fix required adding the below snippet to my app module build.gradle.kts
file.
androidComponents {
onVariants(selector().all()) { variant ->
afterEvaluate {
val capName = variant.name.capitalized()
tasks.getByName<KotlinCompile>("ksp${capName}Kotlin") {
setSource(tasks.getByName("generate${capName}Proto").outputs)
}
}
}
}
Here is the link to the GitHub issue I referenced.