title: Exclude jar-library from aar
body: <p>I have a library project, which has a dependency to cordova.jar which is loaded from the projects libs directory.</p>
  
  <p>This library project I deploy as an aar to a maven nexus.</p>
  
  <p>In an application project, I have a dependency to the library projects aar (compile ...). But the application project has the same dependency to the cordova.jar.</p>
  
  <p>So when building the applicaton project, I get this error:</p>
  
  <pre><code>:transformClassesWithDexForDebug
  UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/AuthenticationToken;
      at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
      at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
      at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
      at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
      at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
      at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
      at com.android.dx.command.dexer.Main.run(Main.java:277)
      at com.android.dx.command.dexer.Main.main(Main.java:245)
      at com.android.dx.command.Main.main(Main.java:106)
  </code></pre>
  
  <p>To solve this, i tried to exclude the cordova.jar when loading the library aar in my application project:</p>
  
  <pre><code>dependencies {
      compile ('com.my.library:hybridstory:1.0'){
          exclude (group: 'org.apache.cordova')
      }
  }
  </code></pre>
  
  <p>But this does not work. Am I doing something wrong?</p>
  
  <p>My second question is:</p>
  
  <p>Is it possible to exclude the /libs/cordova.jar when uploading the library project as aar, instead of excluding the cordova.jar when loading the library in an application? How could I achieve this with this gradle:</p>
  
  <pre><code>apply plugin: 'com.android.library'
  apply plugin: 'maven'
  
  archivesBaseName = 'hybridstory'
  group = 'com....'
  version = '16.3.0-SNAPSHOT'
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
  
      defaultConfig {
          minSdkVersion 16
          targetSdkVersion 22
          versionCode 1
          versionName version
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      provided files('libs/cordova-5.1.1.jar')
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.4.0'
      compile 'com....'
  }
  
  task createJavadoc(type: Javadoc) {
      source = android.sourceSets.main.java.srcDirs
      title = archivesBaseName + " " + version
      options.overview = "src/main/doc-files/overview.html"
      doLast {
          copy {
              from "src/main/doc-files"
              into "$buildDir/docs/javadoc"
          }
      }
  }
  
  uploadArchives {
      repositories {
          mavenDeployer {
              repository(url: 'https://maven..../content/repositories/om-releases/')
              snapshotRepository(url: 'https://maven..../content/repositories/om-snapshots/')
          }
      }
  }
  
  task androidJavadocsJar(type: Jar, dependsOn: createJavadoc) {
      classifier = 'javadoc'
      from createJavadoc.destinationDir
  }
  
  task androidSourcesJar(type: Jar) {
      classifier = 'sources'
      from android.sourceSets.main.java.srcDirs
  }
  
  artifacts {
      archives androidSourcesJar
      archives androidJavadocsJar
  }
  </code></pre>
  
  <p><strong>### UPDATE ###</strong></p>
  
  <p>I tried the gradle scope "provided" as suggested by Xaver Kapeller (thanks!). But there is still the cordova.jar packaged into the aar. Does the provided scope simply not work or am I missing something?</p>