Skip to content

Instantly share code, notes, and snippets.

@maheshj01
Last active July 11, 2021 13:46
Show Gist options
  • Save maheshj01/6c643deefcedb40362403615d3db35ca to your computer and use it in GitHub Desktop.
Save maheshj01/6c643deefcedb40362403615d3db35ca to your computer and use it in GitHub Desktop.
Signing a android app with a releaseKey

Before following the below steps generate a key.jks file using this command source

MacOs/Linux

keytool -genkey -v -keystore ~/<path where key needs to be generated>.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

Windows

keytool -genkey -v -keystore c:\Users\USER_NAME\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload
  1. Create a file named key.properties you can store it anywhere I am storing it here for this project /android/key.properties that contains a reference to your keystore.

  2. add these lines in that file

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, such as /Users/<user name>/key.jks>
  1. storeFile is basically where you place the file if you place key.jks in android folder then sample key.properties will be like this
storePassword=android
keyPassword=android
keyAlias=key
storeFile=..\\key.jks
  1. in App level build.gradle (app/build.gradle) Add the keystore information from your properties file before the android block:
android{
  ...
}

def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

before buildTypes { } block add the SigningConfigs block with the info

signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

Note: Remember its not safe to checkin your key.jks and key.properties to version control.

ISSUES for mismatch signing algorithm: flutter/website#5871

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