简体   繁体   English

Moshi 模型的 Proguard 规则?

[英]Proguard rules for Moshi models?

I have an Android app (Java) that uses Moshi 1.11.0 to work with JSON responses.我有一个 Android 应用程序(Java),它使用 Moshi 1.11.0 来处理 JSON 响应。 Take this model as an example:以这个 model 为例:

class Payments {
    public float amount;
    public int month, year;
}

When developing (and running debug variant), everything works perfectly.在开发(和运行调试变体)时,一切正常。 However, when building a release version, Proguard makes all properties become 0 when trying to read them from my model.但是,在构建发布版本时,Proguard 使所有属性在尝试从我的 model 中读取它们时变为 0。 ( payment.amount , payment.month , payment.year are all 0). ( payment.amount , payment.month , payment.year都是0)。

So far, the only thing that has fixed this is by prepending the @Keep annotation before each and every one of my model declarations:到目前为止,唯一解决此问题的方法是在我的每一个 model 声明之前添加 @Keep 注释:

@Keep
class Payments {...}

My question is.. Is there any other workaround that would fix this issue, without having to modify each and every one of my models?我的问题是.. 是否有任何其他解决方法可以解决此问题,而无需修改我的每一个模型?

I found these keep rules online, can you try to add them to your configuration and see if that solves your problem (without manually adding the @keep annotations to your models)?我在网上找到了这些保留规则,您可以尝试将它们添加到您的配置中,看看是否可以解决您的问题(无需手动将@keep 注释添加到您的模型中)?

https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM