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
-
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. -
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>
- 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
- 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