2016-06-18 66 views
2

錯誤描述:如何在Android中解決「TransformException:java.util.zip.ZipException:重複條目」?

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/api/client/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

先告訴我你應用dexConfig? –

+0

不,我不使用dexconfig –

+0

否則把整個gradle.build代碼..所以我可以建議你你必須實現 –

回答

1

有,如果在您的應用程序的方法refrences超過其上限則提高到解決這個問題

  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文件中排除重複的庫。這個錯誤稱爲「已經添加」,並且它在lib中添加.jar文件時發生。文件夾,併爲此設置gradle依賴關係。
  • 這裏是我的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' 
    } 
    

    我有這三個模塊的問題,所以Ø剛剛從所有的依賴排除,和我的錯誤了。

    +1

    在我的情況下,這是行不通的@sagar –

    +0

    bcz你是僅從一個庫中排除。你應該像我所做的那樣從所有庫中排除。並且不通過組。傳遞模塊也是,bcz當我得到這個問題時,我提到了很多stackoverflow的鏈接。這是我找到的最佳解決方案。 –

    +0

    什麼是方式2?此外,問題是否改變?多分辨率在這裏必須做什麼? –

    0

    也許在不同的版本導入庫

    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' 
    
    相關問題