How can I speed up MXMLC compiles? - apache-flex

I am using ant to build my web application. I have a target in my ant script which takes approximately 8 minutes to compile. Since mxmlc compiles everything from scratch and loads up the JVM each time, it is taking a lot of time. Is there a way to optimize this task?
I am using Flex SDK 3.0. Here is my ant target:
<target name="compile.organic.flash" depends="setup">
<property name="WelcomeBack.swf" value="${www.dir}/swf/as3/apps/welcome/WelcomeBack.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/welcome/src/WelcomeBack.as"
output="${WelcomeBack.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
accessible="true"
default-background-color="${swf.backgrond.color}"
allow-source-path-overlap="true"
compiler.strict="true">
<default-size width="940" height="528" />
<source-path path-element="${Welcome.path}"/>
<source-path path-element="${AS3.classpath}"/>
</mxmlc>
<property name="Welcome.swf" value="${www.dir}/swf/as3/apps/welcome/Welcome.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/welcome/src/Welcome.as"
output="${Welcome.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
accessible="true"
default-background-color="${swf.backgrond.color}"
allow-source-path-overlap="true"
compiler.strict="true">
<default-size width="940" height="528" />
<source-path path-element="${Welcome.path}"/>
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="App.swf" value="${www.dir}/swf/as3/apps/App-${svnVersion}.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/App.as"
output="${App.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
default-background-color="${swf.backgrond.color}"
compiler.strict="true">
<default-size width="300" height="300" />
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="LSOApp.swf" value="${www.dir}/swf/as3/apps/LSOApp-${svnVersion}.swf" />
<mxmlc file="${AS3.classpath}/com/organic/boa/fthb/LSOApp.as"
output="${LSOApp.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
default-background-color="${swf.backgrond.color}"
compiler.strict="true">
<default-size width="300" height="300" />
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="CheckRates.swf" value="${www.dir}/swf/as3/apps/CheckRates-${svnVersion}.swf" />
<mxmlc file="${CheckRates.path}/CheckRates.as"
output="${CheckRates.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="40"
accessible="true"
default-background-color="${swf.backgrond.color}"
compiler.strict="true" compiler.allow-source-path-overlap="true" >
<default-size width="940" height="528" />
<compiler.source-path path-element="${AS3.classpath}"/>
<compiler.source-path path-element="${CheckRates.path}"/>
<!-- <source-path path-element="${AS3.classpath}"/> -->
<compiler.include-libraries dir="${AS3.classpath}">
<include name="fl/fl.swc" />
</compiler.include-libraries>
</mxmlc>
<copy file="${AS3.classpath}/com/organic/app/fthb/checkRates/js/config/check_rates_config.js" tofile="${www.dir}/swf/as3/apps/config/check_rates_config.js"/>
<property name="PointsCalculator.swf" value="${www.dir}/swf/as3/apps/PointsCalculator-${svnVersion}.swf" />
<property name="flash.apps.build.dir" value="${www.dir}/swf/as3/apps" />
<compile-flash basename="PointsCalculator" srcdir="${flash.apps.src.dir}/pointsCalculator">
</compile-flash>
<copy todir="${flash.apps.build.dir}/config">
<fileset dir="${flash.apps.src.dir}/pointsCalculator/config" includes="*.js"/>
</copy>
<copy todir="${build.dir}/www/css">
<fileset dir="${flash.apps.src.dir}/pointsCalculator/css" includes="*.css"/>
</copy>
<copy todir="${build.dir}/www/swf/as3/apps/welcome/assets/swfs">
<fileset dir="${flash.apps.src.dir}/welcome/assets/swfs" includes="*.swf"/>
</copy>
<copy file="${videoplayer.dir}/videoplayer.swf" tofile="${www.dir}/swf/as3/apps/videoplayer.swf" />
</target>

Use fcsh. From the first paragraph of that link
The fcsh (Flex Compiler Shell) utility provides a shell environment
that you use to compile Flex applications, modules, and component
libraries. It works very similarly to the mxmlc and compc command line
compilers, but it compiles faster than the mxmlc and compc
command-line compilers. One reason is that by keeping everything in
memory, fcsh eliminates the overhead of launching the JVM and loading
the compiler classes. Another reason is that compilation results (for
example, type information) can be kept in memory for subsequent
compilations.

We found that what was slowing down the compiler was mostly linking assets. We made a library project swf that is just used for assets (images, swfs, etc.) except fonts, and it works a treat.
We have a massive project building under 2 mins from maven.

Related

How to export Flash builder air mobile project to swf

I have created a flex mobile as3 project that exports to air, to ipa and apk.
This project does not use any specific to mobile or air calls (camera, files. .)
my question is : how do I create a swf ?
Regards
Since your project doesn't use any AIR-specific APIs, you can use an Ant build to create a SWF from your mobile project. The following build file will do the trick if your project is self-contained as a single Flash Builder project.
<?xml version="1.0" ?>
<project name="Build" default="build">
<property name="FLEX_HOME" value="C:/Program Files/Adobe/Adobe Flash Builder 4.7/sdks/4.6.0" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<property name="PROJECT_NAME" value="MyMobileProject" />
<property name="PROJECT_BASE_DIR" value="C:/FlexProjects/${PROJECT_NAME}" />
<property name="PATH_TO_SRC_FOLDER" value="${PROJECT_BASE_DIR}/src" />
<property name="OUTPUT_DIR" value="${PROJECT_BASE_DIR}/bin" />
<target name="build">
<mxmlc file="${PATH_TO_SRC_FOLDER}/${PROJECT_NAME}.mxml"
output="${OUTPUT_DIR}/${PROJECT_NAME}.swf"
show-actionscript-warnings="false" show-binding-warnings="false"
locale="en_US" incremental="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${PATH_TO_SRC_FOLDER}" />
<external-library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</external-library-path>
<compiler.library-path dir="${PROJECT_BASE_DIR}/libs" append="true" includes="*"/>
</mxmlc>
</target>
</project>

Error "Could not resolve <s:SolidColorStroke>" When Trying to Compile a Flex 4 SWC with Ant

I'm trying to compile a component using ant and keep getting this error message throughout the component . . .
ButtonSkin.mxml(179): Error: Could not resolve <s:SolidColorStroke> to a component implementation.
ButtonSkin.mxml(210): Error: Could not resolve <s:GradientEntry> to a component implementation.
It compiles fine in FlashBuilder 4. Here is the contents of the build.xml:
<project name="Flex Ant Tasks Build Script" default="compile flex project">
<property name="FLEX_HOME" value="c:/build/flex_sdk" />
<property name="SDK_VERSION" value="4.1.0.16076" />
<taskdef resource="flexTasks.tasks" classpath="c:/build/flex_sdk/lib/flexTasks.jar"/>
<echo message="File: ${FLEX_HOME}"/>
<!-- Build and output the Main.swf-->
<target name="compile flex project">
<compc output="${basedir}/../FlexSI/libs/MyLibrary.swc" locale="en_US">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${basedir}/src"/>
<include-sources dir="${basedir}/src" includes="*" />
<library-path dir="${basedir}/libs" includes="*" append="true"/>
<namespace uri="http://testapp.com/siLibrary" manifest="${basedir}/src/xml/manifest.xml" />
</compc>
</target>
</project>
SolidColorStroke doesn't belong to Spark theme. Try to use mx:SolidColorStroke instead of s:SolidColorStroke. Same with GradientEntry.
Discussion on the related issue at forums.adobe.com.
Suggested workaround or solution is to explicitly specify all Spark (Flex4) and Halo (Flex3) related class namespaces, e.g.
<namespace uri="library://ns.adobe.com/flex/spark" manifest="${FLEX_HOME}/frameworks/spark-manifest.xml"/>
<namespace uri="http://ns.adobe.com/mxml/2009" manifest="${FLEX_HOME}/frameworks/mxml-2009-manifest.xml"/>
<namespace uri="http://www.adobe.com/2006/mxml" manifest="${FLEX_HOME}/frameworks/mxml-manifest.xml"/>

Run AsUnit runner from Ant

How can you run AsUnit test runner from Ant?
I'm on the Mac OS so I use:
open -a "flash player" tests.swf
How can I make this cross platform?
Here's a target that will compile the tests into a swf and run them. The tests are run using the exec task. This version uses the open command from the Mac OS.
For Windows I can only think of using a property set to the complete path to the Flash player exe and using that to run the tests.
<target name="tests">
<taskdef resource="flexTasks.tasks" classpath="${flextask.jar}" />
<mxmlc file="${test.main}" output="${tests.output}" incremental="true" debug="false" static-link-runtime-shared-libraries="true">
<source-path path-element="${tests.dir}"/>
<load-config filename="${flex.config}" />
<library-path dir="${flex.lib}" append="true">
<include name="flex.swc" />
</library-path>
<library-path dir="${libs.test.dir}" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
<exec executable="open" os="Mac OS X">
<arg line='-a "flash player" ${tests.output}' />
</exec>
</target>
Here's the properties:
# Build locations
src.dir=${basedir}/src/main/actionscript
package.dir=your/apps/package
libs.dir=${basedir}/libs
output.dir=${basedir}/bin
output.swc=${output.dir}/${project.name.versioned}.swc
# testing
tests.dir=${basedir}/src/test/actionscript
tests.output=${output.dir}/${ant.project.name}-tests.swf
libs.test.dir=${basedir}/src/test/libs
test.main=test.main=${tests.dir}/${package.dir}/AllTestsRunner.as
docs.dir=${basedir}/docs
# flex resources
flex.config=${FLEX_HOME}/frameworks/flex-config.xml
flex.lib=${FLEX_HOME}/frameworks/libs
flextask.jar=${FLEX_HOME}/ant/lib/flexTasks.jar
mxmlc.jar=${FLEX_HOME}/lib/mxmlc.jar
compc.jar=${FLEX_HOME}/lib/compc.jar

Flex-Ant: mxmlc doesn't support the "file" attribute

Just moved my Flex app onto Ant with a basic ant script and I am getting this stupid error: mxmlc doesn't support the "file" attribute. I looked through docos and it seems that my code is right, so hows it going.
<!-- load previously defined configuration properties file -->
<property file="build.properties" />
<!-- points to our flexTasks.jar we copied to the libs folder to distribute with the project -->
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasks.jar"/>
<!-- delete and recreate the DEPLOY dir -->
<target name="init">
<delete dir="${DEPLOY_DIR}" />
<mkdir dir="${DEPLOY_DIR}" />
</target>
<!-- Build and output the Main.swf-->
<target name="compile flex project" depends="init">
<mxmlc file="${SRC_DIR}/DNASupport.mxml"
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="false"
incremental="true"
optimize="true"
output="${DEPLOY_DIR}/Main.swf">
<license product="flexbuilder3" serial-number="137740016118223699076222" />
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${app_root_dir}/src" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.debug>false</compiler.debug>
</mxmlc>
</target>
are you using the flex ant tasks?
This is a part of my "typical" build file
<taskdef resource="flexTasks.tasks" />
...
<target name="compile">
<mxmlc file="Main.mxml" debug="true" output="main.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<source-path path-element="${src}" />
</mxmlc>
</target>
Hope this helps

Using ant, does anyone know how to build a SWF made up of SWCs (that you've built) that include resource bundles?

I'm trying to write an ant build script to build my group's flex app, and I've run into some roadblocks that I'm hoping someone on SO has seen before.
We have two projects that we build into SWCs and these components contain resource bundles. One SWC requires the other SWC. We have one project that we build into our application (the SWF) which uses both SWCs.
When I build the SWCs, I get no complaints about resource bundles not being found, and when I open the SWCs in winzip, I can see the bundles (in /locale/EN_US, for example)
When I build the SWF, however, I get complaints about not being able to find the resource bundles in the two swc's, but no complaints about not being able to find any other resource bundles (like the flex framework ones).
This is the kind of message I get from ant:
[mxmlc] Error: Unable to resolve resource bundle "whatever" for locale "en_US".
[mxmlc]
Surely, I am not the first person to hit this gotcha, so does anyone know what the problem is here?
Am I building the SWCs wrong, or the SWF?
For reference, here's one of my build tasks using compc (for some reason, I can't get the opening target tag to show up)
<path id="facet.sourcePath">
<pathelement location="${flex.facet.src}"/>
</path>
<property name="facet.sourcePath" refid="facet.sourcePath"/>
<echo message="sourcePath is ${facet.sourcePath}"/>
<fileset dir="${facet.sourcePath}" id="facet.sources">
<include name="**/*.as"/>
</fileset>
<pathconvert property="facet.classes" pathsep=" " refid="facet.sources">
<compositemapper>
<chainedmapper>
<globmapper from="*.as" to="*"/>
<globmapper from="${facet.sourcePath}\*" to="*" handledirsep="true" />
</chainedmapper>
<chainedmapper>
<globmapper from="*.mxml" to="*"/>
<globmapper from="${facet.sourcePath}\*" to="*" handledirsep="true" />
</chainedmapper>
</compositemapper>
</pathconvert>
<echo message="classes: ${facet.classes}"/>
<compc output="${flex.lib.output}/${facet.swc.name}" locale="EN_US"
include-classes="${facet.classes}" directory="false"
target-player="10.0.0"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<include-resource-bundles bundle="foo"/>
<include-resource-bundles bundle="bar"/>
<include-resource-bundles bundle="whatever"/>
<sp path-element="${flex.facet.dir}/locale/{locale}"/>
<keep-as3-metadata name="Bindable"/>
<keep-as3-metadata name="Remotable"/>
<keep-as3-metadata name="Embed"/>
<keep-as3-metadata name="Event"/>
<keep-as3-metadata name="ResourceBundle"/>
<source-path path-element="${flex.facet.src}"/>
<compiler.library-path append="true" dir="${flex.framework.lib}">
<include name="*.swc"/>
<include name="../locale/${locale}"/>
</compiler.library-path>
<compiler.library-path append="true" dir="${flex.rsm.lib}">
<include name="*.swc"/>
</compiler.library-path>
</compc>
</target>
and here's my mxmlc task:
<target name="flex.webapp.compile" description="compiles your flex app">
<mxmlc file="${flex.webapp.src}\RSM.mxml"
output="${flex.webapp.deploy}\ant_test\RSM.swf"
use-network="true"
keep-generated-actionscript="true"
debug="true"
locale="en_US"
incremental="true"
actionscript-file-encoding="utf-8"
target-player="10.0.0"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<include-resource-bundles bundle="RSM"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${flex.webapp.src}" />
<source-path path-element="${flex.webapp.dir}/locale/en_US" />
<source-path path-element="${flex.rsm.lib}" />
<sp path-element="${flex.core.dir}/locale/{locale}"/>
<sp path-element="${flex.facet.dir}/locale/{locale}" />
<compiler.library-path append="true" dir="${flex.framework.lib}">
<include name="*.swc"/>
<!--include name="../locale/${locale}"/-->
</compiler.library-path>
<compiler.library-path append="true" dir="${flex.rsm.lib}">
<include name="*.swc"/>
<include name="../locale/${locale}" />
<!--include name="rsm_rb.swc" /-->
</compiler.library-path>
</mxmlc>
</target>
Arrgh!
After many hours of staring at this problem, I realized that the issue was looking me in the face the whole time.
The compc task is using 'locale="EN_US"' and the mxmlc task is using 'locale="en_US"'.
If anyone ever posts a "what's the stupidest work problem you've ever had?", this would be my answer.
btw it doesnt have to be that complicated (even in linux console!), all you need is to include libs...
daemonna#NES-KOS-29:~/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src$ mxmlc -library-path=../libs -locale=en_US App.mxml
Loading configuration file /home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/flex-config.xml
Error: Unable to resolve resource bundle "components" for locale "en_US".
....bla bla bla...
Error: Unable to resolve resource bundle "controls" for locale "en_US".
daemonna#NES-KOS-29:~/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src$ mxmlc -library-path=../libs -library-**path=/home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/locale/en_US/** -locale=en_US App.mxml
Loading configuration file /home/daemonna/Frameworks/flex_sdk_4.1.0.16076/frameworks/flex-config.xml
/home/daemonna/Desktop/FlexUnit4Turnkey_4.0_sdk_4.0.fxp_FILES/src/App.swf (37964 bytes)

Resources