android tutorial - Define the signing configuration in an external file in android | Developer android - android app development - android studio - android app developement



define-the-signing-configuration-in-an-external-file-in-android

You can define the signing configuration in an external file as a signing.properties in the root directory of your project. For example you can define these keys (you can use your favorite names):

STORE_FILE=myStoreFileLocation    
STORE_PASSWORD=myStorePassword
KEY_ALIAS=myKeyAlias
KEY_PASSWORD=mykeyPassword
click below button to copy code from our android learning website - android tutorial - team

Then in your build.gradle file

android {

    signingConfigs {
        release
    }
    
     buildTypes {
        release {
            signingConfig signingConfigs.release
        }
     }
}
click below button to copy code from our android learning website - android tutorial - team

Then you can introduce some checks to avoid gradle issues in the build process.

//------------------------------------------------------------------------------
// Signing
//------------------------------------------------------------------------------
def Properties props = new Properties()
def propFile = file('../signing.properties')
if (propFile.canRead()) {

    if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
            props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {

        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        android.buildTypes.release.signingConfig = null
    }
} else {
    android.buildTypes.release.signingConfig = null
}
click below button to copy code from our android learning website - android tutorial - team

Related Searches to Define the signing configuration in an external file in android