I am writing an application with Kotlin and Retrofit 2. As I use proguard, I follow the rules here:
Besides I also need to proguard my models too, as stated in https://stackoverflow.com/a/41136007/3286489
It works fine if I have my models in a package, and I have -keep class com.elyeproj.wikisearchcount.model.** { *; }
package com.elyeproj.wikisearchcount.model
object Model {
data class Result(val query: Query)
data class Query(val searchinfo: SearchInfo)
data class SearchInfo(val totalhits: Int)
}
However, if I keep my Models in the base package as the code below, but I don't want to keep the entire package i.e. -keep class com.elyeproj.wikisearchcount.** { *; }
, since this defeat the purpose of proguard
package com.elyeproj.wikisearchcount
object Model {
data class Result(val query: Query)
data class Query(val searchinfo: SearchInfo)
data class SearchInfo(val totalhits: Int)
}
How could I keep my model classes?
I tried -keep class com.elyeproj.wikisearchcount.Model.** { *; }
, but it doesn't work.
After exploring further, I found the answer
Why don't you use the annotation
@SerializedName
and then you don't have to worry about the obfuscation? You could use the following code: