title: Remove external library from obfuscated classes.jar (in Android Studio / Gradle)
body: <p>I created an android library (using Android Studio), which imports an external .jar file (containing only interfaces) in order to build correctly. But the final library file should not include this file, as the main application project will include a .jar file that already contains these interface classes contained in the external library. If I leave the file inside, the compiler will complain with "multiple dex files define...".</p>
  
  <p>I can automatically remove the external .jar library from the .aar with gradle like this:</p>
  
  <pre><code>android.libraryVariants.all { variant -&gt;
      variant.outputs.each { output -&gt;
          def packageLib = output.getPackageLibrary()
          packageLib.exclude('libs/externalLibrary.jar')
      }
  }
  </code></pre>
  
  <p>But if the library is obfuscated using ProGuard <em>(minifyEnabled true)</em>, then all class files from the external library are added to classes.jar before packaging it into the .aar file, and therefore can't be excluded this way.</p>
  
  <p>I can edit the classes.jar file and remove files from it automatically using gradle like this:</p>
  
  <pre><code>task makeRelease(type: Jar) {
      baseName='changedClasses'
      destinationDir=file('../../release/')
  
      from zipTree('build/intermediates/bundles/release/classes.jar')
      exclude "com/externallibrary/**"
  }
  </code></pre>
  
  <p>which works when running this task after finishing the build of the library. But I would need to run this task after the proguard task has finished, but before the files are packaged into the final .aar in order to automatically build and run the final app. And I haven't found any way to do this so far...</p>
  
  <p>Therefore: How can I automatically remove files from the classes.jar that is included into the final .aar file? Or maybe I'm going at this the wrong way, is there another way to solve my problem, like telling proguard to not include the files in classes.jar?</p>