Android Proguard-保留所有第三方库是否是最佳实践? [英] Android Proguard - is it best practice to -keep all 3rd party libs?

查看:180
本文介绍了Android Proguard-保留所有第三方库是否是最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用第三方库的应用程序配置Proguard.包括以下行是否是最佳实践"(以避免将来出现难以发现的错误):

I'm configuring Proguard for an app that uses 3rd party libraries. Is it "best practice" (in order to avoid future hard-to-find bugs) to include the line:

-keep class 3rd_party_lib_name.** {*;}

对于每个没有其开发者特定的Proguard指令的第三方开放源代码库?

for every single 3rd party open source library that doesn't have specific Proguard instructions from its developer?

另外,还有一个相关的问题:是否有关于应该使用哪种情况的通用指南

Also, a related question: is there a general guideline for which cases I should use

-keep class 

在哪种情况下我应该使用

and in which cases i should use

-keep public class

非常感谢

推荐答案

proguard和代码混淆的主要问题通常是修改了类名,方法和字段名. (即myExplicitMethodName()变为a())

The major problem with proguard and code obfuscation in general is that classname, methods and fields name are modified. ( i.e. myExplicitMethodName() became a() )

修改类名,方法名或字段后,您将无法使用反射API(即Class.classForName(...),...)访问它

When a classname, method name or a field is modified, you cannot access it using the reflection API (i.e. Class.classForName(...) , ... )

知道这一点,最好的方法是-keep使用反射API可以调用的所有类和库.

Knowing that, it's a best practice to -keep all classes and libraries that can be invoked using the reflection API.

对于第三方库,如果您不知道它们是否使用了反射API:-keep

For 3rd party libraries, if you don't know if they use or not the reflection API : then -keep

对于您自己的代码:希望您知道在哪个类中使用它.因此,对于这些类,请使用-keep.

For your own code: hopefully, you know in which classes you use it. So use -keep for those classes.

请注意,一些流行的框架(例如dagger或jackson)在您自己的类上使用了反射API,因此,如果使用它们,请当心!

Note that some popular framework like dagger or jackson use the reflection API on your own classes, so if you use them, be careful!

这篇关于Android Proguard-保留所有第三方库是否是最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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