How to compile a Flex project with RSL using Ant

Recently, we had to write an Ant script to build our application and put it under continuous integration. At the beginning, we passed the minimum arguments to the compiler to build the SWF file and it compiled the project, including the framework classes, in the application SWF file. So, how to use RSL winthin an ant script to reduce the size of the swf result file ?

Firs of all, you have to use a configuration file witch specifies a lots of information to the compiler about your application like the name, the player version, etc. So, you can create your own configuration file and specify all the informations needed. A sample of the file is in the flex sdk named "flex-config.xml". Inside this file, you can write a tag runtime-shared-library-path witch specify the SWC file you want to use as an RSL.

An example of the config file may be:

<flex-config> <compiler> ... </compiler>

<runtime-shared-library-path>

<path-element>libs/framework.swc</path-element>

<rsl-url>framework_3.2.0.3958.swz</rsl-url>

<policy-file-url></policy-file-url>

<rsl-url>framework_3.2.0.3958.swf</rsl-url>

<policy-file-url></policy-file-url>

</runtime-shared-library-path> ...

</flex-config>

The <path-element> tag is the relative path to the library file, the <rsl-url> is the relative url of the RSL relatively to the root server path and the <policy-file-url> is the relative URL for the crossdomain.xml file. If not specify, flash will try to find it at the root of the server.

Now we can use this file in our ant task as a config file for the compiler. Therefore, the compiler will create correct links to the RSL in the project SWF file.

This is a sample how to use the config file:

<mxmlc file="..." > ...

<load-config filename="${basedir}/flex-config.xml"/> ... </mxmlc>

After the build, the SWF file of the project is smaller than before and you have just to put the framework.swz and framework.swf file at the correct location on the server to use them as Runtime Shared Libraries !