2016-07-05 14 views
2

你好我正在一邊跑我的Android項目下列錯誤:安卓:Apache的POI重複項:組織/阿帕奇/的xmlbeans/XML /流/ Location.class錯誤

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. 
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class 

我已搜查過這個問題上互聯網,differenet型解決方案所提供的一些如下其中:

1] Enable multidex, (by doing `multiDexEnabled true`), 
2] Remove support library v4 as v7 comes with it, (I am using only v7), 
3] Increase jvm heap size through gradle or through gradle.properties, 
2] Do not use multiple playstore library versions (Which I am not using already) 

當我加入的gradle爲dependecy Apache的POI如下所有以上的啓動:

dependencies { 
    .... 
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.14' 
} 

以上都不適用於我的情況。爲什麼會發生這種情況&什麼是可靠的解決方案。

回答

2

有哪些嘗試在Android上使用POI時解決了一些問題提供了幾個項目。

請看一下示例項目https://github.com/centic9/poi-on-android/,它允許在Android上爲POI構建一個jar文件。它刪除了重複項,並修正了禁止包名和其他一些問題。

該地區的另一個項目是https://github.com/andruhon/android5xlsx,但它目前只支持舊版本的POI。

+0

我已經使用https://github.com/andruhon/android5xlsx項目解決了bug,謝謝:) – pcj

0

在您的搖籃編譯支持:multidex並添加dexOptions

android { 
compileSdkVersion 23 
buildToolsVersion "23.0.3" 



defaultConfig { 
    .............. 
    minSdkVersion 19 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
    multiDexEnabled true 


} 
dexOptions { 
    //incremental = true; 
    preDexLibraries = false 
    javaMaxHeapSize "4g" 
} 

packagingOptions { 
    exclude 'META-INF/NOTICE.txt' // will not include NOTICE file 
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file 
} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 

dependencies { 
compile fileTree(include: ['*.jar'], dir: 'libs') 
//Your Dependencies 
compile 'com.android.support:multidex:1.0.1' 
} 

在你的AndroidManifest.xml 添加此行的android:命名

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme" 
    android:name="android.support.multidex.MultiDexApplication" 
    > 

如果您已經使用Play服務庫而不是用

compile 'com.google.android.gms:play-services:+' 

,而不是

compile 'com.google.android.gms:play-services-maps:8.4.0' //or other 
0

做一些其他的閱讀中,我發現有與Android中使用POI庫問題之後,見下面的鏈接:

https://bz.apache.org/bugzilla/show_bug.cgi?id=59268#c0

項目在https://github.com/andruhon/android5xlsx減少庫版本都poi.jar & POI-ooxml.jar,導入這些在你的libs文件夾&包括以下在你的代碼的gradle:

compile fileTree(include: ['*.jar'], dir: 'libs') 

這部作品的原因是創建這個項目的人已經排除了xmlbeans.jar與android build有問題的基本poi.jar。信貸交給了這個傢伙和瑞恩。

此解決方案爲我工作,因此作爲發佈答案

相關問題