I’m trying to enable minification on Android but I...
# serialization
c
I’m trying to enable minification on Android but I’m still getting
Serializer for class 'b' is not found
at runtime. I’ve added the ProGuard rules from here, substituting my app package name: https://github.com/Kotlin/kotlinx.serialization#android Is there any other step? Or something I’m missing?
I’ve been using Kotlin serialization plugin v
1.5.31
. I tried upgrading to
1.6.0-RC
, this made no difference
Kotlin version
1.5.21
I have not otherwise made any configuration to proguard besides the default Android Studio provides
I have no custom serializers
e
if you use the reified extension functions
StringFormat.encodeToString(value)
,
StringFormat.decodeFromString()
, similar on
BinaryFormat
,
SerializersModule { polymorphic(..) { subclass(kclass) } }
they use reflection to find the serializer. if you instead use the member functions
StringFormat.encodeToString(serializer, value)
,
StringFormat.decodeFromString(serializer)
, etc. and pass in the serializer statically (e.g.
MyType.serializer()
, not
MyType::class.serializer()
) then no reflection is used, and Proguard should keep everything necessary because it's all referenced directly
c
Oof, I use
encodeToString(value)
/ `decodeFromString(value)`extensively
Ok let me test out some changes…
Thanks for responding
e
in theory the reified helpers should not require reflection, but currently that's how it works until further compiler changes are made https://github.com/Kotlin/kotlinx.serialization/issues/1348
r
It might be because your serialization plugin and kotlin versions don't match.
c
I did not realize they were tracked the same
@russhwolf I did a quick check to see if matching the versions made a difference; it did not for me