代码之家  ›  专栏  ›  技术社区  ›  Pavel Sumarokov

无法编译已连接Excel库的项目

  •  0
  • Pavel Sumarokov  · 技术社区  · 6 年前

    尝试用Excel库编译项目,以便读写*.xls和*.xlsx文件。我还进口了com.android.support支持:多索引:1.0.3库并在默认配置中将multiDexEnabled设置为true。库是我的最后5个条目构建.gradle依赖项:

    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 回复  |  直到 6 年前