Proguard does not remove logical calls

When compiling my application with Ant, I can see the detailed output of Proguard, and I have settings for deleting log statements (see below), but when I run release apk, all the log statements that I tried to delete are there.

I have 2 projects, each of which includes a common project. In the two main projects and in the general project, each has a proguard.cfg file, all of which contain a fragment for deleting log statements.

Is there something I am missing?

** All my log statements are Log.d (...)

proguard.cfg

-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -dontobfuscate -forceprocessing -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class com.android.vending.licensing.ILicensingService -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -assumenosideeffects class android.util.Log { public static *** d(...); public static *** v(...); } 
+4
source share
3 answers

Here your proguard file is fine, but there are details that may be missing.

In your gradle file, you have something like this:

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

Check getDefaultProguardFile('proguard-android') , so if you intend to optimize it, you should change it to getDefaultProguardFile('proguard-android-optimize.txt') .

I took some time to figure this out, saw your question, but still could not delete my Log calls of my code. So I found this link that explains that it is necessary to change file optimization so that proguard can optimize.

https://developer.android.com/tools/help/proguard.html#enabling-gradle

+2
source

You cannot use assumenosideeffects without optimizing Proguard.

+1
source

Instead of deleting or commenting on all of your log messages using pro-guard, you can do something like this. Create a utility class, which basically is the shell of the Android registration system.

 public class Util{ public static boolean showLogs = true; public static String myTag = 'My Tag'; public static void logD(String message){ if (Util.showLogs) Log.d(myTag, message); } } 

Until I compile my application for distribution, I just call showLogs = true; and then all log messages are suppressed

You can easily extend this class so you can specify a tag and create more than debugging messages.

0
source

Source: https://habr.com/ru/post/1397109/


All Articles