Android 使用javafx和apachepoi对项目执行dex时出错

Android 使用javafx和apachepoi对项目执行dex时出错,android,gradle,javafx,apache-poi,gradle-eclipse,Android,Gradle,Javafx,Apache Poi,Gradle Eclipse,我正试图在Android上使用ApachePOI来实现这一点,我在eclipse上创建了一个gradle项目,但是当我执行gradle任务androidInstall时,我在dex步骤中遇到了一个错误。(运行任务正在运行) 下面是错误: Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/EventFilter; Uncaught translation

我正试图在Android上使用ApachePOI来实现这一点,我在eclipse上创建了一个gradle项目,但是当我执行gradle任务androidInstall时,我在dex步骤中遇到了一个错误。(运行任务正在运行)

下面是错误:

Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/EventFilter;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/FactoryConfigurationError;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/FactoryFinder;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/FactoryFinder$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/FactoryFinder$ClassLoaderFinder;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/FactoryFinder$ClassLoaderFinderConcrete;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/Location;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/StreamFilter;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Ljavax/xml/stream/XMLEventFactory;

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:613)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
at com.android.dx.command.dexer.Main.run(Main.java:275)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.InterruptedException: Too many errors
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:605)
... 4 more
16:41:25.082 [ERROR] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:java] Java Result: 2
16:41:25.083 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Setting project property: dexResult -> 2
16:41:25.084 [DEBUG] [org.gradle.api.Project] Dex result value = 2
16:41:25.093 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':dex'
16:41:25.094 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :dex FAILED
16:41:25.095 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :dex (Thread[Daemon worker Thread 2,5,main]) completed. Took 2 mins 19.455 secs.
16:41:25.095 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 2,5,main]] finished, busy: 21 mins 29.722 secs, idle: 0.053 secs
16:41:25.103 [ERROR] [org.gradle.BuildExceptionReporter] 
16:41:25.108 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:41:25.109 [ERROR] [org.gradle.BuildExceptionReporter] 
16:41:25.109 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:41:25.109 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':dex'.
16:41:25.110 [ERROR] [org.gradle.BuildExceptionReporter] > warning: Ignoring InnerClasses attribute for an anonymous inner class
16:41:25.110 [ERROR] [org.gradle.BuildExceptionReporter]   (org.apache.xmlbeans.XmlBeans$1) that doesn't come with an
16:41:25.111 [ERROR] [org.gradle.BuildExceptionReporter]   associated EnclosingMethod attribute. This class was probably produced by a
16:41:25.111 [ERROR] [org.gradle.BuildExceptionReporter]   compiler that did not target the modern .class file format. The recommended
16:41:25.112 [ERROR] [org.gradle.BuildExceptionReporter]   solution is to recompile the class from source, using an up-to-date compiler
16:41:25.112 [ERROR] [org.gradle.BuildExceptionReporter]   and without specifying any "-target" type options. The consequence of ignoring
16:41:25.112 [ERROR] [org.gradle.BuildExceptionReporter]   this warning is that reflective operations on this class will incorrectly
16:41:25.115 [ERROR] [org.gradle.BuildExceptionReporter]   indicate that it is *not* an inner class.
16:41:25.115 [ERROR] [org.gradle.BuildExceptionReporter]   warning: Ignoring InnerClasses attribute for an anonymous inner class
16:41:25.116 [ERROR] [org.gradle.BuildExceptionReporter]   (org.apache.xmlbeans.XmlSimpleList$1) that doesn't come with an
16:41:25.140 [ERROR] [org.gradle.BuildExceptionReporter]   associated EnclosingMethod attribute. This class was probably produced by a
16:41:25.140 [ERROR] [org.gradle.BuildExceptionReporter]   compiler that did not target the modern .class file format. The recommended
16:41:25.140 [ERROR] [org.gradle.BuildExceptionReporter]   solution is to recompile the class from source, using an up-to-date compiler
16:41:25.141 [ERROR] [org.gradle.BuildExceptionReporter]   and without specifying any "-target" type options. The consequence of ignoring
16:41:25.141 [ERROR] [org.gradle.BuildExceptionReporter]   this warning is that reflective operations on this class will incorrectly
16:41:25.141 [ERROR] [org.gradle.BuildExceptionReporter]   indicate that it is *not* an inner class.
16:41:25.141 [ERROR] [org.gradle.BuildExceptionReporter]   warning: Ignoring InnerClasses attribute for an anonymous inner class
16:41:25.142 [ERROR] [org.gradle.BuildExceptionReporter]   (org.apache.xmlbeans.XmlSimpleList$2) that doesn't come with an
16:41:25.142 [ERROR] [org.gradle.BuildExceptionReporter]   associated EnclosingMethod attribute. This class was probably produced by a
16:41:25.142 [ERROR] [org.gradle.BuildExceptionReporter]   compiler that did not target the modern .class file format. The recommended
16:41:25.142 [ERROR] [org.gradle.BuildExceptionReporter]   solution is to recompile the class from source, using an up-to-date compiler
16:41:25.143 [ERROR] [org.gradle.BuildExceptionReporter]   and without specifying any "-target" type options. The consequence of ignoring
16:41:25.143 [ERROR] [org.gradle.BuildExceptionReporter]   this warning is that reflective operations on this class will incorrectly
16:41:25.143 [ERROR] [org.gradle.BuildExceptionReporter]   indicate that it is *not* an inner class.
...
我读到我需要添加这个来忽略警告,但我在CompileSDK版本上遇到了另一个错误

lintOptions {
    abortOnError false
}
这是我的build.gradle文件:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b8'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = "JavaFXStage"
version = '1.0'

repositories {
    jcenter()
}

jfxmobile {
    ios {
        forceLinkClasses = ['ensemble.**.*']
    }

    android {

        javafxportsVersion = '8u40-b5'
        compileSdkVersion  = 23     
        applicationPackage = 'any.package.name' 

    }
}

dependencies{
    def poiVersion = "3.10.1"
    compile "org.apache.poi:poi:${poiVersion}"
    compile "org.apache.poi:poi-ooxml:${poiVersion}"
    compile "org.apache.poi:ooxml-schemas:1.1"
    compile "org.apache.xmlbeans:xmlbeans:2.6.0"
}
如果你需要更多关于这个项目的信息,请毫不犹豫地询问

如果你有什么建议来解决我的问题,谢谢


托马斯

由于诸多限制,在Android上使用ApachePOI并不是现成的。其中之一是xmlbeans jar多次包含某些类,这让Android编译器感到困惑。pacakge
javax
中的代码以及代码的大小也存在一些问题

目前有两个项目试图解决这一问题:

  • (由我保管)

两者都试图通过将类重新打包到一个更紧凑的jar文件中来解决这个问题,然后将该文件添加到Android应用程序中
Android5xlsx
目前基于POI 3.12,android上的POI基于3.15-beta1,可以很容易地根据POI的最新版本重新构建。

我通过在gradle构建中排除xmlbeans,解决了Dex步骤中的错误。构建:

compile 'org.apache.poi:poi:3.16'
compile ('org.apache.poi:poi-ooxml:3.16') {
    exclude group: 'org.apache.xmlbeans', module: 'xmlbeans'
}
在我的java代码中,我没有使用xmlbeans,而是使用其他解析器。这是我的导入列表:

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

xmlbeans似乎已经过时(最近一次更新于2012年,宣布于2014年过时)。你为什么还在用它?你能在没有它的情况下编译你的项目吗?我在没有xmlbeans的情况下编译它,但我仍然有相同的错误。你所附的错误日志特别提到xmlbeans。新的错误日志是什么?我仔细检查了日志文件,它仍然是我的观点所在的同一个文件-仍然有很多错误引用xmlbeans,这意味着仍然有一些东西引用它。我对android和gradle的了解还不足以告诉你该去哪里找,但在某个地方,一定还有对xmlbeans的引用。我使用了第二个链接,因为在您的项目中,您正在使用lint选项来解决问题,我不能像我之前所说的那样,现在我设法将应用程序安装到我的设备上,但当我尝试启动应用程序时,会出现黑屏。我将在日志文件中挖掘。