Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My log messages are not removed with proguard configuration

I am developing my Android app.

Then I enable & configure proguard by:

Step 1. Enable proguard:

In project.properties I have:

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

I also tried the following:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=proguard.cfg

Step 2. Configure proguard:

In proguard.cfg I have:

-assumenosideeffects class android.util.Log { *; }

I think the above configuration should remove all logs.

But when I install the APK under target/ folder & run my app, I can still see all my Log messages in logcat console. Why?

like image 204
Leem.fin Avatar asked Mar 28 '14 13:03

Leem.fin


People also ask

How does ProGuard obfuscation work?

In the obfuscation step, ProGuard renames classes and class members that are not entry points. In this entire process, keeping the entry points ensures that they can still be accessed by their original names. The preverification step is the only step that doesn't have to know the entry points.

Is ProGuard enabled by default?

Proguard is basically integrated into the Android Build System. And it runs only when the build of your application is in the release mode. You can choose to use Android Proguard as it is not compulsory but is highly recommended.

What is ProGuard configuration?

ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.

What is keep in ProGuard?

-keep disables all of ProGuard's goodness. No shrinking, no obfuscation; not for classes, not for members. In real use cases, you can let ProGuard do at least some of it's work. Even if your variables are accessed by reflection, you could remove and rename unused classes, for example.


2 Answers

You should use the first line in your project.properties:

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

You should then add these lines to your proguard-project.txt (not the deprecated proguard.cfg):

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

These options only have any effect if the file does not contain -dontoptimize.

Ant and Eclipse pick up the settings from project.properties. Gradle and Maven require equivalent settings that specify the configuration files, in build.gradle and in pom.xml respectively.

Similar questions and answers:

  • How to config my proguard-project.txt file to remove just Logs
  • Removing Log call using proguard
like image 73
Eric Lafortune Avatar answered Oct 06 '22 00:10

Eric Lafortune


I can't remember where I found the reference to this method, but I've always used this:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}

in my configuration. It does remove debug and verbose logging that I wrote

like image 36
NickT Avatar answered Oct 06 '22 01:10

NickT