December 29, 2016

How to sign an unsigned android apk

How to sign an unsigned android apk

I have created an hybrid mobile app using web technologies like HTML5, CSS3, AngularJS and wrapped up with cordova and generated an android apk. This generated apk is unsigned. We have to add a certificate to the unsigned apk file.

It means digitally signing the applications with a certificate as a means of identifying the author of an application and establishing trust relationships between applications. Let us look on how to sign in detail.

As i am using cordova, run the below command in command prompt from inside your project folder to build an app.

cordova build android --release

This generates an unsigned apk file in the following folder.


Copy this file to the root of your project folder and rename it to app.apk (Just for convenience)

To sign an unsigned apk we will need to do that by using a number of the tools provided by Java to "sign" our application. The first utility we will utilize is the “keytool.” The keytool utility is part of what ships with the Java Development Kit (JDK). In my system it is installed in the following location.

C:\Program Files\Java\jdk1.8.0_91\bin\keytool.exe

Now run the below command.

keytool -genkey -v -keystore the-little-techie.keystore -alias the-little-techie -keyalg RSA -keysize 2048 -validity 10000

Now we will take the .keystore file that was created with the keytool utility and sign it using another utility that ships with the JDK called “jarsigner.exe.” My jarsigner is installed in the below location.

C:\Program Files\Java\jdk1.8.0_91\bin\jarsigner.exe

Now run the below command.

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore the-little-techie.keystore app.apk the-little-techie

Now that we have signed the .apk file we will use the "zipalign" tool to prepare our application for release. The "ZipAlaign" tool can be found in the Android SDK directory. Mine is found in the below location.

C:\Users\VIVIN ANTONY\AppData\Local\Android\Sdk\build-tools\19.1.0\zipalign

We can utilize it by running the following command on our signed .apk file.

zipalign -v 4 app.apk thelittletechie_final.apk

This will create a zip aligned .apk file. Now the app is ready to publish to play store.

No comments:

Post a Comment

Popular Posts