How to skip proguard models used by retrofit2 that is on the base package?

只愿长相守 提交于 2019-12-08 03:38:10

问题


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.


回答1:


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)
}



回答2:


After exploring further, I found the answer

-keep class com.elyeproj.wikisearchcount.Model** { *; }


来源:https://stackoverflow.com/questions/44473673/how-to-skip-proguard-models-used-by-retrofit2-that-is-on-the-base-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!