A few days ago I blogged about the creation of a simple RSS reader for the Android platform. It certainly wasn't complex, but it was good practice to get my feet wet with the Hero SDK and mobile Flex development. I'm a big fan of trying small, simple applications as a way to get experience with a platform. When I built this application though, I have to admit I had something a bit more interesting in mind. Today I'll show you what I built. I think it's pretty cool and it is a testament to the power of the tools Adobe has provided.

Whenever I present on Adobe AIR, I always take pains to mention that the SDK is 100% free. You don't have to buy any tools at all to work with AIR. Certainly Flash Builder is a damn fine tool (if you are doing Flex-based AIR development) and I recommend it, but if you don't have the money, or don't like the editor, you can use your own editor and compile both Flex and your AIR applications by hand. There are a set of command line tools that cover the entire process. To make things even easier, you can automate all of this with ANT. Terry Ryan just did a great blog post on this: Using ANT to package the same AIR app to Multiple Devices. In his post, Terry describes not only compiling the Flex application but also building the installers for both Android and the Playbook. This works great. But did you know that one of the coolest features in ANT is the ability to do replacements in text files? I didn't know this till I saw the ANT file for Model-Glue. If you combine the fact that we can make replacements in our source code with the ability to build/compile the application via ANT, you can provide a "Create your own RSS Android App" application via the web. Consider the following walkthrough:

User hits a form on your site:

They enter a site name, a URL, and a RSS URL and then hit submit. Next they see:

At this point, the APK could be emailed to them (on an Android phone you can install applications sent via email), it could be stored on the file system for download later, or any other number of possibilities. The point is - they now have a 100% customized Android application delivered completely dynamically via ColdFusion and the AIR/Flex command line tools.

Here is the code I used for the ColdFusion side. This is a proof of concept. It will fail horribly if run by multiple users. That's fixable, but beyond the scope of this blog entry.

<cfif structKeyExists(form, "submit")>

<cfset pathToAnt = "C:\apache-ant-1.8.1\bin\ant.bat"> <cfset pathToBuild = """C:/Users/Raymond/Documents/My Dropbox/projects/SimpleRSS/build.xml""">

<cfexecute name="#pathToAnt#" arguments="-buildfile #pathToBuild# -verbose -Dcompany=#form.company# -Durl=#form.companyurl# -Drssurl=#form.rssurl#" variable="result" errorvariable="error" timeout="60" />

<cfif not len(error)> <h2>Done!</h2> Your APK has been created. <cfabort/> </cfif> <!--- no error handling yet - too bad ---> </cfif>

<h2>Make me an Android App</h2>

<form method="post"> Enter company name: <input type="text" name="company" value="test"><br/> Enter company URL: <input type="text" name="companyurl" value="http://www.androidgator.com"><br/> Enter RSS URL: <input type="text" name="rssurl" value="http://feeds.feedburner.com/AndroidgatorcomFeed"><br/> <input type="submit" name="submit" value="Make it so..."> </form>

And here is a modified form of the build script Terry did. I removed the Playbook support, made it copy to a temp dir, and added replacements in.

<?xml version="1.0" encoding="UTF-8"?> <project name="SimpleRSS" default="main" basedir=".">

<property file="settings.properties"/>

<!-- path to the flex task libraries. --> <path id="flextasks.classpath"> <fileset dir="${FLEX_HOME}/ant/lib"> <include name="*.jar"/> </fileset> </path>

<typedef resource="flexTasks.tasks" classpathref="flextasks.classpath" />

<target name="main" depends="prepPackage, package.android, install.android" />

<target name="clean"> <echo message="Cleaning Build Space"/> <delete dir="${build.dir}"/> </target>

<target name="prepPackage" depends="compile,handleDevices" />

<target name="compile" depends="clean"> <echo message="Copying to temp dir" />

<copy todir="${temp.dir}"> <fileset dir="${dev.dir}" /> </copy>

<echo message="Doing replacements... " /> <echo message="Replacing company with ${company}" /> <echo message="Replacing url with ${url}" /> <echo message="Replacing rss url with ${rssurl}" />

<replace dir="${temp.dir}" failOnNoReplacements="true"> <include name="**/*.mxml" /> <replacefilter token="@@@companyText@@@" value="${company}" /> <replacefilter token="@@@url@@@" value="${url}" /> <replacefilter token="@@@rssurl@@@" value="${rssurl}" /> </replace>

<echo message="Compiling swf"/>

<!-- hack one - had to add full path --> <mxmlc file="C:/Users/Raymond/Documents/My Dropbox/projects/SimpleRSS/${projectFile}" output="${swfFile}"> <load-config filename="${FLEX_HOME}/frameworks/airmobile-config.xml"/> <source-path path-element="${FLEX_HOME}/frameworks"/> <static-link-runtime-shared-libraries />

<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true"> <include name="libs/*" /> </compiler.library-path>

<compiler.library-path dir="." append="true"> <include name="libs/*" /> </compiler.library-path>

</mxmlc>

<delete dir="${temp.dir}" />

</target>

<target name="collect.android"> <echo message="Creating Device Folder for Android"/> <mkdir dir="${build.dir}/android"/> <echo message="Copying SWF for Android"/> <copy file="${swfFile}" todir="${build.dir}/android" /> <echo message="Copying Application Description File for Android"/> <copy file="${dev.dir}/${app.name}-app.xml" todir="${build.dir}/android" preservelastmodified="true" /> <echo message="Modifying Application Description File"/> <replace file="${build.dir}/android/${app.name}-app.xml"> <replacefilter token="${contentText}" value="${app.name}.swf" /> </replace> </target>

<target name="handleDevices" depends="collect.android"/>

<target name="package.android"> <echo message="Packaging for Android"/> <exec executable="${ADT}" dir="${build.dir}/android" failonerror="true"> <arg value="-package"/> <arg line="-target apk"/> <arg line="-storetype pkcs12"/> <arg line="-keystore ${cert}" /> <arg line="-storepass ${cert.password}" /> <arg value="${app.name}"/> <arg value="${app.name}-app.xml"/> <arg value="${app.name}.swf"/> </exec> </target>

<target name="install.android"> <echo message="Installing onto attached Android Device"/> <exec executable="${ADB}"> <arg value="install"/> <arg value="-r"/> <arg value="${build.dir}/android/${app.name}.apk"/> </exec> </target> </project>

Thoughts?