
After completing the app development process, when the APK builds initially that one is an unsigned APK by default, not the signed APK. While publishing the app to the Playstore it is needed to build a signed APK. So, to build a signed APK the page covers the following steps.
Step 1: Create a .jks file
i) Run the following command line in your terminal
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
If you are using Java 9 or newer put -storetype JKS at the end. As of the Java 9 release, the keystore type defaults to PKS12.
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS
ii) After running the keytool command, you are requested to enter a password
Enter the password to continue
iii) After entering a password your terminal is displayed as:
Answer the questions (Not mandatory, you can skip)
Finally, your .jks file is generated.
Remember the path where your .jks file is located and copy it as [project/android/app/upload-keystore.jks like this.
Save the .jks file for the release of any other app.
Step 2: Reference the keystore from the app
Create a file named [project]/android/key.properties that contain a reference to your keystore:
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>
Note: storePassword and keyPassword must be the same as the password that you have entered to generate the upload-keystore.jks file
Step 3: Configure Signing in Gradle:
Configure Gradle to use your upload key when building your app in release mode by editing the [project]/android/app/build.gradle file.
i) Add the keystore information from your properties file before the android block:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
...
}
ii)Find the buildtype blocks and replace them with the following signing configuration info:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Step 4: Add Internet Permissions
Add internet permissions in project/android/app/source/main androidmanifest.xml :
<manifest xmlns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
Step 5: Run the following command in your terminal
Run flutter clean (this prevents cached builds from affecting the signing process.)
- i) To generate .aab file run :
flutter build appbundle
- ii) To generate .apk file run :
flutter build apk --release
Note: Before uploading this file, make sure that the line /app/upload-keystore.jks is in [project]/android/.gitignore file and the structure should be like this