[英]How to resolve java.util.zip.ZipException?
當我嘗試調試和部署我的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帖子使用Gradle將外部庫拆分為單獨的dex文件來解決Android Dalvik 64k方法限制 。
這是我的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/<filename>".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庫以及my / libs文件夾中的幾個jar:
我歡迎任何有關如何解決此問題而不刪除任何所需依賴項的建議!
線程有點舊,但我也得到了這個錯誤。
我的問題是我在gradle文件中使用了兩個不同的com.google.android.gms:play-services版本。
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.3.0' // WRONG!
確保您始終使用相同的版本:
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'
編輯:這是一個錯誤,修復到期。 請參閱https://code.google.com/p/android/issues/detail?id=81804
我也有這個問題,我也沒有答案。 但這是我可以添加的內容:
BuildConfig
類是一個魔術類,是作為構建過程的一部分生成的。 出於某種原因,在mutildex-1.0.0
和multidex-instrumentation-1.0.0
aars中都存在具有相同完全限定名稱( android.support.multidex.BuildConfig
)的版本。
我不相信我們做錯了什么。 我認為這是一個處於最前沿的症狀。 我提出了一個錯誤報告 。
要診斷並修復此問題,請運行以下gradle命令:
./gradlew clean app:dependencies
這將在樹中列出您應用中的所有依賴項。 搜索有問題的重復類的結果並添加
compile('naughty.library') {
exclude group: 'foo', module: 'bar'
}
刪除副本。
我最近遇到了這個錯誤,在Android工作室查看我的“外部庫”之后,事實證明我的一個庫已被包含在兩個版本號下。 (在這種情況下,它是wire-runtime 1.5.1和1.5.2)。
我建議的是在Project視圖中查看“External Libraries”,看看那里是否有任何冗余庫。 它還包含傳遞依賴關系,因此您可能會發現令您驚訝的內容。
1.update谷歌播放服務
2.加
compile 'com.google.android.gms:play-services-fitness:8.1.0'
compile 'com.google.android.gms:play-services-wearable:8.1.0'
而不是compile 'com.google.android.gms:play-services:8.1.0'
在build.gradle文件中。
3。
defaultConfig {
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
在我的情況下,原因是Facebook Android SDK。 只是排除傳遞依賴:
compile('com.facebook.android:facebook-android-sdk:+') {
exclude group: 'com.android.support', module: 'multidex'
}
在你的情況下,它可能是一些其他的依賴 - 只需逐個排序,你會發現具有傳遞multidex
依賴的multidex
。
如果啟用multiDex,則應該在afterEvaluate {}
停止執行邏輯。 multi-dex支持將為您處理主要的dex列表。
當某個類位於多個位置時,會發生類似重復輸入的錯誤。 要解決此問題,只需搜索顯示項目中重復條目的類。 它將顯示此類出現多個地方的所有路徑。 在Windows中CNTRL + N是用於在文件中搜索的鍵盤快捷鍵。 簡單的嘗試刪除其中一個lib或文件,問題解決了。
tools:overrideLibrary="com.google.android.gms.location, com.google.android.gms.internal"
我的訣竅(我想你應該用你使用的任何谷歌庫改變位置)
您正在添加這樣的庫
(一個)。
並且您的代碼中已經提供了此庫包。
評論它或刪除此行
如何知道項目中庫的重復副本:
解壓縮您的“YOUR_LIBRARY.jar”並在代碼中看到相同的類名。
轉到File/Invalidate Chaches/Restart
,您的問題已解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.