Build AAB file and Sign key later with Jarsigner

Thế Dũng
3 min readDec 28, 2021

If you have ever published an app to the Play Store, maybe you have looked at something like this

With this config in app build.gradle, you can build an aab file and it was signed with upload key which was specified with storeFile, alias and password. But what if you want to build the app with unsigned key and sign it later?

For example: Your development team just take the responsibility for creating the app, and other team will sign the app with their upload key and then upload it to the Play Store.

So, the progress will be divided into 2 step:

  • Build the app without upload key
  • Sign the app with upload key

Step 1: Build aab file

It is very easy with the first step, you just need to remove the signingConfig from buildTypes { release {}}, then build app with command:

//Linux:
./gradlew bundleRelease
//Windows:
gradlew bundleRelease

To use this gradlew command, you must navigate the woking directory to the folder contain gradlew file (By default, it should be at the root of the android project)

After the running progress is done, you can archive the aab file by accessing to the outputs directory (build\app\outputs\bundle\release)

Then we’ve done step 1.

Step 2: Sign the app with upload key

This step require an upload key, which is used to sign the app and upload to the Play Store. So to create the key, run the following command:

keytool -genkey -v -keystore my-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
  • my-key.keystore is the file name of the key store file
  • alias_name is the name of alias

After running this command, you need to provide some other information. I will put my console bellow as an example:

Then you have your keystore file. The next step is to sign this key with the aab file that we had built at step 1.

I use jarsigner as a tool to sign the app.

Open the terminal and run the following command:

jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -storepass abcdxyzt1234 -keystore my-key.keystore app-release.aab alias_name
  • storepass is the keystore password that you entered in previous step
  • my-key.keystore is the name of the keystore file that you want to sign the app-release.aab file with.
  • alias_name is the name of alias that you want to use to sign the app.

At this step, you need to put the keystore file and the aab file in the same directory, where is the current terminal is running. (If the aab file and keystore file are not in the same directory, you need to provide the path to the file instead of file name only. Ex: aab/app-release.aab instead of app-release.aab)

After running the above command, the terminal will show the signing information

You’ve done the signing progress now. Your aab file now is signed with upload key. You can use this aab file for release the app in Play Store.

Bonus step:

This sign-key command line is quite long to remember, so I put it in a shellscript file (.sh file on mac/linux and .bat file on windows) to make it more easy to execute.

sign.bat
./sign.sh

Thank you very much for taking your time to read this article. Hope that you can learn something from my post!

--

--