APP瘦身
阿新 • • 發佈:2018-12-20
混淆(把程式碼縮小了,比如類名改成a,b)
-
開啟壓縮選項
-
在module的build.gradle中新增
buildTypes {
release {
minifyEnabled true
//proguard(保護一些不能改的檔案 配置)
//proguard-android.txt是系統自帶的不要混淆的檔案(比如四大元件的名字不能混淆,要不清單檔案找不到會無法初始化)
//proguard-rules.pro自定義的不要混淆的(因為一些三方的庫已經做過了混淆,不能再混淆了)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
- 配置自己的檔案不能混淆(防止反射根據類名,欄位名找不到檔案)
- 示例
# 高德地圖
-dontwarn com.amap.api.**
-dontwarn com.a.a.**
-dontwarn com.autonavi.**
-keep class com.amap.api.** {*;}
-keep class com.autonavi.** {*;}
-keep class com.a.a.** {*;}
-dontwarn com.loc.**
-keep class com.loc.** {*;}
# 支付寶
-dontwarn com.alipay.android.app.**
-keep class com.alipay.android. app.** {*;}
# 友盟
-dontwarn com.umeng.**
-keep class com.umeng.** { *;}
-keepclassmembers class * { public <init>(org.json.JSONObject); }
-keep public class com.hyx.maizuo.main.R$*{ public static final int *; }
-keep public class com.umeng.fb.ui.ThreadView { }
# Mob
-dontwarn com.mob.**
-keep class com.mob.** {*;}
# OkHttp3
-dontwarn okhttp3.logging.**
-keep class okhttp3.internal.**{*;}
-dontwarn okio.**
# Retrofit
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
# butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
# ormlite
-dontwarn com.j256.**
-keep class com.j256.** { *; }
-keep enum com.j256.** { *; }
-keep interface com.j256.** { *; }
-keep class com.xjd.takeout.model.dao.bean.** { *; }
# 不混淆 com.squareup.picasso
-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {native <methods>;}
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.xjd.takeout.model.net.bean.** { *; }
##---------------End: proguard configuration for Gson ----------
刪除無用資源
- 刪除無用的語言檔案
- png(帶了透明度)圖片轉換成jpg圖片