如何跳过基本包装上的retrofit2使用的proguard模型? [英] How to skip proguard models used by retrofit2 that is on the base package?

查看:96
本文介绍了如何跳过基本包装上的retrofit2使用的proguard模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kotlin和Retrofit 2编写应用程序.使用proguard时,请遵循以下规则:

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

此外,我还需要保护我的模型,如 https://stackoverflow.com/a/41136007/3286489

Besides I also need to proguard my models too, as stated in https://stackoverflow.com/a/41136007/3286489

如果我将模型包装在包装中,并且有-keep class com.elyeproj.wikisearchcount.model.** { *; }

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

但是,如果我将我的模型按照下面的代码放在基本包中,但我不想保留整个包,即-keep class com.elyeproj.wikisearchcount.** { *; },因为这样做会破坏proguard的目的

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?

我尝试了-keep class com.elyeproj.wikisearchcount.Model.** { *; },但是没有用.

I tried -keep class com.elyeproj.wikisearchcount.Model.** { *; }, but it doesn't work.

推荐答案

为什么不使用注释@SerializedName,那么您就不必担心混淆了吗? 您可以使用以下代码:

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

这篇关于如何跳过基本包装上的retrofit2使用的proguard模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆