Я использую Android studio 1.5.1интеграция org.apache.poi и javax.xml.stream. * Package (stax-api) в android - как установить аргумент -core-library в Android Studio?
Я хотел бы включить библиотеку org.apache.poi-ooxml в свой проект андроида. Чтобы включить эту библиотеку, мне нужно было включить некоторые другие зависимости библиотеки, среди которых библиотека stax-api.
Проблема с stax api заключается в том, что он имеет все пакеты в javax. *, Который является «основной библиотекой». Java jdk включает все эти библиотеки, поэтому, если бы я использовал его в Java SE, мне не понадобилась бы эта библиотека stax-api. Android, с другой стороны, имеет «частичную» библиотеку stax-api. Для android мне нужен пакет javax.xml.stream. *. Это означает, что мне нужно извлечь stax-api, удалить все, кроме пакета javax.xml.stram, и повторно упаковать его снова.
Так что, я думаю, что использовать эту модифицированную библиотеку в Android можно. Но, он имеет javax * пакет, который, в соответствии с Android студии является библиотека ядра, так что Android Studio (или любой другой компонент в Android Studio) дает мне предупреждение:.
trouble processing "javax/xml/stream/EventFilter.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.
This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on.
However, you might actually be trying to define a class in a core namespace, the source of which you may have taken, for example, from a non-Android virtual machine project. This will most assuredly not work. At a minimum, it jeopardizes the compatibility of your app with future versions of the platform. It is also often of questionable legality.
If you really intend to build a core library -- which is only appropriate as part of creating a full virtual machine distribution, as opposed to compiling an application -- then use the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact building an application, then be forewarned that your application will still fail to build or run, at some point. Please be prepared for angry customers who find, for example, that your application ceases to function once they upgrade their operating system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a core package, then the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace. This means that they will never be in conflict with core system classes. JarJar is a tool that may help you in this endeavor. If you find that you cannot do this, then that is an indication that the path you are on will ultimately lead to pain, suffering, grief, and lamentation.
Итак, я хотел бы для использования этой опции -core-library. Но где его установить?
Я уже смотрел Android Studio ignore --core-library flag, который мне не помог. Я думаю, что эти ответы устарели, и именно поэтому я задаю новый вопрос.
Что я сделал попробовать:
build.gradle:
dexOptions { coreLibrary true; }
build.gradle:
dexOptions { preDexLibraries = false } project.tasks.withType(com.android.build.gradle.tasks.Dex) { additionalParameters=['--core-library'] }
Файл -> Другие настройки - > Настройки по умолчанию -> Компиляторы -> Компиляторы Android и установите флажок «Добавить флаг библиотеки»
Ничего из этого не произошло. Есть ли способ установить этот параметр?
EDIT: Почему мне нужно Stax: Я делаю некоторые вещи с Workbook, Лист, Столбцы, клетки для .xlsx файлов. Когда я включаю только poi-ooxml-3.14-beta1-20151223.jar
Я получаю ошибку во время сборки, говоря class file for org.apache.poi.ss.usermodel.Workbook not found
.
После включения poi-3.14-beta1-20151223.jar во время выполнения я получаю, среди прочих, Could not find method org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.isSetBookViews, referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook
.
После включая poi-ooxml-schemas-3.14-beta1-20151223.jar
во время выполнения я получаю, среди прочего, Failed resolving Lorg/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook; interface 59 'Lorg/apache/xmlbeans/XmlObject;
и java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook
После включая xmlbeans-2.6.0.jar
во время выполнения я получаю, среди прочего, Could not find method javax.xml.stream.events.Namespace.getPrefix, referenced from method org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.getQName
и java.lang.NoClassDefFoundError: javax.xml.stream.XMLEventFactory at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
UPDATE Так, из http://poi.apache.org/faq.html#faq-N1017E
18. Why do I get a java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventFactory.newFactory()
This error indicates that the class XMLEventFactory does not provide functionality which POI is depending upon. There can be a number of different reasons for this:
Outdated xml-apis.jar, stax-apis.jar or xercesImpl.jar:
- These libraries were required with Java 5 and lower, but are not actually required with spec-compliant Java 6 implementations, so try removing those libraries from your classpath. If this is not possible, try upgrading to a newer version of those jar files.
- Running IBM Java 6 (potentially as part of WebSphere Application Server): IBM Java 6 does not provide all the interfaces required by the XML standards, only IBM Java 7 seems to provide the correct interfaces, so try upgrading your JDK.
- Sun/Oracle Java 6 with outdated patchlevel: Some of the interfaces were only included/fixed in some of the patchlevels for Java 6. Try running with the latest available patchlevel or even better use Java 7/8 where this functionality should be available in all cases.
Итак, если I r EAD это правильно, в Android, мне нужен «усеченный» STAX api.
STAX не требуется для последних версий Apache POI. Что произойдет, если вы попробуете обновить? – Gagravarr
Я обновил вопрос, чтобы «оправдать» использование STAX – SlumpA
См. [Страница компонентов POI Apache] (http://poi.apache.org/overview.html#components) для получения подробных сведений о том, какие биты POI имеют зависимости: следуя советам, вы устраните недостающие проблемы класса – Gagravarr