Android Proguard Options - Stricter Rules and Deletion of Log Entries

I turned on proguard without commenting out a line in project.properties.

I decompiled my APK to see if it worked. I see that all my methods, variable names and class names have been changed to a, b, c .. etc., which is good. However, my activity classes have not been renamed. Also, the Log.d statements were not deleted as expected.

How can I get someone to read decompiled code as well as delete log entries?

+4
source share
4 answers

The various methods related to the life cycle of an Android application cannot be renamed because:

  • Inheritance; The superclass method is enclosed in the Android library, which cannot be renamed through Proguard. Thus, renaming onCreate() to a() will cause a compilation problem due to the @Override annotation.
  • In the activity lifecycle, Android performs various functions that are expected to have specific names (for example, onCreate() and onResume() ). If your onCreate() renamed to a() , only the superclass implementation will be executed, not yours.

As for why Action class names cannot be renamed:

  • This involves making changes to a manifest that is simply not supported by Proguard.
  • An undesirable effect on the automatic introduction of these changes may occur. For example, shortcuts on the user's home screen may stop working if a class that was previously confused to A can now be confused to B

Retrieving log statements deleted through Proguard is quite simple using the precenosideeffects option. See this related question for more details :

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

Paul Lammertsma gave the exact answer to the first part of your question. Development of the second part:

You can delete the log only if optimization is not disabled, which requires specifying another global configuration file in project.properties :

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

These settings in proguard-project.txt then delete all entries:

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

There are various equivalent forms with more or less wildcards.

Related questions and answers:

+6
source

To remove all links to log statements, you must add these lines to your proguard configuration file:

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

On the official website you can find a complete guide with examples.

+3
source

To remove Journals, I wrote an article with various methods, some of which are from StackOverflow (the article indicates who the author is). You can see it here:

http://bakingcode.com/development/ocultar-trazas-en-una-app-final-de-android/ IMHO I think the second with Proguard is the best.

To confuse your code, you need to think about your needs, see more examples at: http://proguard.sourceforge.net/index.html#manual/examples.html

+2
source

All Articles