Bug 58925

Summary: IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/XMLEvent
Product: POI Reporter: Rowan <rowan.tarek>
Component: XWPFAssignee: POI Developers List <dev>
Status: RESOLVED INVALID    
Severity: blocker    
Priority: P2    
Version: 3.13-FINAL   
Target Milestone: ---   
Hardware: Other   
OS: All   
Bug Depends on: 59268    
Bug Blocks:    

Description Rowan 2016-01-27 16:42:52 UTC
Integrating POI to Android. 
Referencing poi, poi_ooxml and xml-beans results in Uncaught translation error: java.lang.IllegalArgumentException: already added for multiple classes. Classes of issue are:
1- Lorg/apache/xmlbeans/xml/stream/Location;
2- Lorg/apache/xmlbeans/xml/stream/ReferenceResolver;
3- Lorg/apache/xmlbeans/xml/stream/XMLEvent;
4- Lorg/apache/xmlbeans/xml/stream/XMLInputStream;
5- Lorg/apache/xmlbeans/xml/stream/XMLName;
6- Lorg/apache/xmlbeans/xml/stream/XMLStreamException;
7- Lorg/apache/xmlbeans/xml/stream/utils/NestedThrowable;
8- Lorg/apache/xmlbeans/xml/stream/utils/NestedThrowable$Util;

removing any of the jar files mentioned causes dependency error.

Full log:
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/Location;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/ReferenceResolver;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/XMLEvent;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/XMLInputStream;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/XMLName;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/XMLStreamException;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/utils/NestedThrowable;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/utils/NestedThrowable$Util;
8 errors; aborting
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1
Comment 1 Nick Burch 2016-01-27 16:45:55 UTC
This is an xmlbeans bug, not a POI bug - their 2.6 release jar seems to have some duplicate classes in. You need one of: a fixed xmlbeans jar, a different (earlier) runtime jar, to unpack+repack yourself to remove the duplicates, or to tell your environment to ignore the error
Comment 2 Rowan 2016-01-28 12:59:02 UTC
Thanks for directing me to the right way.
I edited the xml-beans jar and got it to build. Unfortunately, I got a runtime exception of
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLEventFactory;

Googling it and it seems it takes so many workarounds to get POI to work.
A feature-needed but sadly lot of hacks and workarounds to run.