开发者

Compiling Flex modules with Ant

I'm trying to compile my Flex 4 project using Ant. I can compile the main application fine and I can compile some of my modules fine. Any module that has dependencies in a sub package is failing saying E开发者_JAVA百科rror: Type was not found or was not a compile-time constant. I do all my development on Windows using Flash Builder 4 so I can compile everything but what I need to do is move the compiling to a headless Linux based server (which is where Ant comes in).

I've created a simple project to test my problem:

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

Module1 uses no classes other then Flex framework classes where Module2 has an instance of SubClass. Compiling the main application works fine and so does Module1. When it tries to compile Module2 I get the error Error: Type was not found or was not a compile-time constant: SubClass..

My full Ant script is:

<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>

I'm at a complete loss as to why this doesn't work.

Thanks,

--Ryan


After much research, trial and error and cursing I finally found the solution. Originally I was trying to compile the modules using ANTs <exec> command. In my final solution I did change it to use the <mxmlc> target for ANT (from flexTasks.jar in your Flex SDK directory ant/lib/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>

In this new macro I added a couple more compiler options. After setting the source path and compiler library options (this tells the compiler what to link against) everything worked great.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜