title: Enable Proguard for only two packages in large Android application
body: <p><strong>Background</strong></p>
  
  <p>I am developing an Android application that relies on multiple external libraries (8 added as library project dependencies, 14 added as jar dependencies).</p>
  
  <p>Some of these jar libraries are closed source an have already been obfuscated and some of them rely pretty heavily on reflection.</p>
  
  <p>The application uses ZXing for QR code scanning/recognition and, without Proguard optimization, ZXing is quite slow (at least on Android). </p>
  
  <p>At first, I only needed to optimize the <code>com.google.zxing.**</code> package using Proguard. In order to do that I've added the following Proguard options in my config file (the best I could figure out from <a href="https://stackoverflow.com/questions/11896618/how-to-obfuscate-only-few-class-or-a-single-package">this question</a>):</p>
  
  <pre><code>-keep class !com.google.zxing.** { *; }
  -keep interface !com.google.zxing.** { *; }
  -keep enum !com.google.zxing.** { *; }
  -dontwarn !com.google.zxing.**
  </code></pre>
  
  <p>I exported my application and it works like a charm.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Now, I want to use Proguard to obfuscate the application's classes.</p>
  
  <p>I've tried changing the above to:</p>
  
  <pre><code>-keep class !(com.google.zxing.**, com.example.app.**) { *; }
  -keep interface !(com.google.zxing.**, com.example.app.**) { *; }
  -keep enum !(com.google.zxing.**, com.example.app.**) { *; }
  -dontwarn !(com.google.zxing.**, com.example.app.**)
  -keep com.example.app.activities.** { *; }
  -keep com.example.app.receivers.** { *; }
  -keep com.example.app.services.** { *; }
  -keep com.example.app.views.** { *; }
  </code></pre>
  
  <p>The problem is that Proguard does not accept <code>!(package.one.**, second.package.**) { *; }</code> as a valid option for a <code>-keep</code> rule.</p>
  
  <p>Another approach would be to put a <code>-keep</code> rule for every package in my application. </p>
  
  <p>This approach has two big disadvantages:</p>
  
  <ol>
  <li><p>adding or swapping libraries would require changing the Proguard config file</p></li>
  <li><p>it makes updating libraries a pain, as some of them are obfuscated and, when recompiled by the library's developer, will change package names.</p></li>
  </ol>
  
  <p>Obviously, I would like to avoid this approach as much as possible (because of the high number of external libraries).</p>
  
  <p><strong>Question</strong></p>
  
  <p>Is it possible to use Proguard to obfuscate just two packages, without defining a <code>-keep</code> rule for each of the other packages in my app? If so, how can I do this?</p>