Signing Your

Android requires that all apps be digitally signed by the developer. The process for doing so is easy, but a little cryptic:

1. Launch the Terminal application and navigate into the KiloGap directory:

cd ~/Desktop/KiloGap

2. 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 8-1).

□ KjloCap

_C

I of 15 selected, 125.75 CS available

* Date Modified

[j, f. |— - J". -, ■

^ AndroidManlfest.xml

Today, 3:11 PM

Today, 3:1

► Q asiets

Today, 3:11 PM

Today, 3

1

▼ If bin

Today, 3:11 PM

Today, 3:1

► classes

Today, 3:11 PM

Today, 3:1

classes, dex

Today, 3:11 PM

Today, 3:1

¡j Kilo-unsigned.apk

Today, 3:11 PM

Today, 3:1

Kifo.ap_

Today, 3

11 PM

Today, 3

lif1 build,properties

Today, 3

11 PM

Today, 3

t build.xml

Today, 3

11 PM

Today, 3

i default.properties

Today, 3

11 PM

Today, 3

► [Jj gen

Today, 3

11 PM

Today, 3

► CJ libs

Today, 3

11 PM

Today, 3

f local.properties

Today, 3

11 PM

Today, 3

► D res

Today, 3

11 PM

Today, 3

► Q src

Today, 3

11 PM

Today, 3

f-

-*

)•* 1

Figure 8-1. The ant release command creates an unsigned binary named Kilo-unsigned.apk in the ~/Desktop/KiloGap/bin/ directory

3. 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,

Generating 1,024 bit RSA key pair and self-signed certificate (SHAlwithRSA) 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 8-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.

Figure 8-2. The keytool command will generate a keystore file named myAndroidKey.keystore in the KiloGap directory

Do not lose this password. If you forget your keystore password, you won't be able to update your app once it's published.

4. 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.

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 8-3). This .apk file is your completed app!

A r\ n

Ul KiloCap

1 1

1 of 17 selected, 125.75 G8 available

* rinKi

Date Create

$ AndroidManifest.xml

-

1 3

11 PM

Today, 3:1

► Q assets

Today, 3:11 PM

Today, 3:1

T m bin

Today, 3:14 PM

Today, 3:1

► classes

Today, 3:11 PM

Today, 3:1

classes, dex

Today, 3:11 PM

Today, 3:1

Kilo-unsigned.apk

Today, 3:13 PM

Today, 3:1

Kilo.ap_

Today, 3:11 PM

Today, 3:1

B Kilo.apk

Today, 3:14 PM

Today, 3:1

? build.properties

Today, 3

11 PM

Today, 3:1

1? build,xin

Today, 3

11 PM

Today, 3:1

* default.properties

Today, 3

11 PM

Today, 3:1

► Cj gen

Today, 3

11 PM

Today, 3:1

► Q libs

Today, 3

11 PM

Today, 3:1

S local.properties

Today, 3

11 PM

Today, 3:1

_ mvAndroidKey.keystore

Today, 3

13 PM

Today, 3:1

► D res

Today, 3

11 PM

Today. 3:1

► Q src

Today, 3

J11 ► U

Figure 8-3. Once you run the jarsigner and zipalign commands, your final app will be generated in the ~/Desktop/KiloGap/bin/directory

0 0

Post a comment