Flex 4 in Iphone

Reading Christian Cantrell post, i give a try the PFI to compile a Flex 4 basic application. After configuring some paths, and environment variables, finally y got an IPA file. I took some screenshots of this test on my Iphone 3G.

the detail process is the next one:

  • download the PFI from adobe labs
  • create a new project in Flash Builder 4 with name “flex4ToIphone”

  • change the application descriptor “flex4ToIphone-app.xml” to
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<application xmlns="http://ns.adobe.com/air/application/2.0">
    <id>com.tidyslice.flex4ToIpad</id>
    <version>1.0</version>
    <filename>flex4ToIpad</filename>
    <description></description>
    <name>flex4ToIpad</name>
    <copyright></copyright>
    <initialWindow>
        <content>flex4ToIphone.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <fullScreen>true</fullScreen>
        <autoOrients>false</autoOrients>
        <aspectRatio>portrait</aspectRatio>
        <renderMode>gpu</renderMode>
    </initialWindow>
    <customUpdateUI>false</customUpdateUI>
    <allowBrowserInvocation>false</allowBrowserInvocation>
    <icon></icon>
    <iPhone>
	<InfoAdditions><![CDATA[<key>UIDeviceFamily</key><array><string>2</string></array>]]></InfoAdditions>
    </iPhone>
</application>
  • Cause we want to use ant to compile, its necessary to create build.propertis
#Flex Locations
FLEX_HOME=/Applications/Adobe\ Flash\ Builder\ 4/sdks/4.1.0
FLEX_TASKS=${FLEX_HOME}/ant/lib/flexTasks.jar

PFI_HOME=/your/path/packagerforiphone_v2_mac_101110/lib
PFI=${PFI_HOME}/pfi.jar
#Compilers
ADL=${FLEX_HOME}/bin/adl
ADT=${FLEX_HOME}/lib/adt.jar
#App Settings
APP_NAME=flex4ToIphone
APP_EXTENSION=mxml
SOURCE_DIR=${basedir}/src
LIBRARY_DIR=${basedir}/libs
RELEASE_DIR=${basedir}/release
BUILD_DIR=${basedir}/build

#Etc Settings
LOCALE=en_US
DEBUG_FLAG=false

#pfi
TARGET=ipa-app-store
PROVISION_PROFILE=/your/path/Provisioning_Profile_.mobileprovision
STORETYPE=pkcs12
KEYSTORE=/your/path/myCertificate.p12
STOREPASS=myStorePass
IPAFILE=${APP_NAME}.ipa
AIRDESCRIPTOR=${SOURCE_DIR}/${APP_NAME}-app.xml
SWFFILE=${APP_NAME}.swf
  • Also we need to create a build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Build File" basedir="." default="build">

    <!--location of property file -->
    <property file="${basedir}/build.properties" description="your specific properities for builds" />

    <!-- additional tasks -->
    <taskdef name="mxmlc" classname="flex.ant.MxmlcTask" classpath="${FLEX_TASKS}"/>
    <taskdef name="compc" classname="flex.ant.CompcTask" classpath="${FLEX_TASKS}"/>
    <taskdef name="asdoc" classname="flex.ant.AsDocTask" classpath="${FLEX_TASKS}"/>

    <!--
       Build
   -->

    <target name="build" description="compiles application">
        <antcall target="init"/>
        <antcall target="compile"/>
        <antcall target="pfi"/>
        <antcall target="cleanup"/>
    </target>

    <target name="compile"
        description="Compiles the AIR application to a SWF file and places SWF in a temp directory to be packaged.">
        <mxmlc file="${SOURCE_DIR}/${APP_NAME}.${APP_EXTENSION}"
            output="${BUILD_DIR}/${APP_NAME}.swf"
            locale="${LOCALE}"
            static-rsls="true"
            accessible="true"
            configname="air"
            debug="${DEBUG_FLAG}"
            failonerror="true"
            fork="true"
            maxmemory="512m">
            <source-path path-element="${SOURCE_DIR}"/>
            <external-library-path file="${FLEX_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
            <library-path dir="${LIBRARY_DIR}" includes="*.swc" append="true"/>
        </mxmlc>
    </target>

 	<target name="pfi" >
        <java jar="${PFI}" fork="true"
            failonerror="true">
  			<arg value="-package"/>
  			<arg value="-target"/>
  			<arg value="${TARGET}"/>
  			<arg value="-provisioning-profile"/>
  			<arg value="${PROVISION_PROFILE}"/>
  			<arg value="-storetype"/>
  			<arg value="${STORETYPE}"/>
  			<arg value="-keystore"/>
  			<arg value="${KEYSTORE}"/>
  			<arg value="-storepass"/>
  			<arg value="${STOREPASS}"/>
			<arg value="${IPAFILE}"/>
			<arg value="${AIRDESCRIPTOR}"/>
			<arg value="-C"/>
			<arg value="${BUILD_DIR}"/>
			<arg value="${SWFFILE}"/>
        </java>
    </target>

    <target name="init" depends="clean"
    description="Cleans the deploy file">
        <mkdir dir="${BUILD_DIR}"/>
        <mkdir dir="${RELEASE_DIR}"/>
    </target>

    <target name="clean"
        description="Cleans up old files.">
        <delete dir="${BUILD_DIR}" failOnError="false" includeEmptyDirs="true" />
        <delete dir="${RELEASE_DIR}" failOnError="false" includeEmptyDirs="true" />
    </target>

    <target name="cleanup"
        description="Cleans up old files.">
        <delete dir="${BUILD_DIR}" failOnError="false" includeEmptyDirs="true" />
    </target>

</project>
  • execute the command: ant build

Feel free to contact me if you have any questions.


2 thoughts on “Flex 4 in Iphone

  1. Pingback: Architect, Engineer, Tech Enthusiast – Hasan Otuome – Using ANT to Compile a Flex Mobile Project for iOS

  2. Pingback: Using ANT to Compile a Flex Mobile Project for iOS - Almer/Blank Labs

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>