4

I have enabled proguard by un-commenting the line in project.properties.

I decompiled my APK to check if it worked. I can 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 removed as expected.

How can I make it harder for someone to read the decompiled code and also remove the log statements?

Santiago
  • 982
  • 3
  • 14
  • 30

4 Answers4

9

Various methods related to the Android application lifecycle cannot be renamed, because:

  • Inheritance; the superclass method is enclosed within the Android library, which cannot be renamed through Proguard. Renaming onCreate() to a() will therefore cause a compilation problem due to the @Override annotation.
  • In the lifecycle of your activity, Android executes various functions that are expected to have specific names (e.g. onCreate() and onResume()). If your onCreate() is renamed to a(), only the superclass implementation will be executed -- not yours.

As for why your Activities' class names can't be renamed:

  • This would assume making modifications to the manifest, which simply isn't supported by Proguard.
  • There may be unwanted implications of making these modifications automatically. For instance, shortcuts from a user's home screen may no longer work if a class that was previously obfuscated to A, may now be obfuscated to B.

Getting your Log statements removed through Proguard is fairly simple using the assumenosideeffects option. See this related question for details:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}
Community
  • 1
  • 1
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
6

Paul Lammertsma has provided an accurate answer to the first part of your question. Elaborating on the second part:

You can only remove logging if optimization is not disabled, which requires specifying a different 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 remove all logging:

-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 fewer wildcards.

Similar questions and answers:

Community
  • 1
  • 1
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
3

In order to remove all references to Log statements, you should add these lines in your proguard configuration file:

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

In the official website you can find the complete manual with examples.

StarsSky
  • 6,721
  • 6
  • 38
  • 63
2

In order to remove Logs I wrote an article with various techniques some are from StackOverflow (in the article says who is the author) You can see it here:

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

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

PaNaVTEC
  • 2,505
  • 1
  • 23
  • 36