I have a requirement in my app to implement excel creation and download. I have used Apache POI's HSSFWorkbook to implement the functionality. The app created the required excel (xls) output successfully.
However if I include apache:poi-ooxml in gradle and use XSSFWorkbook to create xlsx file for the same, I am getting the following error:
D:\USERS\PATH_TO_PROJECT>gradlew build
Configure project :app Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
Task :app:compileDebugJavaWithJavac Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
Exception in thread "main" java.lang.IllegalStateException: Expect only the fields in this interface to be initialized. owner=org/apache/xmlbeans/impl/xb/ltgfmt/Code$1, expected=org/apache /xmlbeans/impl/xb/ltgfmt/Code at com.google.common.base.Preconditions.checkState(Preconditions.java:721) at com.google.devtools.build.android.desugar.InterfaceDesugaring$InterfaceFieldWriteCollector.visitFieldInsn(InterfaceDesugaring.java:260) at org.objectweb.asm.MethodVisitor.visitFieldInsn(Unknown Source) at org.objectweb.asm.tree.FieldInsnNode.accept(Unknown Source) at org.objectweb.asm.tree.InsnList.accept(Unknown Source) at org.objectweb.asm.tree.MethodNode.accept(Unknown Source) at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitEnd(LambdaDesugaring.java:383) at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source) at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source) at org.objectweb.asm.ClassReader.b(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:401) at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326) at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280) at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:583)
FAILURE: Build failed with an exception.
What went wrong: Error:Execution failed for task ':app:transformClassesWithDesugarForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.google.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:\Users\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\USERNAME\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-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:\android-studio-preview\jre\jre\lib\charsets.jar --min_sdk_version 16 --desugar_try_with_resources_if_needed --desugar_try_with_resources_omit_runtime_classes}
I have searched with 'app:transformClassesWithDesugarForDebug' as keyword, but all I get is solution 'app:transformClassesWithDexForDebug'.
Please provide link for solution and explain. I know that desugar transforms class files to desugared class files (to enable new features), as I read on Android docs here. I need to know what files are making these errors.
NOTE: I have even set the multiDexEnabled true in gradle, still same error. Please give me solution for this problem, also please see bold lines in the error stack, I think that is the clue to the answer but I am unable to find it. For time sake, I have used HSSFWorkbook(xls), but I need XSSFWorkbook to create xlsx file.
Thanks...