我尝试将一个正在运行的Eclipse Android项目导入Android Studio。我正在Mac上使用最新版本的Android Studio。当我尝试构建时,它会继续显示此错误:
错误:任务执行失败 ':应用程序:transformClassesWithJarMergingForDebug'。
com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目: COM /谷歌/ API /客户端/ HTTP / AbstractHttpContent.class
产生此问题的类位于com.google.http-client:google-http-client-gson:1.20.0库中,位于com.google.api.client.http包中。我在app.gradle文件中尝试了很多东西,例如排除了com.google.api.client.http组,但没有任何效果。这是我的app.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.time2"
minSdkVersion 17
targetSdkVersion 19
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions.encoding = 'ISO-8859-1'
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.http-client:google-http-client-gson:1.20.0'
compile 'com.google.code.gson:gson:2.1'
compile files('libs/commons-io-2.4.jar')
compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-http-client-1.18.0-rc.jar')
compile files('libs/google-http-client-android-1.18.0-rc.jar')
compile files('libs/google-oauth-client-1.18.0-rc.jar')
compile files('libs/httpcore-4.3.3.jar')
compile files('libs/httpmime-4.3.6.jar')
compile files('libs/json-simple-1.1.1.jar')
compile files('libs/jsr305-1.3.9.jar')
compile 'com.stripe:stripe-android:+'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
答案 0 :(得分:3)
您应该避免手动将libs添加到项目中。
E.g. change compile files('libs/commons-io-2.4.jar') compile files('libs/google-api-client-1.18.0-rc.jar') compile files('libs/google-api-client-android-1.18.0-rc.jar') compile files('libs/google-http-client-1.18.0-rc.jar') compile files('libs/google-http-client-android-1.18.0-rc.jar') compile files('libs/google-oauth-client-1.18.0-rc.jar') compile files('libs/httpcore-4.3.3.jar') compile files('libs/httpmime-4.3.6.jar') compile files('libs/json-simple-1.1.1.jar') compile files('libs/jsr305-1.3.9.jar') to compile 'commons-io:commons-io:2.4' compile 'com.google.api-client:google-api-client:1.18.0-rc' compile 'com.google.api-client:google-api-client-android:1.18.0-rc' compile 'com.google.http-client:google-http-client:1.18.0-rc' compile 'com.google.http-client:google-http-client-android:1.18.0-rc' compile 'com.google.oauth-client:google-oauth-client:1.18.0-rc' compile 'org.apache.httpcomponents:httpcore:4.3.3' compile 'org.apache.httpcomponents:httpmime:4.3.6' compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'com.google.code.findbugs:jsr305:1.3.9'
请确认这些是正确的包裹。让我们知道您在更新后发现了什么?
答案 1 :(得分:2)
库'com.google.http-client:google-http-client-gson:1.20.0'
由以下九个模块组成:
google-http-client google-http-client-android google-http-client-appengine google-http-client-xml google-http-client-protobuf google-http-client-jdo google-http-client-jackson google-http-client-jackson2 google-http-client-gson
其中一些例如google-http-client
作为jar
再次包含在巡视依赖项中。因此重复的条目。
使用google-http-java-client
时,请检查此链接以获得正确的设置。它有一步一步的指示 - Setup Instructions