Building Signed APKs

Building signed APK's for Android is easy if you know what you are doing.

This article goes over the preparation steps and the additional build instructions needed to created signed APKs.

Preparation

First you need to have a keystore. Use this command:

#!/bin/bash
keystore_file="my_key_store.keystore"
key_name="john_doe"
secret='fake_password'
name='John Doe'
dept='Engineering'
org='TLabs Inc'
place='New York'
province='NY'
country='US'

keytool -genkey -v -keystore "$keystore_file" -alias "key_name" -keyalg "RSA" -validity 10000 -storepass "$secret" -keypass "$secret" <<EOF
$name
$dept
$org
$place
$province
$country
yes
EOF

Remember the keystore file and passwords.

Build instructions

In your build.gradle you need the following:


android {
  signingConfigs {
    release {
      storeFile file("my_keystore.keystore")
      storePassword "{password}"
      keyAlias "Key_Alias"
      keyPassword "{password}"
    }
  }
  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }
}