flutter release apk |
To publish your app on Play Store, you need to give your app a digital signature.
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
keytool -genkey -v -keystore c:/Users/USER\_NAME/key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
Enter keystore password: test@12345
Re-enter new password: test@12345
What is your first and last name?
[test]: test
What is the name of your organizational unit?
[test]: test
What is the name of your organization?
[test]: test
What is the name of your City or Locality?
[test]: test
What is the name of your State or Province?
[test]: test
What is the two-letter country code for this unit?
[tt]: tt
Is CN=test, OU=test, O=test, L=test, ST=test, C=tt correct?
[no]: yes
//OUTPUT
Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
for: CN=test, OU=test, O=test, L=test, ST=test, C=tt
[Storing /home/<user name>/key.jks]
Common errors while signing the app
Command 'keytool' not found
run command :
sudo apt install openjdk-11-jre-headless
or
sudo apt install openjdk-8-jre-headless
Write the following lines inside the newly created 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>
Navigate to /android/app/build.gradle file.
1. Replace the following
android {
with
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
2. Replace the following
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now,
// so \`flutter run --release\` works.
signingConfig signingConfigs.debug
}
}
with the signing config info
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Now, every release build of your app will be signed automatically
Running flutter build defaults to a release build
flutter build appbundle
Note : release bundle for your app is created at /build/app/outputs/bundle/release/app.aab
flutter build apk
Note : the above command “flutter build apk” builds a fat apk
OR
flutter build apk --split-per-abi
Note : the above command generated two apk files
Review App Manifest File, AndroidManifest.xml, located in <app dir>/android/app/src/main
Review the build configuration, Gradle build file, build.gradle, located in <app dir>/android/app
Navigate to defaultConfig code block and verify