Select Page

Gradle is the build system used by Android Studio .

Android requires that all APKs be digitally signed with a certificate before they can be installed. For signing your APK you need to create certificate and keystore.

You can Sign your APK using build.gradle.By using build.gradle effectively you can make your everyday Android developer life better.

For sign your APK you need to modify the signingConfigs block of your module’s build.gradle file to reference the following information.

storeFile : Path of your keystore file.

storePassword : Password of your keystore.

keyAlias : An identifying name of your key.

keyPassword : Password of your key.

When you create a signing configuration, Android Studio adds your signing information in plain text to the module’s build.gradle files. For hiding this sensitive information you can place this data into your gradle.properties or you can create a separate properties file for storing keystore.

For this process you can use the following piece of code :

In your gradle.properties (Project Properties)

release_keystore_path=/Path/Of/Your/Keystore/KeyStoreName.jks
release_keystore_password=P@ssword1
release_key_alias=KeyIdentifier
release_key_alias_password=KeyP@ssword1

In your build.gradle


Properties keystoreProperties = new Properties();
keystoreProperties.load(new FileInputStream(file(rootProject.file("gradle.properties"))))

signingConfigs
{
  release
  {
    storeFile file(keystoreProperties["release_keystore_path"])
    storePassword keystoreProperties["release_keystore_password"]
    keyAlias keystoreProperties["release_key_alias"]
    keyPassword keystoreProperties["release_key_alias_password"]
  }
}

After creating the signing configuration, you need to add this into your build types like

buildTypes 
{
  release 
  {
    shrinkResources true
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    signingConfig signingConfigs.release
  }
}
View Gist

 

 

Latest posts by Ranjith Kumar (see all)