2010-11-25 80 views
3

我正在嘗試使用Ant編譯我的Flex 4項目。我可以編譯主應用程序,我可以編譯我的一些模塊。任何在子包中都有依賴的模塊沒有說Error: Type was not found or was not a compile-time constant。我使用Flash Builder 4在Windows上完成了所有的開發工作,因此我可以編譯所有內容,但是我需要將編譯工作轉移到基於Linux的無頭的服務器上(這是Ant進來的地方)。使用Ant編譯Flex模塊

我創建了一個簡單的項目來測試我的問題:

src-> Main.mxml 
|->modules 
     |-> module1-> Module1.mxml 
     |-> module2-> Module2.mxml 
       |-> subPackage-> SubClass.as 

模塊1不使用其他類則Flex框架類,其中單詞數有子類的實例。編譯主應用程序工作正常,Module1也是如此。當它試圖編譯Module2時,我得到錯誤Error: Type was not found or was not a compile-time constant: SubClass.

我的全Ant腳本是:

<project name="Test" basedir="."> 

<property file="build.properties" /> 
<target name="properties"> 
    <fail unless="mxmlc">The "mxmlc" property must be set in build.properties.</fail> 
</target> 

<target name="build-app" depends="properties"> 
    <exec executable="${mxmlc}" dir="${src.dir}" failonerror="true"> 

     <!-- Point to the mxml file --> 
     <arg line="${app.name}.mxml" /> 

     <!-- Don\t generate debug swf --> 
     <arg line="-debug=false" /> 

     <!-- Generate optimized swf --> 
     <arg line="-optimize=true" /> 

     <!-- Don't build incrementally --> 
     <arg line="-incremental=false" /> 

     <!-- Place the built .swf file in the "bin" directory --> 
     <arg line="-output '${build.dir}/${app.name}.swf'" /> 

     <!-- 
      Create a linker report that lists all the classes already in the main app 
      This gets passed to the modules so that they don't load up the shared libs again. 
     --> 
     <arg line="-link-report='${temp.dir}/link-report.xml'"/> 

    </exec> 
</target> 

<target name="build-modules" description="Build Modules"> 
    <build.module dir="${module.dir}/module1" file="Module1"/> 
    <build.module dir="${module.dir}/module2" file="Module2"/> 
</target> 

<macrodef name="build.module"> 
    <attribute name="dir" /> 
    <attribute name="file" /> 
    <sequential> 
     <echo>@{file}</echo> 
     <exec executable="${mxmlc}" dir="${src.dir}" failonerror="true"> 
      <!-- Point to the mxml file --> 
      <arg line="'@{dir}/@{file}.mxml'" /> 

      <!-- Don't generate debug swf --> 
      <arg line="-debug=false" /> 

      <!-- Generate optimized swf --> 
      <arg line="-optimize=true" /> 

      <!-- Don't build incrementally --> 
      <arg line="-incremental=false" /> 

      <!-- Place the built .swf file in the "bin" directory --> 
      <arg line="-output '${module.build.dir}/@{file}.swf'" /> 

      <!-- Exclude all classes that are already in the main application --> 
      <arg line="-load-externs='${temp.dir}/link-report.xml'"/> 
     </exec> 
    </sequential> 
</macrodef> 

我完全茫然,爲什麼這是行不通的。

感謝,

--Ryan

+0

你是什麼意思的「分裝」?這些類是在同一個基本源目錄中,還是不同的? – 2010-11-26 10:00:59

+0

在src目錄中有一個名爲「modules」的目錄,其中有2個名爲「module1」和「module2」的目錄。 「module2」包含一個名爲「subPackage」的目錄,其中包含類「SubClass.as」。換句話說,所討論的3個類是:modules.module1.Module1; modules.module2.Module2; modules.module2.subPackage.SubClass。 – Ryan 2010-11-30 13:47:55

回答

3

大量的研究,試驗和錯誤和咒罵後,我終於找到了解決辦法。最初我試圖使用ANTs <exec>命令編譯模塊。在我的最終解決方案中,我確實將其更改爲使用ANT的<mxmlc>目標(從flex SDK目錄ant/lib/flexTasks.jar中的flexTasks.jar)。

<macrodef name="build.module"> 
    <attribute name="moduleDir" /> 
    <attribute name="dir" /> 
    <attribute name="file" /> 
    <sequential> 
     <echo>@{file}</echo> 
     <mxmlc file="@{moduleDir}/@{dir}/@{file}.mxml" 
       output='${module.build.dir}/@{dir}/@{file}.swf' 
       optimize="true" 
       debug="false" 
       load-externs="${temp.dir}/link-report.xml" 
       incremental="false" 
       fork="true" maxmemory="${maxMem}"> 
      <compiler.source-path path-element="${src.dir}"/> 
      <source-path path-element="${FLEX_HOME}/frameworks"/> 
      <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true"> 
       <include name="libs" /> 
      </compiler.library-path> 
      <source-path path-element="${src.dir}"/> 
      <compiler.library-path dir="${libs.dir}/" append="true"> 
       <include name="*" /> 
      </compiler.library-path> 
     </mxmlc> 
    </sequential> 
</macrodef> 

在這個新的宏中,我添加了更多的編譯器選項。在設置源路徑和編譯器庫選項(這告訴編譯器要鏈接什麼)後,一切運行良好。