1

I created a wrapper class MyLog to do logging for my Android app, which essentially just wraps android.util.Log. I want logging to be completely gone in my release app. I have the following rule defined in my proguard file:

-assumenosideeffects class com.myapp.logging.MyLog {
    public static void d(...);
}

I am seeing that lines that have log statements as follows:

MyLog.d("Logging a boolean %b and a string %s parameter", isTrue, stringName);

are being shrunk to:

Object[] objArr = new Object[]{Boolean.valueOf(z), str};

and lines with log statements as follows:

MyLog.d("function call result: " + foo() + " end");

are shrunk to:

new Object[1][0] = foo();

In both cases the leftovers from obfuscation are pretty useless and might as well should've been removed.

Question:

  1. Why would proguard leave unused variables in example #1 above?
  2. Is there a better way to tell proguard - "Assume no side effects when you remove this method declaration and any calls to it, along with the parameters passed to it"?

I have read other answers related to the topic and the closest answer is here. I am not looking for solutions with BuildConfig.IS_LOGGING_ENABLED type solution where every log statement should be wrapped with this check.

Community
  • 1
  • 1
amitsaurav
  • 531
  • 1
  • 5
  • 18
  • Are you using optimization? Android's default proguard file has a `-dontoptimize` directive in it. If you have `getDefaultProguardFile( 'proguard-android.txt' )` in your build.gradle, try using `getDefaultProguardFile( 'proguard-android-optimize.txt' )` instead. – Barend Oct 24 '16 at 17:07
  • I am using `proguardFile file('proguard.cfg')` in my `release` build type and my rule is defined in the proguard.cfg file. Would that not work? – amitsaurav Oct 25 '16 at 03:45
  • Proguard files can include other proguard files. Thing is that, by default, the Android build system includes a proguard file that disables optimization. Try adding `-printconfiguration` to your proguard.cfg and looking through the output. If there's `-dontoptimize` in there, optimizations are disabled. – Barend Oct 25 '16 at 06:20
  • Tried the `-printconfiguration` and did not see the `-dontoptimize` setting in the output. Any other ideas? – amitsaurav Nov 03 '16 at 23:12

0 Answers0