12

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.**

But the Logs are still appearing in the logcat.

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

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

2 Answers2

28

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

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:

Community
  • 1
  • 1
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • So, from the links you mean to say **Proguard doesn't work for Log.d("answer = " + answer, "something = " + something);**?? – Archie.bpgc Jan 03 '13 at 14:17
  • Also, **proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt** in my project.properties and **The remove logs code** in my proguard-project.txt will work? – Archie.bpgc Jan 03 '13 at 14:19
  • @Snicolas Agreed, but proguard is completely new to me and i don't have time to study it thoroughly :( . Anyways, thanks a lot, its working fine now. Hope it doesn't give any problem later. – Archie.bpgc Jan 03 '13 at 17:08
  • 1
    Is there a way to remove logging also from native libs? – Giuseppe Apr 27 '13 at 06:50
  • @Giuseppe ProGuard only processes bytecode, not native code. For native code, you could use traditional preprocessing directives and macro definitions in the source code. – Eric Lafortune Apr 28 '13 at 13:11
  • Is there a way to remove logs without optimization? – Dinesh Aug 04 '17 at 07:57
10

If you're stuck with this on Android Studio, the solution of Eric must be applied to your build.grade file (at the app level). Replace:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

with:

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
user3057865
  • 313
  • 1
  • 3
  • 9