-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
上面方式只能去除非拼接的日志,像Log.i(tag,“test”+某变量)是去不掉的,会生成StringBuilder拼接过程代码。
另类方法: 采用变量(LOG_DEBUG)控制日志输出,当为false时,会被判断无用代码,自然被删掉。
release {
minifyEnabled true
buildConfigField "boolean", "LOG_DEBUG", "false"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ndk {
abiFilters "armeabi-v7a"
}
}
public static final boolean logDebug = BuildConfig.LOG_DEBUG;
if(Utils.logDebug)
Log.i(tag, "load ");
|