Serializer not generated in test fixtures (`testFixtures`)
Describe the bug
I have enabled test fixures in my Android project, which is working.
However, when I try to create a class annotated with @Serializable in the testFixtures source set, the serializer doesn't seem to be available in my test:
kotlinx.serialization.SerializationException: Serializer for class 'MyClass' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:90)
at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:299)
at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
at androidx.navigation.NavDestinationBuilder.<init>(NavDestinationBuilder.kt:91)
...
When I place the same class in the test source set, the serializer is available in my test.
To Reproduce
# gradle.properties
android.experimental.enableTestFixtures=true
android.experimental.enableTestFixturesKotlinSupport=true
// project level build.gradle.kts
plugins {
alias(libs.plugins.kotlin.serialization)
}
dependencies {
testImplementation(libs.kotlinx.serialization.json)
testFixturesImplementation(libs.kotlinx.serialization.json)
}
Expected behavior
When I move the @Serializable class from the test source set to testFixtures, the serializer is still available in my test.
Environment
- Kotlin version: 2.1.10
- Library version: 1.8.0
- Kotlin platforms: JVM
- Gradle version: 8.10.2
- IDE version: N/A
Have you tried to report this issue to the Android Gradle plugin? I'm afraid it may be a problem on their side.
The same problem happens to me
also reproduce this on our project. Do you have a workaround for this case?
That's an issue on the Android Gradle plugin side (it does not apply Kotlin compiler plugins to test-fixtures source set), and the issue seems to be fixed in AGP 9.0 (I checked 9.0.0-alpha14 and all works fine).