Skip to content

APK Signing configuration

Bhaumik Soni edited this page May 15, 2017 · 1 revision

Steps to create signed apk

Note : this is one time setup for your project. After following below steps, whenever you wants to generate signed apk, you just want to follow step #5 only.

  1. Create a file named keystore.properties in the root directory of your project. This file should contain your signing information, as follows:

    storeFile=YOUR_STORE_FILE_LOCATION
    storePassword=YOUR_STORE_PASSWORD
    keyAlias=YOUR_KEY_ALIAS
    keyPassword=YOUR_KEY_PASSWORD
  2. In your module's build.gradle file, add code to load your keystore.properties file before the android {} block.

    ...
    
    // Create a variable called keystorePropertiesFile, and initialize it to your
    // keystore.properties file, in the rootProject folder.
    def keystorePropertiesFile = rootProject.file("keystore.properties")
    
    // Initialize a new Properties() object called keystoreProperties.
    def keystoreProperties = new Properties()
    
    // Load your keystore.properties file into the keystoreProperties object.
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    
    android {
    ...
    }
  3. You can refer to properties stored in keystoreProperties using the syntax keystoreProperties['propertyName']. Modify the signingConfigs block of your module's build.gradle file to reference the signing information stored in keystoreProperties using this syntax.

    android {
        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            }
        }
        ...
    }
  4. Add signingConfig signingConfigs.release in release{} block as given below to apply configuration to release build

    android {
        ...
        defaultConfig { ... }
        signingConfigs { ... }
        buildTypes {
            release {
                signingConfig signingConfigs.release
                ...
            }
        }
    }
  5. Open the Build Variants tool window and ensure that the release build type is selected.