如何配置我的ProGuard-project.txt文件,删除只是日志我的、文件、日志、project

2023-09-12 09:28:48 作者:Sunflower(向日葵)

这是在$ C $词我使用的是现在在ProGuard的-project.txt

This is the code i am using right now in the 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中。

But the Logs are still appearing in the logcat.

所以,我只是想知道,什么是code必须是,这样只有日志被删除。其它优化不需要

So, i just want to know, what the code must be, so that only Logs are removed. other optimizations are not required.

感谢您

推荐答案

ProGuard的配置文件分割成几个部分(如Android的SDK R20的),这是在project.properties规定:

The ProGuard configuration file is split into several parts (as of Android SDK r20), which are specified in project.properties:

  proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

您只能删除记录,如果优化不残,这需要一个不同的全局配置文件:

You can only remove logging if optimization is not disabled, which requires a different global configuration file:

  proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

文件ProGuard的-project.txt只需要包含项目特定的配置。您的文件似乎包含了太多,但这些都是setttings删除日志:

The file proguard-project.txt only needs to contain project-specific configuration. Your file seems to contain way too much, but these are the setttings to remove the logging:

-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(...);
}

类似的问题和答案:

Similar questions and answers:

使用ProGuard的删除日志呼叫 Removing在ProGuard的优化 未使用的字符串 Removing使用ProGuard记录不会删除字符串被记录 Removing Log call using proguard Removing unused strings during ProGuard optimisation Removing logging with ProGuard doesn't remove the strings being logged