首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在安卓中使用R8和Proguard时,如何保护数据模型类不受逆向工程的影响?

在安卓中使用R8和Proguard时,如何保护数据模型类不受逆向工程的影响?
EN

Stack Overflow用户
提问于 2019-12-10 20:43:59
回答 2查看 392关注 0票数 2

现在,在对android应用程序APK文件进行逆向工程时,我可以看到纯文本中的数据模型类,就像我使用@keep注释一样。如果没有注释,应用程序将崩溃,因为这些文件正在被R8删除。

如何通过确保在逆向工程中看不到数据模型文件来保护它们?

EN

回答 2

Stack Overflow用户

发布于 2020-02-28 23:45:17

最近我遇到了同样的问题,我确定的问题是我有一套过时的防范规则。请注意,在2019年10月4日,Gson更新了他们的前卫规则,以将R8考虑在内。希望你能更新它们。

你可以在https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg上找到它

代码语言:javascript
运行
复制
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

还要记住添加您的特定模型类:查看中心的规则,因为它只是一个示例,必须使用您自己的模型进行更改。

票数 1
EN

Stack Overflow用户

发布于 2019-12-10 20:51:10

将以下代码行添加到gradle.properties文件中。

代码语言:javascript
运行
复制
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59267535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档