Android studio 打包jar時的混淆

混淆的位置爲項目lib或者module下的Proguard-rules.pro文件

#混淆時不使用大小寫混合類名
-dontusemixedcaseclassnames

表示不跳過library中的非public的類

-dontskipnonpubliclibraryclasses

打印混淆的詳細信息

-verbose

Optimization is turned off by default. Dex does not like code run

through the ProGuard optimize and preverify steps (and performs some

of these optimizations on its own).

-dontoptimize

表示不進行校驗,這個校驗作用 在java平臺上的

-dontpreverify

Note that if you want to enable optimization, you cannot just

include optimization flags in your own project configuration file;

instead you will need to point to the

“proguard-android-optimize.txt” file instead of this one from your

project.properties file.

#使用註解需要添加
-keepattributes Annotation
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

For native methods, see http://proguard.sourceforge.net/manual/examples.html#native

#指定不混淆所有的JNI方法
-keepclasseswithmembernames class * {
native ;
}

keep setters in Views so that animations can still work.

see http://proguard.sourceforge.net/manual/examples.html#beans

#所有View的子類及其子類的get、set方法都不進行混淆
-keepclassmembers public class * extends android.view.View {
void set*(**);
*** get
();
}

We want to keep methods in Activity that could be used in the XML attribute onClick

不混淆Activity中參數類型爲View的所有方法

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations

不混淆Enum類型的指定方法

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

不混淆Parcelable和它的子類,還有Creator成員變量

-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}

不混淆R類裏及其所有內部static類中的所有static變量字段

-keepclassmembers class *.R$ {
public static ;
}

The support library contains references to newer platform versions.

Don’t warn about those in case this app is linking against an older

platform version. We know about them, and they are safe.

不提示兼容庫的錯誤警告

-dontwarn android.support.**

Understand the @Keep support annotation.

-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep ;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep ;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep (…);
}
###########################以下是需要手動的混淆配置協議###############################

-libraryjars “C:\Program Files\Java\jre1.8.0_151\lib\rt.jar”
#-libraryjars “C:\Users\admin\AppData\Local\Android\sdk\platforms\android-26\android.jar”

注意:以上兩個路徑需要將以上路徑是自己jar包的位置,需要根據自己情況進行修改,如果報重複配置的錯誤,註釋掉即可

#代碼迭代優化的次數,默認5
-optimizationpasses 5
#混淆時不會產生形形色色的類名
-dontusemixedcaseclassnames
#忽略警告
-ignorewarnings
#以下是不需要混淆的文件
-keep class com.android.sdk.demo.LogUtils{
*;
}
-keep class com.android.sdk.demo.StorageUtils{
*;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章