When I export android project with proguard.cfg, all referenced .jar files are obfuscated as well. How can I exclude some of that .jars from obfuscation?
当我用proguard.cfg导出android项目时,所有引用的.jar文件也会被混淆。如何从混淆中排除一些.jars?
3 个解决方案
#1
25
If you don't want to edit the Ant script, you can add -keep options to proguard.cfg for the classes in those external jars. For instance:
如果您不想编辑Ant脚本,可以为这些外部jar中的类添加-keep选项到proguard.cfg。例如:
-keep class othercode.** { *; }
Or with a regular expression containing a negator:
或者使用包含否定符的正则表达式:
-keep class !mycode.** { *; }
The standard Ant script will still merge all referenced jars in the single output jar though.
标准的Ant脚本仍将合并单个输出jar中的所有引用的jar。
#2
6
In your config file, set up your jars as library jars instead of input jars. This leaves them untouched.
在配置文件中,将jar设置为库jar而不是输入jar。这使他们不受影响。
-libjars <path/to/jars>
#3
1
Using proguard maven plugin I do it like that
使用proguard maven插件我这样做
<inclusion>
<groupId>foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<library>true</library>
<filter>!META-INF/**</filter>
</inclusion>
The
<library>true</library>
lead to the external jar merged into the final jar after the obfuscation. But this might lead to the Manifest being overwritten. I haven't figured out yet how to avoid that the best way.
混淆后导致外部jar合并到最后一个jar中。但这可能会导致Manifest被覆盖。我还没想出如何避免这种最好的方法。
#1
25
If you don't want to edit the Ant script, you can add -keep options to proguard.cfg for the classes in those external jars. For instance:
如果您不想编辑Ant脚本,可以为这些外部jar中的类添加-keep选项到proguard.cfg。例如:
-keep class othercode.** { *; }
Or with a regular expression containing a negator:
或者使用包含否定符的正则表达式:
-keep class !mycode.** { *; }
The standard Ant script will still merge all referenced jars in the single output jar though.
标准的Ant脚本仍将合并单个输出jar中的所有引用的jar。
#2
6
In your config file, set up your jars as library jars instead of input jars. This leaves them untouched.
在配置文件中,将jar设置为库jar而不是输入jar。这使他们不受影响。
-libjars <path/to/jars>
#3
1
Using proguard maven plugin I do it like that
使用proguard maven插件我这样做
<inclusion>
<groupId>foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<library>true</library>
<filter>!META-INF/**</filter>
</inclusion>
The
<library>true</library>
lead to the external jar merged into the final jar after the obfuscation. But this might lead to the Manifest being overwritten. I haven't figured out yet how to avoid that the best way.
混淆后导致外部jar合并到最后一个jar中。但这可能会导致Manifest被覆盖。我还没想出如何避免这种最好的方法。