Hi folks, I have a doubt here: why Kotlin Serializ...
# serialization
t
Hi folks, I have a doubt here: why Kotlin Serialization plugin doesn't generate a proguard file with packages/classes to keep? I know this is out of library/plugin scope, but the plugin walk through classes looking for @Serializable annotation. It would be nice reusing this walk phase to "write" to a file or console packages/classes to keep. I think adding something like that will not be weight because can run in parallel with search annotation phase. If it is totally out of scope, how can I to create a compiler plugin to do something like that?
m
You can use kotlinx.serialization without reflection
Why would you want to keep classes?
t
No classes at all. I mean keep code generated by serialization plugin. We are applying recommended keep rules but we a getting serialization error in release apps with our multi-module app.
s
There is no escape for reflection while using it with Retrofit. https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter I'm almost sure that for
Ktor
this is the case as well.
👀 1
m
I see. Well if proguard is required, there is a section in the README: https://github.com/kotlin/kotlinx.serialization#android
@Thiago can you share the error you're getting?
t
Yes, we recently changed from old way to the new that are using proguard if. After migration we are receiving:
java.lang.IllegalArgumentException: Unable to create converter for class java.lang.Object
in @Serializable classes that was working with previous proguard setup.
We did rollback and we are investigating what is happening. In a multi-module app it became a mess to maintain 😅
m
In general there should be no need to add all
@Serializable
classes explicitely or list them with a plugin. The proguard rules should allow to do something like:
Copy code
keep @kotlinx.serialization.Serializable class **
So that it can match all
@Serializable
classes
But then your error might be something completely different... Bisect on the proguard file?
t
Yes, we were using it.
We did just a migration from https://github.com/Kotlin/kotlinx.serialization/tree/v1.3.0#android to https://github.com/Kotlin/kotlinx.serialization/tree/v1.3.2#android The second approach has broken here our serialization. We are investigating what we forgot to update
e
if you write your own retrofit converter that statically references all your serializers, it'll work without reflection
f
@ephemient do you have any code sample that adds all of them?
e
"all" of them requires some sort of reflection, either runtime or compile-time
228 Views