8
votes

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

3
any luck finding the solution?ShahrozKhan91

3 Answers

4
votes

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

-keepclassmembers enum * {
    public *;
}
0
votes
-keep class Type {
    public *;
}

This works for me. If it doesn't work for you, try moving the enum to a separate file.

0
votes

You can try by adding the following line inside your 'proguard-rules.pro' file. Make sure to replace the 'package.name' part with your own package name.

-keepnames class package.name.Type