Skip to content

Instantly share code, notes, and snippets.

@mohsin
Last active January 4, 2021 22:05
Show Gist options
  • Save mohsin/e224604c8c5aa7546ce2e9cb6302f5bd to your computer and use it in GitHub Desktop.
Save mohsin/e224604c8c5aa7546ce2e9cb6302f5bd to your computer and use it in GitHub Desktop.
Using Keystore properties in Android Projects
  1. Add to project-level build.gradle:
allprojects {
    ...
    afterEvaluate { project ->
        def propsFile = rootProject.file('keystore.properties')
        def configName = 'release'

        if (propsFile.exists() && project.hasProperty("android") && project.android.signingConfigs.hasProperty(configName)) {
            def props = new Properties()
            props.load(new FileInputStream(propsFile))
            android.signingConfigs[configName].storeFile = file(props['storeFile'])
            android.signingConfigs[configName].storePassword = props['storePassword']
            android.signingConfigs[configName].keyAlias = props['keyAlias']
            android.signingConfigs[configName].keyPassword = props['keyPassword']
        }
    }
}
  1. Add to app-level build.gradle
android {
    ...
    ...
    signingConfigs {
        debug {
            storeFile file("/Users/Moz/.android/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
        release {}
    }
    buildTypes {
        debug {
            applicationIdSuffix '.dev'
            versionNameSuffix '-dev'
            debuggable true
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    ...
    ...
}
  1. Create keystore.properties in root folder of project
storeFile=/Users/Moz/Client/Current/ClientPerson/Credentials/SigningKey.jks
storePassword=client111!#
keyAlias=client
keyPassword=client1
@VishwasShashidhar
Copy link

Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment