Android(安卓)Proguard 如何混淆package name
一、在Android 的proguard-project.txt 文件里我们可以看到如下选项:
参考 http://proguard.sourceforge.net/manual/usage.html#keeppackagenames
-keeppackagenames [package_filter]
Specifies not to obfuscate the given package names. The optional filter is a comma-separated list of package names. Package names can contain ?, *, and ** wildcards, and they can be preceded by the ! negator. Only applicable when obfuscating.
-flattenpackagehierarchy [package_name]
Specifies to repackage all packages that are renamed, by moving them into the single given parent package. Without argument or with an empty string (''), the packages are moved into the root package. This option is one example of further obfuscating package names. It can make the processed code smaller and less comprehensible. Only applicable when obfuscating.
-repackageclasses [package_name]
By default, packages that contain classes that can't be renamed aren't renamed either, and the package hierarchy is preserved. (因此我们想到另外一种不让包名被混淆的方法:即在每个package 下放一个空的class指定为不混淆,这样整个package name就会保留,不会把包名也混淆掉)Specifies to repackage all class files that are renamed, by moving them into the single given package. Without argument or with an empty string (''), the package is removed completely. This option overrides the -flattenpackagehierarchy option. It is another example of further obfuscating package names. It can make the processed code even smaller and less comprehensible. Its deprecated name is -defaultpackage. Only applicable when obfuscating.
Counter-indication: classes that look for resource files in their package directories will no longer work properly if they are moved elsewhere. When in doubt, just leave the packaging untouched by not using this option.
二、具体使用方法:Obfuscating package names
参考 http://proguard.sourceforge.net/manual/examples.html#repackaging
Package names can be obfuscated in various ways, with increasing levels of obfuscation and compactness. For example, consider the following classes:
mycompany.myapplication.MyMainmycompany.myapplication.Foomycompany.myapplication.Barmycompany.myapplication.extra.FirstExtramycompany.myapplication.extra.SecondExtramycompany.util.FirstUtilmycompany.util.SecondUtil
Let's assume the class name mycompany.myapplication.MyMain
is the main application class that is kept by the configuration. All other class names can be obfuscated.
By default, packages that contain classes that can't be renamed aren't renamed either, and the package hierarchy is preserved. This results in obfuscated class names like these:
mycompany.myapplication.MyMainmycompany.myapplication.amycompany.myapplication.bmycompany.myapplication.a.amycompany.myapplication.a.bmycompany.a.amycompany.a.b
The -flattenpackagehierarchy
option obfuscates the package names further, by flattening the package hierarchy of obfuscated packages:
-flattenpackagehierarchy 'myobfuscated'
The obfuscated class names then look as follows:
mycompany.myapplication.MyMainmycompany.myapplication.amycompany.myapplication.bmyobfuscated.a.amyobfuscated.a.bmyobfuscated.b.amyobfuscated.b.b
Alternatively, the -repackageclasses
option obfuscates the entire packaging, by combining obfuscated classes into a single package:
-repackageclasses 'myobfuscated'The obfuscated class names then look as follows:
mycompany.myapplication.MyMainmycompany.myapplication.amycompany.myapplication.bmyobfuscated.amyobfuscated.bmyobfuscated.cmyobfuscated.d
Additionally specifying the -allowaccessmodification
option allows access permissions of classes and class members to be broadened, opening up the opportunity to repackage all obfuscated classes:
-repackageclasses 'myobfuscated'-allowaccessmodificationThe obfuscated class names then look as follows:
mycompany.myapplication.MyMainmyobfuscated.amyobfuscated.bmyobfuscated.cmyobfuscated.dmyobfuscated.emyobfuscated.f
The specified target package can always be the root package. For instance:
-repackageclasses ''-allowaccessmodificationThe obfuscated class names are then the shortest possible names:
mycompany.myapplication.MyMainabcdef
Note that not all levels of obfuscation of package names may be acceptable for all code. Notably, you may have to take into account that your application may contain resource files that have to be adapted.
更多相关文章
- Android(安卓)MIME类型与文件后缀名匹配部分
- Android(安卓)关机(reboot)流程
- android手机之间用wifi direct通信
- Android(安卓)Studio混淆错误:Missing class: java.awt.event.Win
- android 多渠道打包,build.gradle文件配置、manifest文件配置
- 编译android出现"too many open files"的解决办法
- Android(安卓)Service中判断系统全屏
- 通过ijetty获取android设备的截图
- Android(安卓)代码混淆