Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin Proguard rule for enum?

Hi there can somebody please advise me if there are any specific rules required for Kotlin class with enum? Simple example as

data class Passenger(
    var type: Type?,
    var id: Int,
    var age: Int
) {

companion object {

    const val AGE_NOT_SET = -1
}

enum class Type {
    ADULT, CHILD, INFANT
}

constructor() : this(null, 0, 0)
}

If object get initialized to Passenger(CHILD, 123456, 4) converted to Json and later on parsed back to POJO it will result in Passenger(null, 0,0)

I do have

-keepclassmembers,allowoptimization enum * { 
    public static **[] values(); public static ** valueOf(java.lang.String); 
}

in my proguard rules that works for enum in Java but for some reason it fails for Kotlin

like image 454
peter_budo Avatar asked Sep 07 '17 18:09

peter_budo


1 Answers

It looks like you need to keep all public enum class members to avoid this error. This worked for me:

-keepclassmembers enum * {
    public *;
}
like image 192
Miguel A. Gabriel Avatar answered Sep 25 '22 16:09

Miguel A. Gabriel