29

I am using Android Studio 0.4.2. Opened project from a friend who is using 0.3.2. Tried to compile but got exception.

Execution failed for task ':JuiceTV:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Program Files\Android\android-studio\sdk\build-tools\19.0.0\dx.bat --dex --output D:\Antik TV - Android\JuiceTV\build\libs\JuiceTV-debug.dex D:\Antik TV - Android\JuiceTV\build\classes\debug D:\Antik TV - Android\JuiceTV\build\dependency-cache\debug D:\Antik TV - Android\JuiceTV\build\pre-dexed\debug\classes-ffe9228b675e120536184b1056a59fcfc91e4006.jar D:\Antik TV - Android\JuiceTV\build\pre-dexed\debug\commons-io-2.4-27f1277ba9e42db4b52f3f658da01a26db29b896.jar D:\Antik TV - Android\JuiceTV\build\pre-dexed\debug\joda-time-2.2-4549e2440d188ee3fb4f85702e03eace13e8ad18.jar D:\Antik TV - Android\JuiceTV\build\pre-dexed\debug\mmlib-04a4fd100008bfbc84f0c25fd219e50eb7de9d0b.jar D:\Antik TV - Android\JuiceTV\build\pre-dexed\debug\support-v4-18.0.0-ba816fc3ae00ee0fdb20e5444c1d8bb88647d773.jar
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/sevensoft/mmlib/AttachedOverlayWindow$1;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:593)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:551)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:532)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:169)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)  

Tried this things:

  • deleting *.apk files
  • searching for dependencies with gradle -q dependencies but got nothing

JuiceTV Gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}

dependencies {
    compile project(':TVbase')
}

BaseTv Gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.+'
    compile files('libs/joda-time-2.2.jar')
    compile files('libs/mmlib.jar')
    compile files('libs/commons-io-2.4.jar')
}

Any new tips?

3
  • 8
    try this : clean your project from Build > Clean Project than use File > Inavlidate Cache/ Restart . Commented Feb 12, 2014 at 18:33
  • Could you tell me where I could do the same in eclipse? Commented Sep 28, 2014 at 14:26
  • In my case ./gradlew clean works and __NOT__./gradlew android:clean Commented Dec 18, 2019 at 2:46

5 Answers 5

18

I just had the same issue and I discovered that my application and a library were referring to 2 versions of the same jar.

I did a search and my application.iml file clearly showed the duplicates.

<orderEntry type="library" exported="" name="crittercism_v3_0_11_sdkonly" level="project" />
<orderEntry type="library" exported="" name="crittercism_v4_4_0" level="project" />

I replaced the older v3 version with the v4 version and it worked after a clean rebuild.

Sign up to request clarification or add additional context in comments.

3 Comments

how did you do this search?
If that dependencies came from 3rd party libraries, you can declare same, up to date library in your build.gradle, or remove old version from library by exclude statement.
I solved my problem using the dependency graph in gradle. Using the gradle wrapper I ran ./gradlew dependencies to see the graph and then you search through if. Remember you might need to run a ./gradlew app:dependencies or ./gradlew lib:dependencies, depending on how your project is structured
7

This happens when a Module has a dependency on both another module and that same module's jar.

1 Comment

I had same problem. Initially I had a project as an aar dependency and when I added the same project as a direct module I forgot to remove the aar dependency.
2

I had this issue on android studio 1.0, along with removing the duplicate entry for libraries you should also try deleting the bin folders and do a clean build.

Comments

2

As of Android Gradle 1.0 this can happen a few ways:

  1. If you only use Maven repos you can run into this issue if two different artifacts include the same class file.
    The Mockito-all library, for instance, includes Hamcrest and you would therefore cause this error if you included both dependencies in a build.
    Note, if you have minification turned on you won't see the error until you start using Hamcrest. The way to resolve this is to use a version of the library that isn't including other package's classes (Mockito-core in this case).

  2. If you declare a local jar/aar dependency (compile 'com.some.library:some-artiface-version_number@aar') that is already being included by other maven-based dependencies.
    In this situation your local declaration doesn't get de-duped with the Maven one because the pom information isn't available. You would typically create a local, file-based maven repo for the aar to get around this.

In either case, a project clean is required to pickup the changes.

Comments

1

Having multiDex disabled and incremental in dexOptions enabled will also cause this issue.

defaultConfig {
    multiDexEnabled = false
 }
dexOptions {
    javaMaxHeapSize "4g"
    incremental true
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.