10 Jan

Javascript MVC + PhoneGap + jQm Build with Ant

In an effort to streamline the build of mobile applications, I made an ant build file to automate some of the tasks you would normally have to do to package your JMVC webapp and deploy it into an android project.

Here is the interesting parts of my build.xml file:

    <target name="build" description="Builds the app for production"  depends="">
        <exec executable="./js" dir="${src}/.." vmlauncher="no">
           <arg line="${src}/scripts/build.js" />
        </exec>
        <copy todir="${build}/steal">
            <fileset dir="${src}/../steal"/>
        </copy>
        <copy todir="${build}/${appName}/images">
            <fileset dir="${src}/images"/>
        </copy>
        <copy file="${src}/${appName}.html" tofile="${build}/${appName}/index.html"/>
        <replace file="${build}/${appName}/index.html" token="steal/steal.js" value="steal/steal.production.js" />
        <move file="${src}/production.css" tofile="${build}/${appName}/production.css"/>
        <move file="${src}/production.js" tofile="${build}/${appName}/production.js"/>
    </target>

I also have the clean phonegap android projects inside a folder called platforms/Android under my JMVC app folder. This project was updated to generate an ant build.xml file using this command from within the project folder:

android update project -p .

Finally I have a task that makes a copy of that Android project into my build folder copies the JMVC build into its assets/www folder and starts building the mobile app:

    <target name="android" description="Invokes a build on the android platform" depends="build">
        <copy todir="${build}/Android">
            <fileset dir="${src}/platforms/Android"/>
        </copy>
        <copy todir="${build}/Android/assets/www/steal">
            <fileset dir="${build}/steal"/>
        </copy>
        <copy todir="${build}/Android/assets/www/${appName}">
            <fileset dir="${build}/${appName}"/>
        </copy>
        <ant antfile="${build}/Android/build.xml" dir="${build}/Android" target="debug">
        </ant>
    </target>

This is not rocket science, but I thought it may be helpful to someone just starting out with a similar project.

2 thoughts on “Javascript MVC + PhoneGap + jQm Build with Ant

  1. Thanks for that. Your instincts are correct: I have suspected that the ant build.xml file was the place to work the magic in PhoneGap. Yesterday, I just took the Touch app and manually inserted it into a blank project for iOS and Android and it worked very well. Now that you have given me this information, I can get a serviceable project in PhoneGap in no time. Cheers!

Comments are closed.