Compilation results from Flex Builder and Flex Ant Tasks are Different
Issue
When you compile your Adobe Flash Builder project using Ant, the finished application (or library) does not work. You can compile the same project using Flash Builder without any issue.
A good indication of this problem is that your compiled SWF/SWC using Ant is smaller than the one you get when compiling from Flash Builder.
Reason
This problem occurs when the configuration used with Ant is not the same as the one Flash Builder itself is using.
Solution
You can determine the options that Flash Builder itself is using to compile your project by creating a configuration file. You can then use that file, including any edits you might make, to run mxmlc or compc from Ant and achieve the desired results.
To generate the configuration file, you should add the following command-line option in Flash Builder:
Windows
-dump-config=c:\myconf.xml
Mac/Unix
-dump-config=/tmp/myconf.xml
You can edit your compiler arguments in Flash Builder by having your project open, going to the "Project" menu and choosing "Properties" and then "Flex Compiler". Add the option in the "Additional Compiler Arguments" box.
The file name and location can be anywhere you wish, where you have permission to create a file.
There are a couple of known issues with the produced config file, and you can remedy these quite easily as follows:
1. The generated <manifest> tag will have a relative path. For use with Ant, you will need to edit the path to be absolute, including all directories above it like so:
<manifest>C:\FlashBuilder\Flex SDK\frameworks\mxml-manifest.xml</manifest>
2. The token œ${flexlib} will appear in the config file but should have been substituted. This is a known issue. You can either comment out the two locations where it appears, or fill in the location of your Flex lib directory.
To then run the compiler with this config file, it is simplest to copy it to the bin directory of the SDK you are using beneath your installation of Flash Builder.
You can then invoke mxmlc like this:
Windows:
mxmlc -load-config+=mycfg.xml C:\\projects\\src\\main.mxml -output myswf.swf
Mac/Unix:
./mxmlc -load-config+=mycfg.xml /projects/src/main.mxml -output myswf.swf
When using compc, the classes to be compiled into the SWC are not output to the generated config file. You must add them manually, or from the command line.
The simplest way to accomplish this is to add tags as follows to your config file:
<include-classes> <class>analysisModule</class> <class>adminModule</class> </include-classes>
You can get the actual content for thst from your project file (.flexLibProperties) which will look something like this:
<?xml version="1.0" encoding="UTF-8"?> <flexLibProperties version="1"> <includeClasses> <classEntry path="analysisModule"/> <classEntry path="adminModule"/> </includeClasses> <includeResources/> <namespaceManifests/> </flexLibProperties>
The classEntry paths translate into the class tag values.
After doing this you can run compc like this:
Windows:
compc -load-config+=analysis_cfg.xml -output myswc.swc
Mac/Unix:
./compc -load-config+=analysis_cfg.xml -output myswc.swc