Flex Icon

Compiling a Mobile Flex Project using Ant and launching the swf using the Air Debug Launcher

Flex IconFirst of all, compiling a Mobile Flex Project is not the same as packaging one. Compiling is creating an swf, packaging is creating a ipa or apk file (Android or iOs). I’ll deal with packaging in a later post. If you double click on a compiled Mobile Flex Project swf, you wont see a thing. If you want to see your swf in action, you’ll have to use the Air Debug Launcher, ADL. Off course, instead of using Ant, you can also use the command prompt or Flash Builder.

First of all, compiling the mobile project to a swf. You’ll have to change things to match your own project, but this can be a start.

Compiling a Mobile Flex Project using Ant

You can replace the variables (things like ${src.dir}) by the actual paths, or declare the variables in ant.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<target name="compile">		
    <echo level="info">Target::compile</echo>
    <mxmlc
	debug="false"
	file="${src.dir}/Main.mxml"
	output="${output.dir}/Main.swf"
	actionscript-file-encoding="UTF-8"
	keep-generated-actionscript="false"
	incremental="false"
	show-binding-warnings="true"
	show-unused-type-selector-warnings="false"
	link-report="${basedir}/report.xml"
	locale="nl_BE,fr_BE,en_US,de_BE"
	allow-source-path-overlap="true"
	report-invalid-styles-as-warnings="true"
	keep-all-type-selectors="true"
	static-link-runtime-shared-libraries="true"> <!-- RSL's result in performance issues: 
        When set to true, all framework code is compiled in the application -->
 
	<theme dir="${FLEX_HOME}/frameworks/themes">
		<include name="Mobile/mobile.swc" /> <!-- See properties project - Flex Theme -->
	</theme>
 
	<load-config filename="${FLEX_HOME}/frameworks/airmobile-config.xml"/>
 
	<source-path path-element="${src.dir}"/>
	<source-path path-element="${basedir}/locale/{locale}"/>
 
	<compiler.library-path dir="${FLEX_HOME}" append="true">
		<include name="frameworks/libs"/>
		<include name="frameworks/locale/en_US"/>
	</compiler.library-path>
 
        <!-- Next include all swc's you need to compile your project. -->
	<compiler.library-path dir="..." append="true">
		<include name="..."/>
                <!-- Include more swc's if needed -->
	</compiler.library-path>
 
        <!-- Application default dimensions-->
        <default-size width="500" height="600"/>	
 
    </mxmlc>
</target>

More information on the compiler options can be found here.

A lot of the options like actionscript-file-encoding, keep-generated-actionscript, incremental, show-binding-warnings, show-unused-type-selector-warnings, link-report, allow-source-path-overlap, report-invalid-styles-as-warnings, keep-all-type-selectors and static-link-runtime-shared-libraries can be left out because either they do not apply to your application or the default value is the same as the one set here. Look at the documentation for more details.

You’ll need to search around a little bit to have the same result as when building in Flash Builder.

Air Debug Launcher using Ant

This will launch your mobile app on your desktop.

1
2
3
4
5
6
7
8
9
<target name="Air Debug Launcher">
    <exec executable="${ADL}" failonerror="true">
	<arg value="-profile"/> 
	<arg value="mobileDevice"/>
	<arg value="-nodebug"/>
	<arg value="${src.dir}/Main-app.xml"/> <!-- Application descriptor -->
	<arg value="dist"/> <!-- Location of swf, locales, ... -->			
    </exec>
</target>

More information at Run and debug a mobile application on the desktop

This video is also usefull for more information.

3 thoughts on “Compiling a Mobile Flex Project using Ant and launching the swf using the Air Debug Launcher

  1. Pingback: Lieven Cardoen » Blog Archive » Packaging a Flex Mobile Project using Ant for Android, BlackBerry or iOs

  2. Swathi

    Hi,

    The custom ios mobile theme does not seem to include using the above mentioned theme compiler option. Do you have any clue?

    Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>