how to Prepare an android app for release in flutter?

Step 1 : First review the app manifest file 

in case of flutter you will get app manifest file here at location <app dir>/android/app/src/main





step 2 : Please check your package name this will be your app unique id in playstore ( How to change package name in flutter



step 3 : Please check permission in same file  Android Manifest file 

Internet permission should be there if your app need an internet access. if your app does not need internet access then remove the internet permission line 

step 4 : Review the build configuration in file build.gradle at folder location <app dir>/android/app/



step 5 : check the default id in build.gradle file . This should be matched with Android Manifest file package name. You can change minsdkversion and targetsdkversion here only. In case of flutter versioncode and version name will be picked from pubspec.yaml file. 



step 6: Add the launcher icon 
add dev dependency in pubspec.yaml  and place icon.png under images folder
flutter_launcher_icons: ^0.7.3
flutter_icons:
  android: "launcher_icon"

  ios: true

  image_path: "images/icon.png"
see below screenshot for clarity
run below commands
flutter pub get
flutter pub run flutter_launcher_icons:main
Step 7: sign the app by creating keystore file 

You need to sign the app digitally to upload it into playstore  
Run command 

keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key 

In My Case it is " C:\Program Files (x86)\Java\jdk1.8.0_151\bin>keytool -genkey -v -keystore E:\pro jects\flutterprojects\santeyalibota/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key" 

step 8. reference the keystore file from the app 
create file at <app dir>/android/key.properties  
and load it with your data  
storePassword=<password from previous step> 
keyPassword=<password from previous step> 
keyAlias=key 
storeFile=<location of the key store file, e.g. /Users/<user name>/key.jks>

Note: Keep this file private; do not check it into public source control. 

step 9 : configure signing in build.gradle file

Replace:

android {
with the keystore information from your properties file:

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

android {
  1. Replace:
    
    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:
    
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
    
Release builds of your app will now be signed automatically.

Step 10: Enable Proguard 

Create /android/app/proguard-rules.pro file and add rules listed below.

#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
The configuration above only protects Flutter engine libraries.

Step 11 : Enable obfuscation

Open /android/app/build.gradle file and locate buildTypes definition. Inside release configuration set minifiyEnabled and useProguard flags to true. You have to also point ProGuard to the file you have created in previous step

android { ... buildTypes { release { signingConfig signingConfigs.release minifyEnabled true useProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }

Note: Obfuscation and minification can extend compilation time of the Android application.

Step 12 : build the release apk

Using the command line:
  1. cd <app dir> (replace <app dir> with your application’s directory).
  2. Run flutter build apk (flutter build defaults to --release).
The release APK for your app is created at <app dir>/build/app/outputs/apk/release/app-release.apk.

Step 13 : install the release apk on a device

Connect your Android device to your computer with a USB cable.

cd <app dir> where <app dir> is your application directory

Run flutter install .

Step 14 : Publishing an APK to the Google Play Store

Thats it 



* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

Share: