Android Studio Multiple Dex错误

时间:2015-06-26 14:49:42

标签: java android jar dex

我查看了相关主题,但我找不到任何解决方案。我第一次运行项目时,模拟器打开了,但随后它开始出错。 我怎么能解决这个问题? 此致...

我的错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/http/entity/mime/FormBodyPart;
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:502)
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)
Error:Execution failed for task ':userAndroid:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 19.946 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

我的build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion '23.0.0 rc2'

defaultConfig {
    applicationId "com.user.android"
    minSdkVersion 14
    targetSdkVersion 19
 //   multiDexEnabled = true

}


/*dexOptions {
    preDexLibraries = false
    incremental true
    javaMaxHeapSize "4g"
}*/

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

  }

dependencies {
compile project(':slidingMenuLibrary')
compile project(':pullToRefreshLibrary')
compile project(':placeActivity')
compile project(':jMC')
compile project(':salesforceSDK')
compile project(':library')
compile files('libs/android-integration-2.3-SNAPSHOT.jar')
compile files('libs/aws-android-sdk-1.4.4-core.jar')
compile files('libs/aws-android-sdk-1.4.4-s3.jar')
compile files('libs/com.radaee.pdfex_view.jar')
compile files('libs/commons-lang3-3.1.jar')
compile files('libs/core-2.3-SNAPSHOT.jar')
compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')
compile files('libs/libGoogleAnalyticsServices-v3.01.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile files('libs/urbanairship-lib-3.0.0.jar')
compile 'com.google.api.client:google-api-client-repackaged-com-google-common-base:1.2.3-alpha'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:support-v4:22.2.0'
}

编辑:我在不同的文件中编译com.android.support:support-v4:22.2.0'

我的JMC库的build.gradle:

apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion '23.0.0 rc2'

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 16
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
compile files('../libMaster/acra-4.2.3.jar')
compile files('../libMaster/apache-mime4j-0.5.jar')
compile files('../libMaster/commons-io-2.4.jar')
compile files('../libMaster/httpclient-4.0.jar')
compile files('../libMaster/httpcore-4.0-beta3.jar')
compile 'com.google.guava:guava:18.0'
compile files('../libMaster/httpmime-4.0-beta2.jar')
compile 'com.android.support:support-v4:22.2.0'

}

2 个答案:

答案 0 :(得分:1)

Android newer build tools have support for mutidex. you can enable multidex support by editing your build.gradle file like below

  defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }

Also you have @override this method in your Application class

protected void attachBaseContext(Context base) {
 super.attachBaseContext(base);
 MultiDex.install(this);
}

答案 1 :(得分:0)

发现这个:https://github.com/mihaip/dex-method-counts 工具显示具有许多方法的库。 你对graddle的依赖如此巨大,你真的在​​使用它吗?如果没有尝试删除未使用的