How do I build a Flex library without resorting to ant?

First, here's what I want to do:

  • Compile my library code into a SWC
  • Do not staticly link the Flex framework


At first, I tried just setting up a Flex module, clicking the "library" and "use framework as an RSL" buttons. This however doesn't compile any of my code into the SWC, and it basically just compiles a new SWC of the entire Flex framework, all resources and classes included.

Then, I managed to get my classes into the build using a custom compiler config, but it still includes the few Flex classes that I reference in my library code.

Finally, I figured I could use the custom flex-config.xml file, remove the parent reference to the library using
<library-path append="false"></library-path> and then using a custom command line parameter (and also from ant), add -compiler.external-library-path references to the SDK and PlayerGlobal.swc. This should probably work, but Idea won't let me set command line parameters when I'm using a custom config file :'(

Any suggestions are greatly appreciated!

5 comments
Comment actions Permalink

1. You are right, to compile your library code into a SWC you check Output Type: Library at Flex Compiler Settings tab.
You mentioned that without custom config file none of your code was included in swc. This seems to be incorrect project configuration. Please check source roots at Project Structure | Modules | Sources tab

2. Unfortunately 'Use Framework as Runtime Shared Library (RSL)' option doesn't do what you need and you really should use custom compiler configuration file. Nice thing is that you do not need to set any Additional compiler options because all these options have equivalent tag in compiler configuration file. For example instead of  -compiler.external-library-path command line option you write something like this

<flex-config xmlns="http://www.adobe.com/2006/flex-config">

  <compiler>

      <external-library-path>

           <path-element>FLEX_SDK/frameworks/libs/player/{targetPlayerMajorVersion}.{targetPlayerMinorVersion}/playerglobal.swc</path-element>

       </external-library-path>

  </compiler>

</flex-config>

So your compiler config file may look like standard FLEX_SDK/framewoeks/flex-config.xml file with library-paths moved to external-library-paths and with you project specific information added: source folders, classes to include and output file name.

0
Comment actions Permalink

Thanks for your help!

As for number 1, I've attached a screenshot of my module source folders, it looks fine to me.

For number 2, I didn't know that we could put {parameters} into flex-config.xml. Of course, I don't really know anything about flex-config.xml due to Adobe's absolutely terrible documentation. Unfortunately for some reason "targetPlayerMajorVersion" correctly resolves, but "targetPlayerMinorVersion" doesn't, and I can't seem to guess the correct parameter for the SDK location. Do you have any idea where I can find a list of these available parameters? My project is OSS, so hard-coding references to the SDK location on any particular development machine is not an option.



Attachment(s):
Screen shot 2010-01-19 at 9.31.58 AM.png
0
Comment actions Permalink

OK, Through much googling and random experimentation, here's what worked. Take careful note that some parameters are specified like "{name}" and some are "${name}". No, I don't know why :-/

<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">


    <!-- Specifies the minimum player version that will run the compiled SWF. -->
    <!-- 9.0.124 is the April 2008 security release -->
    <target-player>9.0.124</target-player>


    <compiler>

        <source-path>
            <path-element>src</path-element>
        </source-path>


        <incremental>true</incremental>

        <keep-as3-metadata append="true">
            <name>Inject</name>
            <name>InjectInto</name>
            <name>InjectIntoContents</name>
            <name>Singleton</name>
            <name>PostConstruct</name>
        </keep-as3-metadata>


        <!-- Remove the "include" library path. -->
        <library-path append="false"></library-path>


        <!-- Set up an "external library" path that is compiled against but not linked. -->
        <!-- SWCs not used for SP are left in but commented out to make it easier to copy this script -->
        <external-library-path>
            <path-element>${flexlib}/libs/player/{targetPlayerMajorVersion}/playerglobal.swc</path-element>
            <path-element>${flexlib}/libs/framework.swc</path-element>
            <!--<path-element>${flexlib}/libs/flex.swc</path-element>-->
            <!--<path-element>${flexlib}/libs/rpc.swc</path-element>-->
            <!--<path-element>${flexlib}/libs/utilities.swc</path-element>-->
            <!--<path-element>${flexlib}/libs/datavisualization.swc</path-element>-->
        </external-library-path>


    </compiler>

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

    <include-classes>
        <class>net.expantra.smartypants.impl.InjectorImpl</class>
    </include-classes>


    <output>./build/SmartyPants-IOC.swc</output>

</flex-config>

0
Comment actions Permalink

You use {name} (i.e. without $) for {targetPlayerMajorVersion} because this is a special property that you do not specify externally, it is taken from
<target-player>9.0.124</target-player>

One more special property (you may notice it in standard flex-config.xml) is {locale} which is taken from
      <locale>
          <locale-element>en_US</locale-element>
      </locale>
There can be more than one locale, {locale} will be substituted with each one.

0
Comment actions Permalink

Yes, source roots are configured properly. I'm sure that if you compile your swc without using custom config file then autogenerated config file (MODULE_NAME_temp_flex_config.xml lcoated in project root) contains <include-classes> tag and all your classes are listed there, so all of them are compiled in swc.

0

Please sign in to leave a comment.