无法在连接Excel库的情况下编译项目

时间:2018-12-16 19:40:21

标签: java android excel xlsx apache-modules

尝试使用Excel库编译项目,以读取和写入* .xls和* .xlsx文件。另外,我已经导入了com.android.support:multidex:1.0.3库,并在默认配置中将multiDexEnabled设置为true。库是我build.gradle依赖项中的最后5个条目:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.hand.measurements"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'org.apache.commons:commons-lang3:3.6'

    implementation 'junit:junit:4.12'
    implementation 'com.android.support.test:runner:1.0.2'
    implementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation project(':classification')
    implementation files('libs/commons-io-2.6.jar')
    implementation files('libs/poi-3.17.jar')
    implementation files('libs/poi-ooxml-3.17.jar')
    implementation files('libs/poi-ooxml-schemas-3.17.jar')
    implementation files('libs/commons-collections4-4.1.jar')
    implementation files('libs/xmlbeans-2.6.0.jar')
}

当我编译该项目时,发生以下错误:

Information:Gradle tasks [build]
Error:Program type already present: org.apache.xmlbeans.xml.stream.XMLName
Error:Program type already present: org.apache.xmlbeans.xml.stream.Location
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\base_android\AndroidStudioProjects\Measurements\app\libs\xmlbeans-2.6.0.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
Error:com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Error:com.android.tools.r8.utils.AbortException: Error: Program type already present: org.apache.xmlbeans.xml.stream.XMLName
Information:BUILD FAILED in 6m 39s
Information:6 errors
Information:0 warnings
Information:See complete output in console

我试图将xmlbeans库更改为3.0.1和3.0.2版本,项目成功编译,但是当它与* .xlsx文档一起执行以下行时:

Workbook workbook = WorkbookFactory.create(is);

发生运行时错误:

java.lang.NoClassDefFoundError: javax.xml.stream.XMLEventFactory

它也在new XSSFWorkbook(is)运算符期间引发了运行时错误。

如何修复它以使其能够使用* .xlsx格式?

0 个答案:

没有答案