[Android Themes] Raiz:
VI-Sign and Zipalign

​

We must sign an app after having modified it, so it can be installed properly on our devices. System Apps MUST keep the same signature they had before modifying, or else the app will continuously force close, and it may even result in bootloops and other bad things.

To keep the signature take the META-INF folder from the not decompiled apk (browse it as a zip file) and put it in the newly recompiled apk (browse it as a zip file too, if there is already a META-INF folder, just replace it)

Links to build and platform tool:

Platform-tools: https://developer.android.com/studio/releases/platform-tools​

Build-tools: Have to be downloaded from sdk manager in android studio​

A)Official way:

​

Tool used in the correct order:

1)keytool (included inside java)

2)zipalign from build tools (29.0.2 here, but use the latest )

3)apksigner from build tools (29.0.2 here, but use the latest) (+the lib folder containing apksigner.jar)

Where are build tools?

Mac: ~/Library/Android/sdk/build-tools/[your buld-tool version]/

Linux: ~/Android/sdk/build-tools/[your buld-tool version]/

Windows: C:/User/yourusername/AppData/Local/Android/sdk/build-tools/[your buld-tool version]/

Disclaimer:

Using jarsigner is also possible (tool natively included in java jdk), if you use it, make sure you zipalign AFTER signing.

Make sure that apksigner (and lib) as well as zipalign are in the folder you’re apk is in.

Make sure they’re all executable (check that using chmod) and on mac os, make sure your terminal has full disk access (I had a hard time figuring this out lol).

​

1-Generate keystore:

​

This is pretty simple, we’ll use keytool, at tool antively included in java jdk. We’ll need only one thing before using apksigner : the keystore.jks file (or a separate certificate and private key, but that’s more complicated)

keytool -genkey -v -keystore ~/Desktop/apktool/keystore.jks -alias Raiz -keyalg RSA -keysize 2048 -validity 10000​

Just replace the alias (here Raiz) by a familiar name, you have to remember it! (here’s why)

Also replace the name of the jks file (but not it’s extension, even though it can be .keystore, I had less issues with .jks)

Quick explanation of what does what in the command:

keytool : the command to use keytool obviously

-genkey : generate the keystore

-v : display verbose

-keystore : set the path to the future file

~/Desktop/apktool/keystore.jks : Path and name of the future file, you can call the keystore whatever you want to.

-alias Raiz : specify the alias used, it can be whatever you want, but remember it, it’s like a publisher name

-keyalg RSA : specify the algorithm used for the key, here it’s RSA (here’s a bit of history)

-keysize 2048: the size of the key in bits

-validity 10000: validity in days, here 10000 days

1*- Generate key.pk8 and cert.pem:

​

This is a quote from another thread (by @wilskywalker), this isn't necessary, but can come handy when signing zip, so I'll leave that here anyway.

2- Zipalign:

​

​

./zipalign -v 4 firfox-mod.apk firefox-aligned.apk
​

Quick explanation:

-v : verbose

4 : align on 4 bits, putting another value will align the wrong way, just keep 4

firefox-mod.apk: name of the input apk, can be anything

firefox-mod-aligned.apk: name of the output apk, can be anything too

3-Sign the apk with apksigner:

​

./apksigner sign --ks keystore.jks firefox-mod-aligned.apk​

Quick explanation:

sign: the command use to sign

--ks keystore.jks : specify the keystore file (the same one we generated seconds ago)

firefox-mod-aligned: the input apk (the one we just aligned), note that the apk will be signed and there won’t be any output apk this time

And you’re done, you can check that it has been properly signed with this command:

./apksigner verify firefox-mod-aligned​

Where firefox-mod-aligned is the apk signed we want to check

​

3*-Sign the apk with apksigner using .pk8 and .pem files:

​

./apksigner sign ---key key.pk8 --cert certificate.pem firefox-mod-aligned.apk​

Credits, links for this part:

How to sign an app (by Google)

apksigner documentation

keytool documentation

zipalign documentation

Stack Overflow post

@Rizal Lovins ’ Guide

B) Unofficial ways:

​

Some amazing devs and contributors at xda provided us with tools to sign with ease APKs (without having to think about all of that),I didn’t fully tested every one fo them, but you can try them as an alternative if the “official way” didn’t worked out well.

Here they are:

APK easy tool by @evildog1

APK Sign/Zipalign/Install by @aureljared

Uber APK signer (Github)