Categories
Android 🏴‍☠️

How to sign an unsigned Android package (.apk file) using command line

Spread the love

1. Export the unsigned package:

Right click on the project in Eclipse -> Android Tools -> Export Unsigned Application Package

2. Check environment avialable “JAVA_HOME : C:Program FilesJavajdk1.7.0_21bin”

“C:Program FilesJavajdk1.7.0_21bin” for jarsigner and keytools..
… or whatever jdk version you have

open cmd.exe,

3. Sign the application using your keystore and the jarsigner tool (comes with the JDK):

Change directory to where your unsigned .apk file is. Then run:

[sourcecode language=”css”]<br />keytool -genkey -v -keystore C:UsersuserDesktopmy-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000<br />[/sourcecode]

Then you will have be presented with:
Enter keystore password: (type in a password you will use)
Re-enter new password: (type in same password here)
What is your first and last name? Anton
What is the name of your Organization unit? (You dont have to type anything really)
What is the name of your city or locality?
What is the name of your state or providence?
what is the two-letter country code for this unit? US
is CN=Anton C=US correct?
[no]: yes (type yes there)
Enter key password for
: (push enter)

[sourcecode language=”css”]<br />jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore C:UsersthanaDesktopmy-release-key.keystore C:UsersthanaDesktopk.apk alias_name<br />[/sourcecode]

Enter Passphase for keystore: (your password you made earlier)
adding: META-INF/MINFEST.MF ….
…….
…..
…Signing: classes.dex

[sourcecode language=”css”]<br />jarsigner -verify -verbose -certs C:UsersthanaDesktopkeyk.apk<br />[/sourcecode]

4.Align the APK (must use -v 4 option):
Check directory adt tools
C:UsersthanaDownloadsadt-bundle-windows-x86_64adt-bundle-windowssdktools

[sourcecode language=”css”]<br />zipalign -v 4 C:UsersthanaDesktopk.apk C:UsersthanaDesktopk_align.apk<br />[/sourcecode]

As you can see, zipalign expects you to provide the input .apk file and specify what you want the output file to be named.

ref:
http://developer.android.com/tools/publishing/app-signing.html#debugmode
http://www.talkandroid.com/android-forums/android-market-reviews/1317-tutorial-signing-your-apk-publishing.html

How to sign an unsigned Android package (.apk file)


http://wiki.ludei.com/cocoonjs:androidapk
How to sign Android APK file using command line

Spread the love

2 replies on “How to sign an unsigned Android package (.apk file) using command line”

Comments are closed.