I am writing an application with Kotlin and Retrofit 2. As I use proguard, I follow the rules here:
https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-square-retrofit2.pro
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.
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:
object Model {
data class Result(@SerializedName("query") val query: Query)
data class Query(@SerializedName("searchInfo") val searchinfo: SearchInfo)
data class SearchInfo(@SerializedName("totalhits") val totalhits: Int)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With