每当我尝试调试和部署我的android应用程序(在Android Studio 0.9中)时,都会出现以下错误:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/multidex/BuildConfig.class
这里要说明的是我的行动的简要历史记录:
今天早上该项目运行良好
添加了一些其他的类和方法
超出限制并收到此错误:Unable to execute dex: method ID not in [0, 0xffff]: 65536
决定增加对我项目的multiDex支持,因为减少依赖不是一种选择
从那时起,我按照此SO post using Gradle在分离的dex文件中拆分外部库以解决Android Dalvik 64k方法限制的问题后,在将multiDex添加到我的项目后,一直得到描述的错误。
这是我的build.gradle文件:
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.0'
defaultConfig {
applicationId "com.stackoverflow.application"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
dx.additionalParameters += "--main-dex-list=$projectDir/".toString() // enable the main-dex-list
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':viewPagerIndicatorLibrary')
compile 'com.google.android:multidex:0.1'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'se.emilsjolander:stickylistheaders:2.5.1'
compile 'joda-time:joda-time:2.5'
compile 'com.makeramen:roundedimageview:1.4.0'
compile 'javax.inject:javax.inject:1'
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'com.googlecode.libphonenumber:libphonenumber:6.3.1'
compile('com.google.api-client:google-api-client-gson:1.18.0-rc') {
exclude module: 'httpclient'
}
compile 'com.google.android.gms:play-services:6.1.71'
compile('com.google.api-client:google-api-client:1.17.0-rc') {
exclude(group: 'xpp3', module: 'xpp3')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
exclude(group: 'junit', module: 'junit')
exclude(group: 'com.google.android', module: 'android')
}
compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
}
compile('com.google.http-client:google-http-client-android:1.17.0-rc') {
exclude(group: 'com.google.android', module: 'android')
}
compile 'com.google.guava:guava:18.0'
}
我还有另一个项目依赖项,可以使用viewPagerIndicator库以及/ libs文件夹中的一些jar:
android-async-http-1.4.6.jar
guice-3.0-no_aop.jar
jsr305-1.3.9.jar
roboguice-2.0.jar
欢迎提供任何有关在不删除我所需依赖项的情况下如何解决此问题的建议!