Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure proguard to ONLY remove android logging calls

Tags:

I'm trying to configure proguard to ONLY remove calls to android.util.Log from my Android app (for the release build). I specifically don't want proguard to do any obfuscation or minification of the code.

This is the configuration I've tried but it doesn't remove the Log calls (I assume because of the -keep class **)

-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*  -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod  -keep class ** {     *; }  -assumenosideeffects class android.util.Log {     *; } 

Is what I'm asking even possible with proguard?

like image 221
UloPe Avatar asked Mar 22 '13 13:03

UloPe


People also ask

What is R8 ProGuard in Android?

R8 is another tool that will convert your java byte code into an optimized format of dex code. It will check the whole application and will remove the unused classes and methods. It helps us to reduce the size of our APK and to make our app more secure. R8 uses similar proguard rules to modify its default behavior.

What is Android ProGuard rules?

ProGuard is a free Java app for Android that allows us to do the following: Reduce (minimize) the code: Unused code in the project should be removed. Code obfuscation: Rename the names of classes, fields, and so on. Improve the code: Inline the functions, for example.


2 Answers

You can remove logging calls with this option in 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(...); } 

This option is only relevant if optimization is not disabled, like in proguard-android.txt. You have to specify proguard-android-optimize.txt instead, in project.properties:

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

You can disable shrinking and obfuscation if you wish. You can also preserve the internal API of your application from optimization if you wish:

-keep class myapp.** { *; } 

Disabling these steps and keeping all code of course isn't optimal from a ProGuard point of view.

like image 148
Eric Lafortune Avatar answered Feb 19 '23 04:02

Eric Lafortune


In build.gradle

buildTypes {          release {             minifyEnabled true             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'         }     } 

In proguard-rules.pro

-dontwarn ** -target 1.7 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose  -optimizations !code/simplification/arithmetic,!code/allocation/variable -keep class ** -keepclassmembers class *{*;} -keepattributes *  #This will not remove error log -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(...); } 
like image 31
Sandeep Shabd Avatar answered Feb 19 '23 02:02

Sandeep Shabd