1. 程式人生 > >Android 混淆檔案配置

Android 混淆檔案配置

第一次配置混淆檔案,盜用的別人的模板,也不知道合不合格,反正最後打包沒問題,其實主要的變動是在第三方,有些使用的是官方的使用配置,有的沒找到就直接使用萬能寫法
比如融雲:
-dontwarn io.rong.push.**
-keep class io.rong.push.** {*;}
如果你不知道第三方的混淆配置,就這樣寫,沒問題的

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/wangwei/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
#-------------------------------------------定製化區域----------------------------------------------
#---------------------------------1.實體類---------------------------------

#本程式
-keep class
com.kb.lifecool.bean.** {*;
}
#------------------------------------------------------------------------- #---------------------------------2.第三方包------------------------------- #阿里雲 -keep class com.alibaba.sdk.android.oss.** { *; } -dontwarn okio.** -dontwarn org.apache.commons.codec.binary.** #融雲 -dontwarn io.rong.push.**
-keep class io.rong.push.** {*;} #圖片選擇 -dontwarn cn.finalteam.rxgalleryfinal.** -keep class cn.finalteam.rxgalleryfinal.** {*;} #地址選擇 -dontwarn kankan.wheel.** -keep class kankan.wheel.** {*;} # -dontwarn com.amap.api.** -keep class com.amap.api.** {*;} #小米推送 -dontwarn com.xiaomi.push.** -keep class
com.xiaomi.push.** {*;
}
# -dontwarn okhttp3.** -keep class okhttp3.** {*;} # -dontwarn retrofit2.** -keep class retrofit2.** {*;} # RxJava RxAndroid -dontwarn sun.misc.** -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { long producerIndex; long consumerIndex; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { rx.internal.util.atomic.LinkedQueueNode producerNode; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { rx.internal.util.atomic.LinkedQueueNode consumerNode; } # GSON -keep class sun.misc.Unsafe { *; } -keep class com.google.gson.examples.android.model.** { *; } # ButterKnife -keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewBinder { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; } #phototView -dontwarn com.github.chrisbanes.PhotoView.** -keep class com.github.chrisbanes.PhotoView.** {*;} #輪播圖 -dontwarn com.jude.rollviewpager.RollPagerView.** -keep class com.jude.rollviewpager.RollPagerView.** {*;} #剪下圖片 -dontwarn com.yalantis.ucrop.** -keep class com.yalantis.ucrop.** { *; } -keep interface com.yalantis.ucrop.** { *; } #提示小圓點 -dontwarn com.jauker.widget.** -keep class ccom.jauker.widget.** { *; } #側滑刪除 -dontwarn com.github.mcxtzhang.SwipeDelMenuLayout.** -keep class com.github.mcxtzhang.SwipeDelMenuLayout.** { *; } #執行時許可權 -dontwarn com.zhy.m.** -keep class com.zhy.m.** {*;} -keep interface com.zhy.m.** { *; } -keep class **$$PermissionProxy { *; } #------------------------------------------------------------------------- #---------------------------------3.與js互相呼叫的類------------------------ #------------------------------------------------------------------------- #---------------------------------4.反射相關的類和方法----------------------- -keep class com.kb.lifecool.utils.StatusBarCompat { *; } #---------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------- #-------------------------------------------基本不用動區域-------------------------------------------- #---------------------------------基本指令區---------------------------------- #程式碼混淆的壓縮比例,值在0-7之間 -optimizationpasses 5 #指定不去忽略非公共的庫的類的成員 -dontskipnonpubliclibraryclassmembers #生成原類名和混淆後的類名的對映檔案 -printmapping proguardMapping.txt #指定混淆是採用的演算法 -optimizations !code/simplification/cast,!field/*,!class/merging/* #不混淆Annotation -keepattributes *Annotation*,InnerClasses #不混淆泛型 -keepattributes Signature #丟擲異常時保留程式碼行號 -keepattributes SourceFile,LineNumberTable #---------------------------------------------------------------------------- #---------------------------------預設保留區--------------------------------- -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class * extends android.view.View -keep public class com.android.vending.licensing.ILicensingService -keep class android.support.** {*;} -keep public class * extends android.view.View{ *** get*(); void set*(***); public <init>(android.content.Context); public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class * implements java.io.Serializable { static final long serialVersionUID; private static final java.io.ObjectStreamField[] serialPersistentFields; private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); java.lang.Object writeReplace(); java.lang.Object readResolve(); } -keep class **.R$* { *; } -keepclassmembers class * { void *(**On*Event); } #---------------------------------------------------------------------------- #---------------------------------webview------------------------------------ -keepclassmembers class fqcn.of.javascript.interface.for.Webview { public *; } -keepclassmembers class * extends android.webkit.WebViewClient { public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); public boolean *(android.webkit.WebView, java.lang.String); } -keepclassmembers class * extends android.webkit.WebViewClient { public void *(android.webkit.WebView, jav.lang.String); } #---------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------