I recently needed to compile a SWC from Flex Builder 3 on my Mac. I hadn’t done that before, as I really hadn’t had the need to share or publish my Flex components with a broader audience. This seemed like it was going to be a pretty straightforward thing to do, but after a while of tinkering about in FlexBuilder 3 with a number of different failures of varying types, it became abundantly clear that simply following the tutorials on LiveDocs, the docs on Labs and the help files in FlexBuilder wasn’t going to cut it. A number of posts on Mike Chambers blog regarding SWC compiling with compc and some messages in the FlexCoder’s discussion list got me closer to my goal, but it still took a lot more tiral and error than I think it should on a commerical product like Flex Builder. The bugs I found in Adobe’s Jira Flex SDK area on the subject were almost laughable, some mentioning compiling SWCs from FlexBuilder 3 on a Mac as an “edge use case”. Really? An edge use case?
FlexBuidler 3 on a Mac is not capable of compiling Flex components to SWC files out of the box. You need to install and configure Apache Ant before you will be able to share your code libraries with other developers.
So, for my own future reference and in the hopes of saving some Mac Flex developers the headache I encountered, here are the steps I needed to take to get Ant to successfully build a SWC that I could use in other Flex projects or give to developers on my team.
Installing Ant For FlexBuilder on OSX
You’ll need to load Ant into your FlexBuilder installation. To do this, open FlexBuilder and go to “Help -> Software Updates -> Find and Install..” Once the dialog appears, choose the “The Eclipse Project Updates” option and click finish. Choose a repository. You’ll need to install The Eclipse JDT package. Confirm the download, accept the agreement and wait for the install to happen. After the install completes you’ll need to restart Flex Builder to see it. After the restart, it should be available to you via “Window -> Other View -> Ant”. Before using it, though, we have a little more tweaking to get it to work.
Configuring Ant For FlexBuilder on OSX.
Add your SDK folder to your system’s $PATH environment variables. This is a simple step in theory, but in practice will cause you some headaches due to the default location of the Flex Builder install. By default, Adobe Flex is installed here: “/Applications/Adobe Flex Builder 3″. The folder has spaces in the name. Typically, when using spaces in folder names, specifying the path to that directory in a shell application requires using encapsulating quotes or the escape character “\” proceeding the space. In this case, using either of those failed for me. In order to workaround this, I needed to create a symlink at “usr/local/flex_sdk, allowing Ant to reach “compc” in a directory that didn’t have spaces in it. If you don’t do this, you’ll end up seeing errors like this.
So to do this, open Terminal and type: “sudo ln -s "/Applications/Adobe Flex Builder 3/sdks/3.2.0/" /usr/local/flex_sdk” – Of course, this assumes your SDK is located in “/Applications/Adobe Flex Builder 3/sdks/3.2.0/”, which for me, on a default FlexBuilder3 install, it was.
Once that is done, you may edit your “.profile” file to add the symlinked directory (pointing to your Flex SDK) to your $PATH environment variable. You have to do this, because without it, when Ant fires off the Compc Task, your Mac won’t know where the compc application is. You can use any text editor you like to edit the file, but since the file has a “.” prefix in the name, the file is invisible by default to the finder. Pico, Vi, etc in the Terminal have no problem with hidden files, and BBEdit is also capable of opening hidden files via the “File -> Open Hidden…” command. Your edited .profile file should look something like this after you are done:
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/flex_sdk/bin:/usr/local/flex_sdk/lib:$PATH
Once this edit is complete, logout of the Finder, log back in and check that the edit stuck by using this command in your Terminal:
echo $PATH
After that fun is over, you should be able to fire up Flex Builder… Once you have some AS you want to turn into a Ant Project, you’ll need to write a build.xml file and a build.properties file. Pretty much all the other tutorials out there on using Ant with Flex work after this point, so I won’t bore you with those details. After everything is working, I have to say Ant is pretty cool and I’m already thinking of some cool things to use it for to automate my workflow and speed up testing and deployment.
That said, I surely hope that FlexBuilder 4 fixes some of these dicier development issues that seem to plague FlexBuilder 3. Honestly, avoiding stuff like this was one of the main reasons I have paid for a FlexBuilder license, rather than simply downloading the free SDK and using the free Eclipse IDE, so if 4 doesn’t fix a lot of this stuff, I’ll likely do that. Writing MXML is easy enough, and with Catalyst just around the bend, it might supplant one of the bigger benefits of the FlexBuilder design view, so this seems even more plausible for many now than it did around the release of FlexBuilder 3.
In closing, I hope this article helps you, and if does, please comment below. If things aren’t working for you after following the tips in this post, comment and I’ll try to help you out!