Skip to content

Instantly share code, notes, and snippets.

@mahdi-malv
Last active February 6, 2021 15:11
Show Gist options
  • Save mahdi-malv/0c4cd79e38544d95cfe94b3f18cc2cbf to your computer and use it in GitHub Desktop.
Save mahdi-malv/0c4cd79e38544d95cfe94b3f18cc2cbf to your computer and use it in GitHub Desktop.

Sign application with signKey (Best way)

  • signed with parameters via command line, use them
  • If not signed with parameters, use the key.properties

Prerequisites

  • Add the following snippet to app:build.gradle -> android { }
android {
    // ...
    signingConfigs {
      release {
        if (findProperty("keyStorePath") != null) {
            storeFile file(findProperty("keyStorePath"))
            storePassword findProperty("keyStorePassword")
            keyAlias findProperty("keyAlias")
            keyPassword findProperty("keyPassword")
        } else {
            def keystoreProperties = new Properties()
            keystoreProperties.load(new FileInputStream(rootProject.file('key.properties')))
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
      }
    }
}
  • Use
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
    debug {
        minifyEnabled false
        signingConfig signingConfigs.release
    }
}

Sign via commandline:

Use this command:

./gradlew assembleRelease -PkeyStorePath=keyStore/signKey -PkeyStorePassword=PASS -PkeyAlias=ALIAS -PkeyPassword=SIGN_PASS

Sign automatically on build (buildApk):

  • Create a file named key.properties and add:
keyAlias=ALIAS
keyPassword=KEY_PASS
storeFile=KEY_ADDRESS
storePassword=STORE_PASS
(In the root dir)

On building Android studio will automatically use the signKey

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