0
0
Fluttermobile~5 mins

Android build configuration in Flutter

Choose your learning style9 modes available
Introduction

Android build configuration helps you set up how your Flutter app is built and packaged for Android devices.

When you want to change the app's version number or build number.
When you need to add permissions or features to your Android app.
When you want to customize the app's signing for release.
When you want to set the minimum Android version your app supports.
When you want to change the app's package name or application ID.
Syntax
Flutter
android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
        }
    }
}

This code is inside the android/app/build.gradle file.

compileSdkVersion is the Android API level used to compile the app.

Examples
Sets the app ID, minimum Android version, target version, and app version info.
Flutter
defaultConfig {
    applicationId "com.example.myapp"
    minSdkVersion 21
    targetSdkVersion 33
    versionCode 2
    versionName "1.1"
}
Enables code shrinking and obfuscation for the release build.
Flutter
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
Configures the signing key for releasing the app.
Flutter
signingConfigs {
    release {
        storeFile file("my-release-key.jks")
        storePassword "password"
        keyAlias "my-key-alias"
        keyPassword "password"
    }
}
Sample App

This is a simple Android build configuration for a Flutter app. It sets the app ID, minimum and target SDK versions, and version info. The release build uses the debug signing config and disables code shrinking.

Flutter
android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.myflutterapp"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            signingConfig signingConfigs.debug
        }
    }
}
OutputSuccess
Important Notes

Always update versionCode and versionName before releasing a new app version.

Use minSdkVersion to set the lowest Android version your app supports.

Signing configuration is required for publishing your app on the Play Store.

Summary

Android build configuration is set in android/app/build.gradle.

It controls app ID, SDK versions, version numbers, and build types.

Proper configuration is important for building and releasing your Flutter Android app.