Signing Android App With Gradle Using CLI

Recently I stumbled upon a problem of creating a signed Android app via command line, after spending some time on this, I have decided to post following tutorial.
This problem exist in 2 situations. For example when you want to share your application publicly, but do not want to share any details about your signing key or you would like to automate building process using some kind of CI server.

Create a new key store using Android studio (or use existing one), this document shows how to create a new keystore:
After your key is created you need to setup gradle properties like this. I have edited following file: /home/w/.gradle/

This file is later used in build.gradle file like this:

Please note the signingConfigs option, these are read by gradle from the previously created file.

To build singed application just run:

From the root folder of your repository.

This will create signed apk file in app/build/outputs/apk. File will be called app-release.apk