You need to do a few things to get the app ready for
distribution:
1. Removing Debug Code
There’s no reason to have debugging or logging code slowing down your app while it’s
running on a user’s phone. If you have added any such code to your HTML, CSS, or JavaScript files,
now’s the time to take it out.
You should also open up the
AndroidManifest.xml file in the
KiloGap folder, search for “debuggable” and set it
to false. When you’re done, it should look something like this:
...
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="false">
...
Note:
While you have the manifest file open, you
might as well check to make sure android:icon and
android:label are specified as shown in the previous
listing. PhoneGap normally takes care of this for you, but I think
it’s worth double checking, because you won’t be able to upload your
app if these values are not set.
2. Versioning Your App
Near the top of your
AndroidManifest.xml file, you should see values set for the version name and version
code for your app:
...
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jonathanstark.kilo"
android:versionName="1.0.0"
android:versionCode="1">
...
Because this is probably your first app,
these values are fine as is. Once you’ve published your app and later
want to release an update, you’ll update these values appropriately. The
Android system doesn’t check or enforce this version information, but
it’s a critical piece of data for your long term app strategy.
The version name is the value that will be
shown to the user. It’s a string, so you can put whatever you want here, but the
common practice is to use a
<major>.<minor>.<point> format (such as
1.0.0).
The version code is expected to be a positive
integer value. It need not correspond to the version name in any way. In
fact, it probably won’t—you should just increment it by 1 every time you
release an update, regardless of whether the release is a major upgrade
or a minor bug fix.
3. Signing Your App
Android requires that all apps be digitally signed by the developer. The process for doing
so is easy, but a little cryptic:
Launch the Terminal application and
navigate into the KiloGap directory:
cd ~/Desktop/KiloGap
Compile the app in release mode:
ant release
You’ll see a page or so of output scroll
by, ending with BUILD SUCCESSFUL. An unsigned binary named
Kilo-unsigned.apk will now be sitting in the
~/Desktop/KiloGap/bin/ directory (Figure 1).
Create a private key:
keytool -genkey -v -keystore keystore -alias alias -keyalg RSA -validity days
This command is interactive and will ask
you a bunch of questions. Mine looks like this:JSC-MBP:KiloGap jstark$ keytool -genkey -v -keystore myAndroidKey.keystore \
-alias myAndroidKeyAlias -keyalg RSA -validity 10000
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: Jonathan Stark
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]: Jonathan Stark Consulting
What is the name of your City or Locality?
[Unknown]: Providence
What is the name of your State or Province?
[Unknown]: RI
What is the two-letter country code for this unit?
[Unknown]: US
Is CN=Jonathan Stark, OU=Unknown, O=Jonathan Stark Consulting, L=Providence,
ST=RI, C=US correct?
[no]: yes
Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with
a validity of 10,000 days for: CN=Jonathan Stark, OU=Unknown, O=Jonathan Stark
Consulting, L=Providence, ST=RI, C=US
Enter key password for <myAndroidKeyAlias>
(RETURN if same as keystore password):
[Storing myAndroidKey.keystore]
When the process completes, you should
see myAndroidKey.keystore created in the
~/Desktop/KiloGap directory (Figure 2). If you’d like to use this keystore for other
apps in the future, you might want to move the keystore file to a
more central location.
Warning:
Do not lose this password. If you
forget your keystore password, you won’t be able to update your
app once it’s published.
Sign your app with the key you just
created:
jarsigner -verbose -keystore myAndroidKey.keystore
./bin/Kilo-unsigned.apk myAndroidKeyAlias
When you run this command, you’ll be
asked for your keystore password.
Align the .apk
file:
zipalign -v 4 ./bin/Kilo-unsigned.apk ./bin/Kilo.apk
You’ll see a page or so of output scroll
by, ending with “Verification successful.” A signed binary named
Kilo.apk will now be sitting in the
~/Desktop/KiloGap/bin/ directory (Figure 3). This .apk file is your
completed app!