Saturday, November 29, 2008

Using the flex framework RSL's in Flex 3 using Ant

Using RSLs will save you over 300kb of your swf filesize. Flexbuilder has build in features to compile your swf using the rsl libraries, but offcourse we are building on our build server using ant. Using the flex frameworks RSL's from ant is easier said then done. Appearantly this Ant mxmlc target does not implement this feature yet. This feature is shipped with the next flex version (Flex 4 Gumbo). The solution after the jump!

So simply adding the RSL to the mxmlc tag in ant does not work:

<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
<url rsl-url="${FLEX_HOME}/frameworks/rsls/framework_3.0.189825.swz"/>
</runtime-shared-library-path>
The easiest (probably not the prettiest) way to fix this is to specify the RSLs in the flex-config.xml file, located in your flex sdk. Simply change the following statement to false to use the RSL.

<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>

The framework RSL is default, but you can also specify to use the rpc and datavisualization RSLs in the same flex-config.xml.

When you are using a build server, change this setting in the sdk on your build server, be aware that all projects that are build by this build server are using the same settings!
You also need to include the compiled libraries next to your compiled swf file. You can find the files in frameworks/libs and frameworks/rsls folders of your sdk. These files are neccessary for people who didn't cache the frameworks libraries yet in their flex player. Don't be fooled if it works for you without the files, you probably have them cached already.

3 comments:

Anonymous said...

I was wondering why my very similar Ant task wasn't working. Thanks for answering my question!

Hans-Peter Smit said...

Hello Marcel,

Thanks for your post. I investigated a bit further on this.
A quick way is to add: static-rsls="false" to your ant mxmlc tag. (I can not seem to post an example, because it is refused).

Also the alternative by specifying runtime-shared-library works fine. However I always add the (default) flex-config.xml in load-config, perhaps that makes the difference. Options you specify in mxmlc overrule the ones in flex-config.xml.

So basically I think it is possible to use Ant and RSL's without changing the default flex-config.xml for every project.

regards,
HP

Hans-Peter Smit said...

To be more precise you have to specify: static-rsl="false" in mxmlc and you have to define the runtime-shared-library-path!
Reason is that only the framework-rsl is defined in the default flex-config.xml.
See the example below:

<mxmlc file="${SRC_DIR}/${MAIN_MXML}.mxml"
    output="${OUTPUT_DIR}/${MAIN_MXML}.swf"
    keep-generated-actionscript="false"
    debug="${DEBUG}"
    static-rsls="false"
    link-report="${OUTPUT_DIR}/linkreport.xml">
                           
     <!-- Framework RSL's -->
     <runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
             <url rsl-url="framework_3.1.0.${build.number}.swz"/>
             <url rsl-url="framework_3.1.0.${build.number}.swf"/>
     </runtime-shared-library-path>
     <runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/datavisualization.swc">
             <url rsl-url="datavisualization_3.1.0.${build.number}.swz"/>
             <url rsl-url="datavisualization_3.1.0.${build.number}.swf"/>
     </runtime-shared-library-path>
     <runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/rpc.swc">
             <url rsl-url="rpc_3.1.0.${build.number}.swz"/>
             <url rsl-url="rpc_3.1.0.${build.number}.swf"/>
     </runtime-shared-library-path>     <!-- src path contain our packages -->
     <compiler.source-path path-element="${SRC_DIR}"/>
</mxmlc>

Post a Comment