android apache poi-ooxml导致构建错误' app:transformClassesWithDesugarForDebug'

时间:2017-08-10 13:20:06

标签: android-gradle apache-poi openxml android-build

我的应用程序中有要求实现Excel创建和下载。我使用Apache POI的HSSFWorkbook来实现该功能。该应用程序成功创建了所需的excel(xls)输出。
但是如果我在gradle中包含apache:poi-ooxml并使用XSSFWorkbook创建相同的xlsx文件,我收到以下错误:

D:\USERS\PATH_TO_PROJECT>gradlew build
  

配置项目:app   配置'编译'在项目':app'已弃用。使用'实施'代替。

     

任务:app:compileDebugJavaWithJavac   注意:某些输入文件使用或覆盖已弃用的API。   注意:使用-Xlint重新编译:弃用以获取详细信息。   注意:某些输入文件使用未经检查或不安全的操作。   注意:使用-Xlint重新编译:取消选中以获取详细信息。

线程中的异常" main" java.lang.IllegalStateException:期望只初始化此接口中的字段。 owner = org / apache / xmlbeans / impl / xb / ltgfmt / Code $ 1,expected = org / apache /的xmlbeans / IMPL / XB / ltgfmt /代码         在com.google.common.base.Preconditions.checkState(Preconditions.java:721)         在com.google.devtools.build.android.desugar.InterfaceDesugaring $ InterfaceFieldWriteCollector.visitFieldInsn(InterfaceDesugaring.java:260)         在org.objectweb.asm.MethodVisitor.visitFieldInsn(未知来源)         在org.objectweb.asm.tree.FieldInsnNode.accept(未知来源)         在org.objectweb.asm.tree.InsnList.accept(未知来源)         在org.objectweb.asm.tree.MethodNode.accept(未知来源)         在com.google.devtools.build.android.desugar.LambdaDesugaring $ InvokedynamicRewriter.visitEnd(LambdaDesugaring.java:383)         在org.objectweb.asm.MethodVisitor.visitEnd(未知来源)         在org.objectweb.asm.MethodVisitor.visitEnd(未知来源)         在org.objectweb.asm.ClassReader.b(未知来源)         在org.objectweb.asm.ClassReader.accept(未知来源)         在org.objectweb.asm.ClassReader.accept(未知来源)         在com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:401)         在com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326)         在com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280)         在com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:583)

失败:构建因异常而失败。

出了什么问题: 错误:任务':app:transformClassesWithDesugarForDebug'执行失败。

  

com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException:com.android.ide.common.process.ProcessException:使用com.google主类执行java进程时出错.devtools.build.android.desugar.Desugar with arguments {--input C:\ Users \ USERNAME \ .gradle \ _caches \ modules-2 \ files-2.1 \ org.apache.xmlbeans \ xmlbeans \ 2.6.0 \ 29e80d2dd51f9dcdef8f9ffaee0d4dc1c9bbfc87 \ xmlbeans-2.6.0.jar --output D:\ USERS \ PATH_TO_PROJECT \ app \ build \ intermediates \ transforms \ desugar \ debug \ 30.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ design-26.0.0.aar \ 88757c55175e8007a9a997cb5c307f06 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ appcompat-v7-26.0.0 .aar \ 9b22a71aa7416871ab6c4351056e3163 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ constraint-layout-1.0.2.aar \ 3113031e47d9da0b206f8a6d5dc5ddb5 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ cardview-v7-26.0.0.aar \ 44a7b81392464ba1ca65bd40f2e71204 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ gridlayout-v7-26.0.0.aar \ 0d2a4abaa9e93e5e2ca39f668099f366 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ acra-4.9.2。 aar \ a95cb5a22663d0060239228bd98b8433 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ transition-26.0.0.aar \ bf06e65e1453c6ecba1710c6d321fc23 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ adapters-1.3.1.aar \ 53fb1dbf25549b14049acaaa62d454b7 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ library-1.3.1.aar \ 54ece89f3ae5343b4010f6a6ec76b51c \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-v4- 26.0.0.aar \ 30b6c2f5af04a368bb3ba3da5a12978e \ jars \ classes.jar --classpath_entry C:\ Us ers \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ recyclerview-v7-26.0.0.aar \ ecbf0b20322f38889946e58312686426 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules -2 \ files-2.1 \ com.google.code.gson \ gson \ 2.8.0 \ c4ba5371a29ac9b2ad6129b1d39ea38750043eff \ gson-2.8.0.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files -2.1 \ com.annimon \ stream \ 1.1.7 \ a71f0635ac38194d70094e53f6fd89e00a93c834 \ stream-1.1.7.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ org.apache.poi \ poi-ooxml \ 3.16 \ 76e20fe22404cc4da55ddfdaaaadee32bbfa3bdd \ poi-ooxml-3.16.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ org.apache.poi \ poi \ 3.16 \ ad21c123ee5d6b5b2a8f0d4ed23b3ffe6759a889 \ poi-3.16.jar --classpath_entry D:\ android-studio-preview \ gradle \ m2repository \ com \ android \ databinding \ baseLibrary \ 3.0.0-beta1 \ baseLibrary-3.0.0-beta1.jar --classpath_entry C: \ Users \用户名\ .gradle \缓存\变换-1 \文件-1.1 \动画向量抽拉-26.0.0.aar \ e436cd2461e582de2e8dd0f296ecb608 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-vector-drawable-26.0.0.aar \ 0a153ef2b3a29b2746c4ade8c57868f8 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-fragment-26.0.0.aar \ 90abaab734f5b5dc1ebf43c2e1e6a5b7 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-core-ui-26.0.0.aar \ 0c1bca53056184d4f28ea1a21be505f5 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-media-compat-26.0.0.aar \ 912ee7959b738daba3efb4d6cb162083 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-core -utils-26.0.0.aar \ 8052717d55d9db1adc43a2838ce31976 \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms-1 \ files-1.1 \ support-compat-26.0.0.aar \ 69023f52457cfb4013657fbef040bfec \ jars \ classes.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ com.android.support \ support-annotations \ 26.0.0 \ db09a97f4f0db8892c1a0111a4b966f97920d082 \ support-annotations-26.0.0.jar --classpath_entry D:\ SOFTWARES \ AndroidSDK \ extras \ m2repository \ com \ android \ support \ constraint \ constraint-layout-solver \ 1.0.2 \ constraint-layout-solver-1.0.2.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ transforms- 1 \ files-1.1 \ multidex-1.0.1.aar \ f429f7a46c1e6dc7d9deaabf508265bf \ jars \ classes.jar --classpath_entry D:\ SOFTWARES \ android-studio-preview \ gradle \ m2repository \ commons-codec \ commons-codec \ 1.10 \ commons -codec-1.10.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ _caches \ modules-2 \ files-2.1 \ org.apache.commons \ commons-collections4 \ 4.1 \ a4cf4688fe1c7e3a63aa636cc96d013af537768e \ commons-collections4-4.1.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ _caches \ modules-2 \ files-2.1 \ org.apache.poi \ poi-ooxml-schemas \ 3.16 \ 9828a49307fc6bebfd42185b677d88b6e4994c63 \ poi-ooxml-schemas-3.16.jar - classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ com.github.virtuald \ curvesapi \ 1.04 \ 3386abf821719bc89c7685f9eaafaf4a842f0199 \ curvesapi-1.04.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ org.apache.xmlbeans \ xmlbeans \ 2.6.0 \ 29e80d2dd51f9dcdef8f9ffaee0d4dc1c9bbfc87 \ xmlbeans-2.6.0.jar --classpath_entry C:\ Users \ USERNAME \ .gradle \ caches \ modules-2 \ files-2.1 \ stax \ stax-api \ 1.0.1 \ 49c100caf72d658aca8e58bd74a4ba90fa2b0d70 \ stax-api-1.0.1.jar --classpath_entry D:\ USERS \ PATH_TO_PROJECT \ app \ build \ intermediates \ classes \ debug --bootclasspath_entry D:\ AndroidSDK \ platforms \ android-26 \ android .jar --bootclasspath_entry D:\ AndroidSDK \ platforms \ android-26 \ optional \ org.apache.http.legacy.jar --bootclasspath_entry D:\ SOFTWARES \ android-studio-preview \ jre \ jre \ lib \ resources.jar --bootclasspath_entry D:\ android-studio-preview \ jre \ jre \ lib \ rt.jar --bootclasspath_entry D:\ android-studio-preview \ jre \ jre \ lib \ jsse.jar --bootclasspath_entry D:\ android- studio-preview \ jre \ jre \ lib \ jce.jar --bootclasspath_entry D:\ andr oid-studio-preview \ jre \ jre \ lib \ charsets.jar --min_sdk_version 16 --desugar_try_with_resources_if_needed --desugar_try_with_resources_omit_runtime_classes}

我搜索了' app:transformClassesWithDesugarForDebug'作为关键字,但我得到的只是解决方案' app:transformClassesWithDexForDebug'。

请提供解决方案的链接并解释。我知道desugar将类文件转换为desugared类文件(以启用新功能),正如我在Android文档here上所读到的那样。我需要知道哪些文件出现了这些错误。

注意:我甚至在gradle中设置了 multiDexEnabled true ,但仍然是同样的错误。请给我解决这个问题,也请在错误堆栈中看到粗线,我认为这是答案的线索,但我无法找到它。为了时间的缘故,我使用了HSSFWorkbook(xls),但我需要XSSFWorkbook来创建xlsx文件。

...谢谢

1 个答案:

答案 0 :(得分:0)

更改您的项目/ build.gralde

compileOptions {
        //sourceCompatibility JavaVersion.VERSION_1_8
        //targetCompatibility JavaVersion.VERSION_1_8
    }

重建.......好的, 我改变了这个文件。 rebuild ......编译apk成功! 希望它能帮到你