这是我现在在proguard-project.txt
中使用的代码# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-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
-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{*;}
-keep public class * extends android.app.Application{*;}
-keep public class * extends android.app.Activity{*;}
-keep public class * extends android.app.MapActivity{*;}
-keep public class * extends android.app.PreferenceActivity{*;}
-keep public class * extends android.view.View{*;}
-keep public class * extends android.widget.BaseAdapter{*;}
-keep public class * extends android.app.Service{*;}
-keep public class * extends android.content.BroadcastReceiver{*;}
-keep public class * implements android.view.View.OnTouchListener{*;}
-keep public class * implements android.view.View.OnClickListener{*;}
-keep public class * extends com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay<OverlayItem>{*;}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-libraryjars libs/android-support-v4.jar
-libraryjars libs/apache-mime4j-0.6.jar
-libraryjars libs/httpmime-4.0.1.jar
-libraryjars libs/libGoogleAnalyticsV2.jar
-assumenosideeffects class android.util.Log {*;}
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembers class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-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
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# 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.**
-dontwarn org.apache.**
但是日志仍然出现在logcat中。
所以,我只是想知道代码必须是什么,以便只删除日志。其他优化不是必需的。
谢谢
答案 0 :(得分:26)
ProGuard配置文件分为几个部分(从Android SDK r20开始),在project.properties中指定:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
如果未禁用优化,则只能删除日志记录,这需要不同的全局配置文件:
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
文件proguard-project.txt只需要包含项目特定的配置。您的文件似乎包含太多,但这些是删除日志记录的设置:
-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(...);
}
类似的问题和答案:
答案 1 :(得分:10)
如果您在Android Studio上遇到此问题,则必须将Eric的解决方案应用于您的build.grade文件(在应用级别)。替换:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
使用:
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'