2015-10-13 109 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