To build my Android app (which I call TweetMe) from its HTML, CSS, and JavaScript sources, I create a folder called tweetme in my home directory, and in that tweetme folder I place another folder called tweetme wich contains the sources (HTML, CSS, JavaScript):
This will create the directory ~/tweetme/tweetme_android which contains everything we need to build our final app from it. The ~/tweetme/tweetme_android/assets/www/ directory contains our HTML, CSS, JavaScript sources plus the phonegap.<version>.js file.
Important: I found a problem with the phonegap.0.9.5.js file - it contains several lines with a prompt() function that asks the user some questions (it asks for getPort, getToken, getServer, restartServer, usePolling), and this is clearly not what you want inside your app - see the following screenshots:
As a solution for this problem, you can either edit phonegap.0.9.5.js and comment out all lines that contain the prompt() function (there are six lines), or you download PhoneGap 0.9.4 from http://phonegap.googlecode.com/files/phonegap-0.9.4.zip (PhoneGap 0.9.4 doesn't use the prompt() function), extract the phonegap.0.9.4.js file from it, delete phonegap.0.9.5.js from the assets/www/ directory and place phonegap.0.9.4.js in the assets/www/ directory instead.
If you prefer to comment out all lines that contain the prompt() function in phonegap.0.9.5.js, but don't want to edit the file manually, you can use the following command which comments out all six lines automatically (the command works fine for phonegap.0.9.5.js; however, it might not work for future versions, so please keep this in mind!):
sed -i '/prompt/s;^;//;' assets/www/phonegap.0.9.5.js
The libs/ directory contains the file phonegap.<version>.jar:
ls -l libs/
falko@falko-virtual-machine:~/tweetme/tweetme_android$ ls -l libs/
total 136
-rw-r--r-- 1 falko falko 139004 2011-06-21 14:25 phonegap.0.9.5.jar
falko@falko-virtual-machine:~/tweetme/tweetme_android$
Now we must edit the index.html file in the assets/www/ folder and add the phonegap.<version>.js file to the <head></head> section (before all other JavaScript files/JavaScript code).
gedit assets/www/index.html
Let's assume the file starts as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tweetme</title>
<!-- include JQuery through Google API => Always have the latest version -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript"> google.load("jquery", "1.3.2"); </script>
<!-- import JQTouch -->
<script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script>
<!-- Import JQTouch default style (iPhone look).
Replace the string "themes/apple" with "themes/jq" for a non-iPhone theme -->
<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">
<link type="text/css" rel="stylesheet" media="screen" href="themes/apple/theme.css">
[...]
Add the line <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script> before all other JavaScript so that it looks as follows (if you have replaced phonegap.0.9.5.js with phonegap.0.9.4.js, please use the line <script type="text/javascript" charset="utf-8" src="phonegap.0.9.4.js"></script> instead ):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tweetme</title>
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
<!-- include JQuery through Google API => Always have the latest version -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript"> google.load("jquery", "1.3.2"); </script>
<!-- import JQTouch -->
<script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script>
<!-- Import JQTouch default style (iPhone look).
Replace the string "themes/apple" with "themes/jq" for a non-iPhone theme -->
<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">
<link type="text/css" rel="stylesheet" media="screen" href="themes/apple/theme.css">
[...]
Now, still in the ~/tweetme/tweetme_android directory, we can finally build our app:
ant debug
It should say BUILD SUCCESSFUL at the end:
[...]
-package-debug-sign:
[apkbuilder] Creating tweetme-debug-unaligned.apk and signing it with a debug key...
debug:
[echo] Running zip align on final apk...
[echo] Debug Package: /home/falko/tweetme/tweetme_android/bin/tweetme-debug.apk
BUILD SUCCESSFUL
Total time: 38 seconds
falko@falko-virtual-machine:~/tweetme/tweetme_android$
You can now find your app in the bin/ directory (called tweetme-debug.apk; apk is the extension for Android apps):
Please do not use the comment function to ask for help! If you need help, please use our forum. Comments will be published after administrator approval.
Recent comments
1 day 1 hour ago
1 day 6 hours ago
1 day 8 hours ago
1 day 9 hours ago
1 day 10 hours ago
1 day 15 hours ago
1 day 16 hours ago
1 day 18 hours ago
2 days 7 hours ago
2 days 9 hours ago