2015-10-13 44 views
0

我试图让j2objc运行在gradle项目中的一些java模块上。我使用j2objc的gradle插件,但我不相信这是任何问题的根源。该模块使用XMLUnit来检测输入文件的差异。 XMLUnit包含一个org.xmlunit.builder.JaxbBuilder类,由于没有看到j2objc中省略的一些javax类,可能会因翻译失败而导致翻译失败。无论如何,我的代码不会使用JaxbBuilder类,因此我创建了一个死代码报告以省略它。我知道我可以使用proguard生成一个更完整的集合,但现在,我的重点仅仅是防止尝试这个类,因为我仍然在为所有这些构建一个gradle CI流水线。这份报告的题目是dead_code.log,仅包含以下行:j2objc不尊重死代码报告

org.xmlunit.builder.JaxbBuilder

的j2objc插件配置规定为:

j2objcConfig { 
    autoConfigureDeps true 
    // Xcode workspace directory 
    xcodeProjectDir '../ios' 

    translateArgs '--dead-code-report', './dead_code.log' 
    translateArgs '--doc-comments' 
    translateArgs '-v' 

    finalConfigure()   // Must be last call to configuration 
} 

而且我可以在加死码参数在日志中看到到命令行,但在执行我然后看到:

INEST: parsing jar:file:/Users/jenkins/.gradle/caches/modules-2/files-2.1/org.xmlunit/xmlunit-core/2.0.0-SNAPSHOT/b11b5e5d8e9f223af2fbaa93982d17b55899498/xmlunit-core-2.0.0-SNAPSHOT-sources.jar!org/xmlunit/builder/JaxbBuilder.java error: org/xmlunit/builder/JaxbBuilder.java:19: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:20: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:21: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:22: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:23: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:24: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:25: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:26: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:27: The import javax.xml.bind cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:31: The import java.beans.Introspector cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:43: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:56: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:57: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:82: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:83: The method createDefaultMarshaller() from the type JaxbBuilder refers to the missing type JAXBException error: org/xmlunit/builder/JaxbBuilder.java:87: JAXBSource cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:87: JAXBSource cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:87: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:92: JAXBException cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:93: DataBindingException cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:99: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:103: XmlRootElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:103: Bound mismatch: The generic method getAnnotation(Class) of type AnnotatedElement is not applicable for the arguments (Class). The inferred type XmlRootElement is not a valid substitute for the bounded parameter error: org/xmlunit/builder/JaxbBuilder.java:103: XmlRootElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:106: The method createJAXBElement(Object) from the type JaxbBuilder refers to the missing type JAXBElement error: org/xmlunit/builder/JaxbBuilder.java:108: The method createInferredJAXBElement(Object) from the type JaxbBuilder refers to the missing type JAXBElement error: org/xmlunit/builder/JaxbBuilder.java:117: JAXBException cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:117: PropertyException cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:118: JAXBContext cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:119: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:120: JAXBContext cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:120: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:120: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:123: JAXBContext cannot be resolved error: org/xmlunit/builder/JaxbBuilder.java:125: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:126: Marshaller cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:126: Marshaller cannot be resolved to a variable error: org/xmlunit/builder/JaxbBuilder.java:130: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:133: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:136: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:137: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:137: The method createJaxbElementFromObjectFactory(T) from the type JaxbBuilder refers to the missing type JAXBElement error: org/xmlunit/builder/JaxbBuilder.java:139: The method createInferredJAXBElement(T) from the type JaxbBuilder refers to the missing type JAXBElement error: org/xmlunit/builder/JaxbBuilder.java:146: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:156: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:161: JAXBElement cannot be resolved to a type error: org/xmlunit/builder/JaxbBuilder.java:174: Introspector cannot be resolved

我认为这意味着它试图处理是JaxbBuilder类。配置中是否有某些我缺少的东西?

回答

2

j2objc的第一个翻译步骤是调用Eclipse Java编译器,因此需要解析死代码引用以便翻译器继续执行,即使带有这些引用的类稍后会由死代码消除步骤删除。添加一个jar文件来解析javax.xml.bind类(如jaxb-api.jar)将清除大部分这些错误。

但java.beans.Introspector仍然是一个问题,因为它不是Android API的一部分,j2objc的JRE支持基于Android源。由于该类及其引用将被删除,因此可以尝试将JVM的rt.jar指定为转换程序的bootclasspath(-Xbootclasspath:flag)。翻译通常使用与j2objc的JRE库匹配的jar,所以不支持的类会提前报告。指定一个JVM rt.jar作为bootclasspath,可以解决此错误检查问题,但可以解析不支持的类。

由于上述听起来很多工作,你有另一种选择是要求对j2objc的gradle这个插件有一个排除选项,类似:

j2objcConfig { 
    ... 
    translateArgs '-v' 
    exclude 'org.xmlunit.builder.JaxbBuilder' 
    ... 

为j2objc队gradle这个插件是独立的来自j2objc's,但他们对这种合理的功能要求非常敏感。

+0

谢谢。现在我试着指定引导类路径,它工作。违规进口已经解决,但是这个违规类已经被翻译了。我想如果代码试图使用它的东西会失败,但我至少能够导出我需要的代码。一个让我前进的临时解决方案。我还会要求你建议的插件选项。 – Jared

+0

Jared - 你能否在插件问题页面上写下请求:https://github.com/j2objc-contrib/j2objc-gradle/issues/ – brunobowden