Photo by Lisa Fotios from Pexels
Table Of Contents
- Introduction
- Keystore-keytool
- Keystore-password
- keystore-credentials
- keystore-alias-password
- Successful Keystore
- Jarsigner
- Zipalign
🎯 Introduction
Hey, if you're here, that means you're already familiar with APK files. Well, in the case you don't know 🤗
An APK file is the file format used to install the applications on android operating system
To Pull this off, we would be needing the following:
- JDK, this should come with your Downloaded and Installed Java, else Download your System version Java, and install
- Set Java Home Directory, let's assume for a sec you haven't done this yet, Learn to set Java Home
🎯 Keystore-keytool
This is the MOST important part of any APK file, as this creates a unique ID-like key for your application, which will always be needed for everytime there's a need for an update on your app, so keep this safe.
NB: If you're uploading your Folder (repo) to a Version Control System (like Github), please
remember to add it to your .gitignore . (the file looks like this george.keystore, i.e,
depending on what you name it, but the extension will be *.keystore)
From your preferred command line interface (cmd.exe) run the below code:
$ keytool -genkey -v -keystore [keystore_name].keystore -alias [alias_name] -keyalg RSA -keysize 2048 -validity 10000
I will try and explain the essential parts of the code above;
- [keystore_name]: would be the name you wish to give your keystore, say calculatore.keystore
-
[alias_name]: would be the alias for your keystore
NB: Copy the above code snippet, paste on your command line, then make the changes to your
standard, then hit enter to run the code.
🎯 Keystore-password
Immediately the above code runs, a dialog comes up, for you to secure your keystore with a password.
NB: This is a command line interface, so your text would be hidden, but not to worry,
you'll retype for confirmation sake
🎯 keystore-credentials
These are simply additional details required of you.
NB: Please provide what you can remember, as the information you provide, is fused with
the keystore being created.
NB: When you hit enter after the country code, the next dialog will be a summary
for you so confirm the details you provided before commencing.
🎯 keystore-alias-password
The alias you earlier chose, needs to be secured also,
NB: You can still use the keystore password also, by hitting <b>enter</b> as a
confirmation or simply provide a new one. If you're lazy like me, just hit enter 🤣🤣
🎯 Successful Keystore
Once you hit enter from the previous dialog, the below would be your popup (say everything went well oo ) 🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰.
NB: keep this baby safe, else, be ready to build another app for Playstore 😂😂😂😂
🧿 Jarsigner
jarsigner uses key and certificate information from a keystore to generate digital signatures for JAR files. A keystore is a database of private keys and their associated X. 509 certificate chains authenticating the corresponding public keys.
NB: Please, don't be mad at me, I just copied from Google and Pasted here. 😅... moving on
😎
Like the above definition, this tool will allow you to sign your APK file. Don't worry, if you'd followed everything thus far, there's 99% chance that you already have jarsigner 😊, if you don't have it, well ...🙄🙄 Check Introduction
In your cmd.exe, enter the below line of code:
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore [keystore_name].keystore [my_application.apk] [alias_name]
I will try and explain the essential parts of the code above;
- [keystore_name]: would be the same name you gave to your keystore initially, say calculatore.keystore
- [alias_name]: would be the same alias you provided earlier.
- [my_application.apk]: would be the APK file you wish to sign, now this is a bit tricky, the apk file 'app-released-unsigned.apk' will be seen (in my case), at the:
$ C:\Users\usser\Documents\GitHub\COPEDA\src-cordova\platforms\android\app\build\outputs\apk\release\app-released-unsigned.apk
NB: Take caution as to your current directory when deploying the 'jarsigner' command,
because the 'my_application.apk' would literally have to be the app-released-unsigned.apk
file, so either you copy the long file path with the apk file and paste in-place of the
'my_application.apk' or you just run the 'jarsigner' in the same direactory as the 'app-
release-unsigned.apk'.
The catch there is that, you'd have to also copy the full path to where your created
keystore file is located.
Best practive, run the 'jarsinger' in your project root, where the 'keystore' file was
saved, then append the full path of your 'app-release-unsigned.apk' file as the
'my_application.apk'
NB: The password for the keystore, is needed, provide it, and everything being equal,
you'll get your APK signed
OMG!!! you're still here 😅, that means i'm not that boring, ok, losen up a bit, we're almost there. Hey, how way your day??? Remember to take a walk now and then to ease the stress, this is the life you and I chose 🤣🤣🤣🤣. ok, moving forward...
🏁 Zipalign
If you had installed the SDK while running the Introduction part (Yikes, looks like I forgot to add that 😥)
NB: Ok, since we're building an android APK file, it's only fair we have android studio
installed yeah?. If we do, nice, because the SDK should be available, if we didn't well,
don't get pissed off...
Get your Latest Android Studio & SDK here
NB: Once done, add the Zipalign (found in the build-tools, of the API-App level you
installed) to your Operating System (OS) path.
How to Add to Path (For Win 10, will work for all windows)
Click the windows key, and search for 'env', select the Environment Variables
Double click the 'Path', then edit to add the actual path of the SDK build-tools
Click on save, another save, apply, then exit.. just nod positively to the already opened dialogs 🤗
NB: To test if we were successful, close your already opened cmd.exe (For real, close it,
else it won't work 🥱) then type 'zipalign', the response should be dope 😋
Run the below code
$ zipalign -p 4 [app-release-unsigned.apk] [my-aligned.apk]
I will try and explain the essential parts of the code above;
- [app-release-unsigned.apk]: would be the full path to the unsigned APK file
- [my-aligned.apk]: would be the New Name for Your Application, say Powercap.apk
Top comments (0)