Proguard-不要混淆Kotlin数据类 [英] Proguard - do not obfuscate Kotlin data classes
问题描述
在我的项目中,我的旧模型类使用 AutoValue .我开始使用Kotlin,并且想使用数据类代替AutoValue.我想对我的数据层中的所有数据类禁用模糊处理,但要继续对程序包中的其他类进行模糊处理.
In my project I use AutoValue for my old model classes. I started using Kotlin and I want to use Data Classes instead of AutoValue. I want to disable the obfuscation for all Data classes in my Data layer but to keep obfuscating the other classes in the package.
有没有办法做到这一点?
Is there a way to do this?
我希望在我的 Proguard 文件中包含以下内容:
I would expect to have something like this in my Proguard file:
-keepclassmembers data class example.data_layer.** { *; }
推荐答案
To fix the problem I moved the model classes to model package and added new ProGuard rule for the package.
-keep class com.company.myfeature.model.** { *; }
另一种解决方案是使用来自 @Keep注释支持库以禁用该类的混淆处理:
Another solution would be to use @Keep annotation from support library to disable the obfuscation for the class:
@Keep
data class MyRequestBody(val value: String)
使用 @Keep 可能会引起问题,因为它很容易忘记为新班级添加它.
Using @Keep may cause problems because it's easy to forget to add it for new classes.
希望将来有一种方法可以使用一个 ProGuard规则来禁用软件包中所有 Data类的混淆,而无需为该子软件包提供子软件包. 模型类.
Hopefully in future there will be a way with one ProGuard rule to disable the obfuscation for all Data classes in package without the need to have a sub-package for the model classes.
这篇关于Proguard-不要混淆Kotlin数据类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!