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?
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.
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.
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.
-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.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With