启用Proguard的只有两个大型的Andr​​oid应用程序包 [英] Enable Proguard for only two packages in large Android application

查看:133
本文介绍了启用Proguard的只有两个大型的Andr​​oid应用程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我开发一个Android应用程序,它依赖于多个外部库(8添加为库项目的依赖性,14添加为依赖的JAR)。

I am developing an Android application that relies on multiple external libraries (8 added as library project dependencies, 14 added as jar dependencies).

有些罐子库是闭源的已经被混淆,其中一些严重依赖pretty的反思。

Some of these jar libraries are closed source an have already been obfuscated and some of them rely pretty heavily on reflection.

该应用程序使用ZXing的QR code扫描/识别,并在不Proguard的优化,ZXing是相当缓慢的(至少在Android)。

The application uses ZXing for QR code scanning/recognition and, without Proguard optimization, ZXing is quite slow (at least on Android).

起初,我使用ProGuard只需要优化 com.google.zxing。** 包。为了做到这一点我已在我的配置文件(以下Proguard的选项最好的,我可以从<一弄清楚href=\"http://stackoverflow.com/questions/11896618/how-to-obfuscate-only-few-class-or-a-single-package\">this问题):

At first, I only needed to optimize the com.google.zxing.** package using Proguard. In order to do that I've added the following Proguard options in my config file (the best I could figure out from this question):

-keep class !com.google.zxing.** { *; }
-keep interface !com.google.zxing.** { *; }
-keep enum !com.google.zxing.** { *; }
-dontwarn !com.google.zxing.**

我出口我的应用程序,它就像一个魅力。

I exported my application and it works like a charm.

问题

现在,我想用Proguard的混淆应用程序的类。

Now, I want to use Proguard to obfuscate the application's classes.

我试图改变上述为:

-keep class !(com.google.zxing.**, com.example.app.**) { *; }
-keep interface !(com.google.zxing.**, com.example.app.**) { *; }
-keep enum !(com.google.zxing.**, com.example.app.**) { *; }
-dontwarn !(com.google.zxing.**, com.example.app.**)
-keep com.example.app.activities.** { *; }
-keep com.example.app.receivers.** { *; }
-keep com.example.app.services.** { *; }
-keep com.example.app.views.** { *; }

问题是Proguard的不接受 {*!(package.one **,** second.package。); } 作为一个 -keep 规则有效的选项。

The problem is that Proguard does not accept !(package.one.**, second.package.**) { *; } as a valid option for a -keep rule.

另一种方法是把一个 -keep 规则在我的应用程序的每个包。

Another approach would be to put a -keep rule for every package in my application.

该方法有两大缺点:


  1. 添加或交换库需要改变Proguard的配置文件

  1. adding or swapping libraries would require changing the Proguard config file

这让更新图书馆痛苦,因为他们中的一些混淆,当由库的开发者重新编译,将改变包名。

it makes updating libraries a pain, as some of them are obfuscated and, when recompiled by the library's developer, will change package names.

显然,我想避免这种方法尽可能地(因为大量外部库的)。

Obviously, I would like to avoid this approach as much as possible (because of the high number of external libraries).

是否可以使用Proguard的混淆只是两个包,但没有设定每个我的应用程序的其他包的 -keep 规则?如果是这样,我怎么能这样做呢?

Is it possible to use Proguard to obfuscate just two packages, without defining a -keep rule for each of the other packages in my app? If so, how can I do this?

推荐答案

正确的语法是没有任何括号中的逗号分隔的列表:

The correct syntax is a comma-separated list without any parentheses:

-keep class !com.google.zxing.**,!com.example.app.** { *; }

请参阅ProGuard的手册>使用> 过滤器

See the ProGuard manual > Usage > Filters.

请注意,这个单行已经暗示了其他两个线接口和枚举。你可以不让过去的通配符匹配子包意味着所有的子包-keep选项:

Note that this single line already implies the two other lines for interfaces and enums. You can imply the -keep options for all subpackages by not letting the last wildcard match subpackages:

-keep class !com.google.zxing.**,!com.example.app.* { *; }

这篇关于启用Proguard的只有两个大型的Andr​​oid应用程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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