MOBILE

Building Android Apps : Build KiloGap

1/11/2011 4:22:45 PM

Next, we’re going to convert our web app into a native Android app. The gang at Nitobi has created a little helper application named droidgap to help us with this. When you run droidgap, it’ll ask you a few questions and insert your answers into a bunch of locations throughout a template to create your project. It’s very cool; in fact, if you ever run into someone from Nitobi, you should buy him a martini.


Note:

The Android SDK requires Apache Ant, which is included with Mac OS X and many versions of Linux. If you’re using Windows, see http://ant.apache.org/manual/install.html. You will need to install Ant before you can run droidgap.


  1. To begin the wizard, launch the Terminal application and enter the following command:

    droidgap wiz

    The wizard will ask you for a few pieces of information that will be used to generate your PhoneGap project (Figure 1).

    Figure 1. The droidgap wizard asks you a few questions and builds a customized Android project based on your answers

  2. When prompted, enter a name for your app. This is the name that will be displayed to the user in various places on the phone (e.g., beneath the home screen icon for your app, in the list of applications). I’m going to enter “Kilo.”

  3. When prompted, enter a package name for your app. The package name serves as a unique identifier for your app. Typically, people use reverse domain name syntax for app package names. I’m going to enter com.jonathanstark.kilo, but you should use your own domain name.

  4. When prompted, enter the path to the folder on your computer that contains the HTML, CSS, and JavaScript files for your web app. My files are in a folder named www on my desktop (Figure 2), so I’ll enter:

    ~/Desktop/www

    Figure 2. My HTML, CSS, and JavaScript files are in a folder named www on my desktop

  5. When prompted, enter a directory path for your project. The directory must not already exist—droidgap is going to create it for you. If a directory exists at the path you specify, droidgap will give you an error and ask for a different path. I want droidgap to put my PhoneGap project on my desktop in a directory named KiloGap, so I’m going to enter the following:

    ~/Desktop/KiloGap

  6. When prompted, enter the Android SDK platform you are targeting. If you followed the instructions above to install all Android SDK platforms, your target platform ID is android-7.

    If you want to target a different platform, you can get a list of available platform IDs by leaving the platform ID blank and pressing Enter. In the list that appears, the first line of each entry will have an ID displayed as both an integer and string (e.g., id: 2 or "android-4"). Enter the string version of the ID without quotes (i.e., android-4) when the droidgap prompt returns.

After entering the target SDK ID, droidgap will build your project and put the files in the output directory you specified. The process should only take a couple of seconds (Figure 3).

Figure 3. droidgap will build your project and put the files in the output directory you specified


If you navigate to the ~/Desktop/KiloGap/assets/www/ directory, you’ll notice that droidgap has deposited a file named phonegap.js alongside your other application files. This is the file that PhoneGap uses to expose certain native device functionality via JavaScript. To make use of phonegap.js, you have to include it in the head section of your index.html file like so:

...
<head>
<title>Kilo</title>
<link type="text/css" rel="stylesheet"
media="screen" href="jqtouch/jqtouch.css"/>
<link type="text/css" rel="stylesheet"
media="screen" href="themes/jqt/theme.css"/>
<link type="text/css" rel="stylesheet"
media="screen" href="kilo.css"/>
<script type="text/javascript" src="phonegap.js" charset="utf-8"></script>
<script type="text/javascript" src="jqtouch/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="jqtouch/jqtouch.js" charset="utf-8"></script>
<script type="text/javascript" src="kilo.js" charset="utf-8"></script>
</head>
...
Other  
  •  Building Android Apps: Create an Android Virtual Device
  •  Building Android Apps: Going Native - Setting Up the Environment
  •  Building Android Apps: Introduction to PhoneGap
  •  iPhone Application Development : How Xcode and Interface Builder Implement MVC
  •  iPhone Application Development : Understanding the Model-View-Controller Paradigm
  •  Building Android Apps: Going Offline - Debugging
  •  Building Android Apps: Creating a Dynamic Manifest File
  •  Building Android Apps: Online Whitelist and Fallback Options
  •  The Basics of the Offline Application Cache
  •  Building Android Apps: Web SQL Database (part 4) - Deleting Rows
  •  Building Android Apps: Web SQL Database (part 3) - Selecting Rows and Handling Result Sets
  •  Building Android Apps: Web SQL Database (part 2) - Inserting Rows
  •  Building Android Apps: Web SQL Database (part 1) - Creating a Database
  •  Building Android Apps: Web Storage
  •  Building Android Apps : Simple Bells and Whistles
  •  Building Android Apps : Traffic Cop
  •  iPhone Application Development : Exploring Interface Builder - Connecting to Code
  •  iPhone Application Development : Customizing Interface Appearance
  •  iPhone Application Development : Creating User Interfaces
  •  iPhone Application Development : Understanding Interface Builder
  •  
    Top 10
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 8)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 7)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 6)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 5)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 4)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 3)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 2)
    A Trio From HIS: 7970 IceQ X² GHz Edition, 7950 IceQ X² Boost Clock And 7850 IceQ Turbo X Graphics Cards Review (Part 1)
    Lenovo IdeaPad Yoga 13 - One Of The First Convertible Windows 8 Tablet/Laptops
    HP Pavilion G4 - Four Times The Gs
    Most View
    Samsung Ultra 535 AMD-powered Ultraportable Laptop (Part 2)
    Windows Server 2003 : Active Directory - Understanding Directory Replication (part 3) - Spanning Trees and Site Links
    Creating and Managing Views in SQL Server 2008 : Definition of Views & Using Views
    Drying A Wet Mobile Phone
    Windows 8 vs. OS X Mountain Lion (Part 2)
    DIY Social Networking with BuddyPress
    Connect-Back Shellcode
    sp_configure and SQL Server Management Studio
    Send an Email via SMTP
    The SQL Programming Language : Complex Queries and Join Queries (part 1)
    Windows Server 2003 : Dynamic DNS
    Technology For Business (Part 2)
    Linking PCs with a Network : Connecting Wirelessly
    The games that we play (Part 2)
    Nzxt Phantom 410
    Using Non-Windows Systems to Access Exchange Server 2010 : Understanding Non-Windows–Based Mail Client Options
    The Benefits Of A Technet Subscription (Part 1)
    Programming the Mobile Web : WebKit CSS Extensions (part 5) - Transformations
    Top 10 Video Streaming – Q1 2013
    Noctua NH-L12 - Low-Profile And Low Noise