android proguard 使用 (一)

解析的时候往往会用到第三方jar包
-libraryjars ../libs/mail.jar 
-libraryjars ../libs/activation.jar 
-libraryjars ../libs/additionnal.jar
-libraryjars ../libs/android-support-v4.jar


还有的如下:

===========================================================================

-optimizationpasses 5

-dontusemixedcaseclassnames
-ignorewarning
-dontskipnonpubliclibraryclasses
-dontoptimize
-verbose
-injars libs\your_library.jar
-outjars libs\your_library_out.jar
-libraryjars '..\....\.xxxxx.jar'

====================================================================================

如上的红色文字非常重要

-injars 表示你要混淆的jar文件

-outjars 是混淆后的jar文件名

-libraryjars 是混淆时需要引用的android库

-ignorewarning 表示混淆时忽略所以的警告

-dontoptimize 不进行优化,这句代码非常重要。并且配置中不能有-dontpreverify字段;-dontpreverify在混淆jar时没有问题但是在apk应用中使用该jar后对apk进行混淆时就会失败。

===============================================================================================

关于 keep有个复杂的语法

[@annotationtype] [[!]public|final|abstract|@ ...] [!]interface|class|enum classname
    [extends|implements [@annotationtype] classname]
[{
    [@annotationtype] [[!]public|private|protected|static|volatile|transient ...] <fields> |
                                                                      (fieldtype fieldname);
    [@annotationtype] [[!]public|private|protected|static|synchronized|native|abstract|strictfp ...] <methods> |
        <init>(argumenttype,...) |  classname(argumenttype,...) |(returntype methodname(argumenttype,...));
    [@annotationtype] [[!]public|private|protected|static ... ] *;
    ...
}]

“|” 表示或关系,“!”表示非,“[]”表示可选,“...”代表等等

注意语法有个花括号,里面是用来说明成员变量是否keep的,可以写一个范围,比如写<fields>就是所有字段不被混淆,<methods>就是所有方法不被混淆,*就是所有都不被混淆。还可以单独指出哪个函数不被混淆,比如对于“寻找getSomething游戏”,可以这样写:

-keep public class yourpackagename.JavascriptInterface {
  void getSomething(java.lang.String)
}

对于keep有几个类似的选项,下面的表格抄自:http://proguard.sourceforge.net/#manual/usage.html

Keep
From being removed or renamed From being renamed
Classes and class members -keep -keepnames
Class members only -keepclassmembers -keepclassmembernames
Classes and class members, if class members present -keepclasseswithmembers -keepclasseswithmembernames

我就不解释了。




你可能感兴趣的:(android proguard 使用 (一))