How to Build Flex with MSBuild

For those how cares for software quality, continuous  integration is nowadays one of the most valuable process. We should implement it as soon as possible and use as a single, reliable source of test data. I will not write here about what such a process should do, I will focus on something that seems simple to implement but as it turned out, it takes a long time.

The question is: how to prepare, compile and build Flex application using MSBuild tool.

What problems can we meet?

  • flex module compilation
  • library (swc) compilation
  • embedded assets and styles
  • external library linking
  • not stable SDK

Typical compiler errors:

  • “A file found in a source-path must have the same package structure”
  • “Unable to resolve asset for transcoding”
  • “The definition of base class * was not found”
  • “java null point exception” thrown by mxmlc.exe

In developing the process I made one important assumption, which helped me to not give up too early. It sounded something like this: since FlexBuilder is able to compile my project using the same tools (MXMLC, COMPC) MSBuild will do it too. There are couple of ANT Tasks for Flex but I wanted to use MSBuild because of some build server restrictions.

For a moment forget about MSBuild, let’s use the command line to build the project. I assume that our sources are in “src” folder, and our script is located in the parent folder, main class or mxml is named Application.

$(FLEXSDK)\bin\mxmlc.exe -library-path+=libs -warnings=false -output $(OutputDir)/Application.swf -locale en_US -file-specs src\Application.mxml

Divide this line into parts:

  • $(FLEXSDK) – path to your local Flex SDK
  • library-path – path or paths to your external library folders
  • output – where the bin file should be created
  • file-specs – main application file

all options can be found at Adobe MXMLC Reference

What about compiling SWC library/component?

$(FLEXSDK)\bin\compc.exe -source-path . -external-library-path lib $(FLEXSDK)\frameworks\libs\player\$(TARGETPLAYER) $(FLEXSDK)\frameworks\libs -warnings=false -include-sources Views Controllers Models -include-sources lib -output=Library.swc

  • $(TARGETPLAYER) – version of target Flash Player (9 or 10)
  • include-sources – all paths where needes classes or mxml lies
  • external-library-path – our external libs and flex sdk libs (important)

all options can be found at Adobe COMPC Reference

Everything looks simple, but if you have a bit more complicated code, many assets and dependencies, often the whole operation fails.

Unable to resolve asset …
For me is the most often repeated error, usually occurs when we have css style file with embedded assets or skins.

Embed(source=”middleTab.png”, scaleGridTop=”2″, scaleGridBottom=”20″, scaleGridLeft=”25″, scaleGridRight=”135″);

Solution ?
First try to change the paths from “com/myapplication/assets/image.png” to “/com/myapplication/assets/image.png”.
If that does not work, we have a big problem, the only way, in my opinion, is to switch form styles to the skin class but earlier try to download latest sdk.

The definition of base class…
We will meet often but the solution is simple, missing libraries, you can use -library-path switch.

“Java null point exception” thrown by mxmlc.exe or similar
Watch out for flex sdk night builds and not stable versions. When using Flex Builder we have “internal error”, command line shows null point exceptions.

I hope that this advice will help you. For some time I will try to write about how to create a complete build script with application version and build time injection maybe in connection with TeamCity or CCNET server.
Remember that you can easily edit xml build files with Visual Studio.


No comments for “How to Build Flex with MSBuild”

Post a comment