title: Removing logging with ProGuard doesn't remove the strings being logged
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6009078/removing-unused-strings-during-proguard-optimisation">Removing unused strings during ProGuard optimisation</a>  </p>
  </blockquote>
  
  
  
  <p>I have an Android application with dozens of logging statements. I'd prefer they wouldn't appear in the release version, so I used Proguard with something like this in the <code>proguard.cfg</code> file:</p>
  
  <pre><code>-assumenosideeffects class android.util.Log {
      public static *** d(...);
  }
  </code></pre>
  
  <p>But the problem is that there are a lot of <code>Log.d("something is " + something)</code>, and although the <code>Log.d()</code> statement is being removed from the bytecode, <strong>the strings are still there</strong>.</p>
  
  <p>So, following <a href="https://stackoverflow.com/questions/6009078/removing-unused-strings-during-proguard-optimisation/6023505#6023505">this</a> answer, I created a simple wrapper class, something along the lines of:</p>
  
  <pre><code>public class MyLogger {
      public static void d(Object... msgs) {
          StringBuilder log = new StringBuilder();
          for(Object msg : msgs) {
              log.append(msg.toString());
          }
          Log.d(TAG, log.toString());
      }
  }
  </code></pre>
  
  <p>Then I edited my <code>proguard.cfg</code>:</p>
  
  <pre><code>-assumenosideeffects class my.package.MyLogger {
      public static *** d(...);
  }
  </code></pre>
  
  <p><strong>But the strings are still found in the generated bytecode!</strong></p>
  
  <p>Other than this, I am using the standard <code>proguard.cfg</code> provided by the Android SDK. Am I doing something wrong?</p>
  
  <hr>
  
  <p><strong>Edit</strong>: after examining the generated bytecode, I saw that the strings were there, but they were not being appended one to another, as I thought. They were being <strong>stored in an array</strong>. Why? To pass them as variable parameters to my method. It looks like ProGuard doesn't like that, so I modified my logger class like this:</p>
  
  <pre><code>public static void d(Object a) {
      log(a);
  }
  
  public static void d(Object a, Object b) {
      log(a, b);
  }
  
  (... I had to put like seven d() methods ...)
  
  private static void log(Object... msgs) {
      (same as before)
  }
  </code></pre>
  
  <p>It's ugly, but now the strings are <strong>nowhere</strong> in the bytecode.</p>
  
  <p>Is this some kind of bug/limitation of ProGuard? Or is it just me not understanding how it works?</p>