title: Multiple Dex Files define Landroid/support/v4
body: <p>I've been banging my head against this for a few hours now. I tried importing 2bard's <code>AndroidPianoView</code> as a library project (both PianoView and PianoViewExample inside) and they both have a <code>support-v4 jar</code> in their <code>libs</code> directory.</p>
  
  <p>My project is in Android Studio.</p>
  
  <p>Removing the jar from either or both directories does me no good, and I have tried following the solution in <a href="https://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility">this popular question</a> without success.</p>
  
  <p>Here's the dependency tree from running <code>gradle -q:app:dependencies</code>:</p>
  
  <pre><code>compile - Classpath for compiling the main sources.
  +--- com.android.support:appcompat-v7:22.2.1
  |    \--- com.android.support:support-v4:22.2.1
  |         \--- com.android.support:support-annotations:22.2.1
  \--- project :PianoViewExample
       \--- project :PianoView
  </code></pre>
  
  <p>Here are the build.gradle files:</p>
  
  <p><strong>My Project</strong></p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral() // or jcenter()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:1.3.1'
      }
  }
  
  apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 22
      buildToolsVersion "22.0.1"
  
      defaultConfig {
          applicationId "com.ajbowler.jamory"
          minSdkVersion 15
          targetSdkVersion 22
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      compile 'com.android.support:appcompat-v7:22.2.1'
      compile project(':PianoViewExample')
  }
  </code></pre>
  
  <p><strong>PianoView</strong></p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral() // or jcenter()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:1.3.1'
      }
  }
  
  apply plugin: 'com.android.library'
  
  dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
  }
  
  android {
      compileSdkVersion 22
      buildToolsVersion "22.0.1"
  
      sourceSets {
          main {
              manifest.srcFile 'AndroidManifest.xml'
              java.srcDirs = ['src']
              resources.srcDirs = ['src']
              aidl.srcDirs = ['src']
              renderscript.srcDirs = ['src']
              res.srcDirs = ['res']
              assets.srcDirs = ['assets']
         }
  
          // Move the tests to tests/java, tests/res, etc...
          instrumentTest.setRoot('tests')
  
          // Move the build types to build-types/&lt;type&gt;
          // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
          // This moves them out of them default location under src/&lt;type&gt;/... which would
          // conflict with src/ being used by the main source set.
          // Adding new build types or product flavors should be accompanied
          // by a similar customization.
          debug.setRoot('build-types/debug')
          release.setRoot('build-types/release')
      }
  }
  </code></pre>
  
  <p><strong>PianoViewExample</strong></p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral() // or jcenter()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:1.3.1'
      }
  }
  
  apply plugin: 'com.android.library'
  
  dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
      compile project(':PianoView')
  }
  
  android {
      compileSdkVersion 22
      buildToolsVersion "22.0.1"
  
      sourceSets {
          main {
              manifest.srcFile 'AndroidManifest.xml'
              java.srcDirs = ['src']
              resources.srcDirs = ['src']
              aidl.srcDirs = ['src']
              renderscript.srcDirs = ['src']
              res.srcDirs = ['res']
              assets.srcDirs = ['assets']
          }
  
          // Move the tests to tests/java, tests/res, etc...
          instrumentTest.setRoot('tests')
  
          // Move the build types to build-types/&lt;type&gt;
          // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
          // This moves them out of them default location under src/&lt;type&gt;/... which would
          // conflict with src/ being used by the main source set.
          // Adding new build types or product flavors should be accompanied
          // by a similar customization.
          debug.setRoot('build-types/debug')
          release.setRoot('build-types/release')
      }
  }
  </code></pre>
  
  <p><strong>Console Output</strong></p>
  
  <pre><code>UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/ActivityCompatHoneycomb;
      at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
      at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
      at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
      at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
      at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
      at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
      at com.android.dx.command.dexer.Main.run(Main.java:246)
      at com.android.dx.command.dexer.Main.main(Main.java:215)
      at com.android.dx.command.Main.main(Main.java:106)
  Error:Execution failed for task ':app:dexDebug'.
  &gt; com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
  </code></pre>
  
  <p><strong>What Happens when I <code>exclude module: 'support-v4'</code> in main project</strong></p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral() // or jcenter()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:1.3.1'
      }
  }
  
  apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 22
      buildToolsVersion "22.0.1"
  
      defaultConfig {
          applicationId "com.ajbowler.jamory"
          minSdkVersion 15
          targetSdkVersion 22
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile project(':PianoViewExample')
      compile('com.android.support:appcompat-v7:23.0.1') {
          configurations {
              all*.exclude group: 'com.android.support', module: 'support-v4'
              all*.exclude group: 'com.google.android.gms', module: 'play-services'
          }
      }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Error:(8, 8) error: cannot access TaskStackBuilder
  class file for android.support.v4.app.TaskStackBuilder not found
  Error:(10, 5) error: method does not override or implement a method  from a supertype
  Error:(12, 9) error: cannot find symbol variable super
  Error:(13, 9) error: cannot find symbol method setContentView(int)
  Error:(16, 5) error: method does not override or implement a method from a supertype
  Error:(19, 9) error: cannot find symbol method getMenuInflater()
  Error:(23, 5) error: method does not override or implement a method from a supertype
  Error:(35, 16) error: cannot find symbol variable super
  Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
  &gt; Compilation failed; see the compiler error output for details.
  </code></pre>
  
  <p>I would really appreciate some help on this. I have been unable to figure out where the issue has been coming from past <code>exclude</code>-ing the support jar from one of the PianoView modules, which hasn't worked.</p>