请配置android sdk模块的build.gradle文件,可以参考如下:
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
然后修改proguard-rules.pro内容,例如在打包后优化掉log不再输出信息:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** e(...);
public static *** i(...);
public static *** w(...);
}
给你贴一份完整的proguard-rules.pro文件参考吧:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\IDE\adt-bundle-windows-x86-20130522\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 *;
#}
-dontshrink
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-optimizationpasses 5
-dontusemixedcaseclassnames
-keepattributes *Annotation*
-dontpreverify
-verbose
-dontwarn android.support.v4.*
-ignorewarnings
-keep class * extends NativeCrashHandler
-keep,allowshrinking class * extends android.app.ActivityManager
-keep,allowshrinking class * extends android.app.Context
-keep,allowshrinking class * extends android.content.Intent
-keep,allowshrinking class * extends android.content.pm.ApplicationInfo
-keepnames class **ReLinker*
-keepnames class **CrashHandler*
-keepnames class **UserStrategy*
-keepnames class **H5JavaScriptInterface*
-keepclassmembers class **CrashHandler* {
public <methods>;
}
-keepclassmembers class **H5JavaScriptInterface* {
public *;
}
-keepclassmembers class **UserStrategy* {
public <methods>;
}
-keepclassmembers class **ReLinker* {
public <methods>;
}
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** e(...);
public static *** i(...);
public static *** w(...);
}
# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}