Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android duplicate class error when including Apache POI

I've got a problem with the apache poi excel api (xlsx). I'm using android studio and I've added the poi libs to the "libs" folders. This error is popping up for some reason (see below). How would I solve it?, could you please explain how you identified the issue?

xmlbeans-2.6.0, poi-ooxml-schemas-3.10.1-20140818, poi-ooxml-3.10.1-20140818, poi-3.10.1-20140818, log4j-1.2.13, junit-4.11, dom4j-1.6.1, commons-logging-1.1, commons-codec-1.5

Thanks!

My build.gradle looks like the following (excluding the generic other stuff)...

dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') }

android { packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } }

My app.iml has no duplicate entries either...

Error

Error:Class org.apache.xmlbeans.xml.stream.Location has already been added to output. Please remove duplicate copies. compiler that did not target the modern .class file format. The recommended (org.apache.log4j.chainsaw.ControlPanel$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a solution is to recompile the class from source, using an up-to-date compiler 1 error; aborting

like image 864
Douglas Johgn Avatar asked Sep 21 '14 01:09

Douglas Johgn


2 Answers

Please note that there are a number of problems that you might run into when using Apache POI on Android. The duplicate classes in XmlBeans can currently only be avoided by re-packaging the jar.

There are currently two projects which try to solve most of the problems for you, both re-package all classes including any dependencies into a single jar-file to make it easier to deploy. Also some shading is done to avoid problems with javax-namespace which Android does not allow.

  1. https://github.com/andruhon/android5xlsx
  2. https://github.com/centic9/poi-on-android/ (mainted by me)

The first one is currently based on POI 3.12, whereas the second can be re-compiled with newer versions of POI more easily.

like image 149
centic Avatar answered Oct 04 '22 16:10

centic


The xmlbeans 2.6 JAR from Maven Central contains some duplicate class entries. The XMLBeans JIRA has an issue open for the problem. Until they publish a new JAR, I think I'm going to unzip the jar, which will overwrite the duplicates, then re-zip it up and put it in my libs dir for now.

like image 20
Robert St. John Avatar answered Oct 04 '22 16:10

Robert St. John