FunkyMuse

    FunkyMuse

    9 months ago
    Hey guys, is it possible to use kotlinx serialization on Android without providing proguard rules in release mode? Something that moshi has with codegen
    e

    ephemient

    9 months ago
    as long as you avoid functions that look up the serializer at runtime (e.g.
    inline fun <reified T> encodeToString(value: T)
    ) and stick to
    encodeToString(MyClass.serializer(), value)
    it should already work without ProGuard rules
    if everything is referenced statically in code, ProGuard can't remove them and it doesn't matter if they're renamed
    ideally the reified helpers wouldn't rely on reflection, but that requires further compiler work. https://github.com/Kotlin/kotlinx.serialization/issues/1348
    FunkyMuse

    FunkyMuse

    9 months ago
    @Serializable
    data class MetaModel(
        @SerialName("current_page")
        val currentPage: Int?,
        @SerialName("last_page")
        val lastPage: Int?,
        @SerialName("per_page")
        val perPage: String?,
        @SerialName("total")
        val total: Int?
    )
    I do it like this all the time, all my classes are annotated with serial names and serializable, but still it fails without proguard rule, is there a way to somehow circumvent adding proguard rules for this way?
    e

    ephemient

    9 months ago
    what fails, exactly?
    FunkyMuse

    FunkyMuse

    9 months ago
    Unable to create converter for class, works perfectly without proguard tho
    e

    ephemient

    9 months ago
    how are you creating the converter?
    if you're writing
    MetaModel.serializer()
    it should work. if you're relying on anything doing reflection to obtain the serializer, you will need proguard rules.
    FunkyMuse

    FunkyMuse

    9 months ago
    I'm using retrofit and using Jake's converter, basically I'm not adding anything anywhere, should i be? Sorry for the noob questions, I'm still exploring how this library works
    e

    ephemient

    9 months ago
    that relies on
    serializersModule.serializer(type)
    to get the serializer, so it's effectively reflecting at runtime
    there's not much to it though, you could easily copy and fork it to have static references to your own types, or come up with your own way to register serializers that doesn't use reflection