Hey, everyone, I am a little stuck trying to updat...
# android
s
Hey, everyone, I am a little stuck trying to update an android jetpack compose app from a few years ago. It is using KSerializer for a custom serializer, and that wants to include compose-preview-renderer:0.0.1-alpha01, but that causes a duplicate class found error with kotlin-stdlib-1.9.0. What would I need to do to resolve this duplicate class error?
s
Can you post the error log? Was the Kotlin Serialisation library also updated?
s
Caused by: java.lang.RuntimeException: Duplicate class _COROUTINE.ArtificialStackFrames found in modules compose-preview-renderer-0.0.1-alpha01 (com.android.tools.composecompose preview renderer0.0.1-alpha01) and kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinxkotlinx coroutines core jvm1.7.3)
s
Can you provide the full stacktrace of the exception? I understand that the issue is the conflict, but serialization library does not include anything compose related to trying to understand where
com.android.tools.compose:compose-preview-renderer:0.0.1-alpha01
is being picked up from.
s
appdexBuilderDebug • org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable • java.lang.RuntimeException: Duplicate class _COROUTINE.ArtificialStackFrames found in modules compose-preview-renderer-0.0.1-alpha01 (com.android.tools.composecompose preview renderer0.0.1-alpha01) and kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinxkotlinx coroutines core jvm1.7.3) • org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction • com.android.builder.merge.DuplicateRelativeFileException: 2 files found with path 'kotlin/reflect/reflect.kotlin_builtins'. • Duplicate class found
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Caused by: java.lang.RuntimeException: Duplicate class _COROUTINE.ArtificialStackFrames found in modules compose-preview-renderer-0.0.1-alpha01 (com.android.tools.composecompose preview renderer0.0.1-alpha01) and kotlinx-coroutines-core-jvm-1.7.3 (org.jetbrains.kotlinxkotlinx coroutines core jvm1.7.3)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
Caused by: com.android.builder.merge.DuplicateRelativeFileException: 2 files found with path 'kotlin/reflect/reflect.kotlin_builtins'.
dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) implementation(platform(libs.androidx.compose.bom)) implementation(libs.androidx.ui) implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.material3) implementation(libs.androidx.appcompat) implementation(libs.androidx.constraintlayout.compose) implementation(libs.compose.preview.renderer) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(platform(libs.androidx.compose.bom)) androidTestImplementation(libs.androidx.ui.test.junit4) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) }
I'm using KSerializer, and android studio suggests adding this dependency: implementation(libs.compose.preview.renderer) and when it does it also adds this import kotlinx.serialization.KSerializer
Once that happens, the build compiles, but it gives the errors above when I try to run the app.
Is KSerializer deprecated now, or should it be coming from a different dependency instead of the libs.compose.preview.renderer one?
s
s
Thank you! I ended up with this: Project build.gradle.kts:
Copy code
plugins {
    ...    
    kotlin("plugin.serialization") version "1.9.0" apply false
}
Module build.gradle.kts:
Copy code
plugins {
    ...
    kotlin("plugin.serialization")
}
...
dependencies {
    ...
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
}
It all compiles and runs now, thank you for your help, Saud!
🎉 1
239 Views