2017-07-17 102 views
1

嗨添加Apache poi gradle構建後,我得到這個預期。你能否向我解釋一下如何解決這個問題。Android的gradle構建給DuplicateFileException

我已經試過在很多方面不包括封裝選項,沒有工作

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.1.0' 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:design:25.1.0' 
    compile 'com.android.support:cardview-v7:25.1.0' 
    compile 'org.greenrobot:greendao:3.2.0' 
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.9' 

} 

錯誤:執行失敗的任務「:應用程序:transformResourcesWithMergeJavaResForDebug」。

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE File1: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi-ooxml-schemas/3.9/4c514498f0e82cccfdd3208b9caff2f45158db4a/poi-ooxml-schemas-3.9.jar File2: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi-ooxml/3.9/bbe83c739d22eecfacd06d7e0b99ba13277040ed/poi-ooxml-3.9.jar File3: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi/3.9/5d5e41354e88322e4bc590b31f3d2d1d52b3e6ac/poi-3.9.jar

+0

也許問題是通過替換com.github.dextorer來解決的:沙發:1.0.0而不是編譯組:'org.apache.poi',名稱:'poi-ooxml',版本:'3.9' –

回答

1

嘗試這種通過使用下面的代碼

packagingOptions { 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    pickFirst 'META-INF/license.txt' 
     } 
+0

多謝兄弟。爲我工作。你能解釋一下嗎? –

0

加入這個給你gradle這個文件中排除重複的文件

android { 
     ... 
     packagingOptions { 
       exclude 'META-INF/DEPENDENCIES' 
       exclude 'META-INF/NOTICE' 
       exclude 'META-INF/LICENSE' 
       exclude 'META-INF/LICENSE.txt' 
       exclude 'META-INF/NOTICE.txt' 
      } 
} 
0

轉到排除複製文件到您的build.gradle文件,並添加以下行:

packagingOptions { 
    exclude 'META-INF/LICENSE.txt' 
    } 

在我來說,我不得不添加像這樣的:

apply plugin: 'com.android.library'  
android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    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' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 
} 
dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:+' 
    compile 'com.google.android.gms:play-services:6.5.87' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.mcxiaoke.volley:library:1.0.15' 
    compile 'com.google.code.gson:gson:2.2.4' 
    compile "org.apache.httpcomponents:httpcore:4.4.1" 
    compile "org.apache.httpcomponents:httpmime:4.3.6" 


} 

爲了更好的參考訪問this answer