错误说明:
错误:任务执行失败 ':应用程序:transformClassesWithJarMergingForDebug&#39 ;. > com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目: COM /谷歌/ API /客户端/ HTTP / AbstractInputStreamContent.class
这是我的gradle代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.richwebs.user.hohoride"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.google.api-client:google-api-client-android:1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-base:9.0.2'
compile 'com.google.android.gms:play-services-analytics:9.0.2'
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}
android {
useLibrary 'org.apache.http.legacy'
}
答案 0 :(得分:1)
有两种方法可以解决这个问题
dexOptions { preDexLibraries = false javaMaxHeapSize" 4g" }
并启用mutidexSupport,如下所示:
defaultConfig {
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
并在清单文件中设置名称属性:
<application
android:name="android.support.multidex.MultiDexApplication" >
</application>
这是我的完整gradle文件代码..
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.apple"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile project(':library')
compile files('libs/httpmime-4.3.jar')
compile files('libs/gcm.jar')
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:multidex:1.0.1'
compile 'com.firebase:firebase-client-android:2.3.1'
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpclient-4.3.3.jar')
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-vector-drawable'
all*.exclude group: 'com.android.support', module: 'animated-vector-drawable'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
我对这三个模块有问题所以o只是从所有依赖项中排除,我的错误消失了。
答案 1 :(得分:0)
在导入的libs的不同版本中可能存在问题
你有
compile 'com.google.android.gms:play-services-analytics:9.0.0' // wrong!
compile 'com.google.android.gms:play-services-gcm:9.0.2'
确保您始终使用相同的版本:
compile 'com.google.android.gms:play-services-analytics:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'