Android Build (APK/AAB)

Build Android applications for distribution to Google Play Store or direct installation. This comprehensive guide covers APK and AAB generation, signing, and optimization for both Parent and Student apps.

Prerequisites: Ensure Flutter setup is complete and both parent and student apps are properly configured before building.

1. Pre-Build Configuration

Configure Android-specific settings before building your applications:

Update App Information

# parent_app/pubspec.yaml
name: mighty_school_parent
description: Mighty School Management System - Parent App
version: 1.0.0+1

# student_app/pubspec.yaml
name: mighty_school_student
description: Mighty School Management System - Student App
version: 1.0.0+1

Configure Android Manifest

<!-- parent_app/android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mightyschool.parent">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:label="Mighty School Parent"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme">

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

2. Generate Signing Key

Create a signing key for your Android applications:

Create Keystore File

# Generate keystore for Parent App
keytool -genkey -v -keystore parent-app-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias parent-app

# Generate keystore for Student App
keytool -genkey -v -keystore student-app-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias student-app
Important: Store your keystore files and passwords securely. You'll need them for all future app updates.

Configure Key Properties

# parent_app/android/key.properties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=parent-app
storeFile=../../../parent-app-key.jks

Update Build Configuration

// parent_app/android/app/build.gradle
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.mightyschool.parent"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

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

3. Build APK Files

Generate APK files for direct installation or testing:

Build Debug APK

# Build debug APK for testing
cd parent_app
flutter build apk --debug

# Build for specific architecture
flutter build apk --target-platform android-arm64 --debug

Build Release APK

# Build release APK
flutter build apk --release

# Build split APKs for different architectures
flutter build apk --split-per-abi --release

# Build with specific flavor
flutter build apk --flavor production --release

Build Student App APK

# Switch to student app and build
cd ../student_app
flutter build apk --release
APK Locations: Built APKs will be located in build/app/outputs/flutter-apk/ directory.

4. Build AAB Files (Google Play Store)

Generate Android App Bundle (AAB) files for Google Play Store distribution:

Build Parent App AAB

cd parent_app
flutter build appbundle --release

# Build with obfuscation for better security
flutter build appbundle --obfuscate --split-debug-info=build/debug-info --release

Build Student App AAB

cd ../student_app
flutter build appbundle --release --obfuscate --split-debug-info=build/debug-info
AAB Benefits:
  • Smaller download sizes for users
  • Dynamic delivery of features
  • Required for new apps on Google Play Store
  • Better optimization by Google Play

5. Optimize Build Performance

Configure build optimizations for better performance and smaller file sizes:

Enable R8 Optimization

# android/gradle.properties
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true

# Enable build optimizations
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.caching=true

Configure ProGuard Rules

# android/app/proguard-rules.pro
-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.**  { *; }

# Firebase
-keep class com.google.firebase.** { *; }
-keep class com.google.android.gms.** { *; }

# HTTP and networking
-keep class okhttp3.** { *; }
-keep class retrofit2.** { *; }

6. Test Built Applications

Verify that your built applications work correctly:

Install and Test APK

# Install APK on connected device
adb install build/app/outputs/flutter-apk/app-release.apk

# Install specific architecture APK
adb install build/app/outputs/flutter-apk/app-arm64-v8a-release.apk

# Check installed app
adb shell pm list packages | grep mightyschool

Test AAB Locally

# Install bundletool
# Download from: https://github.com/google/bundletool/releases

# Generate APKs from AAB for testing
java -jar bundletool.jar build-apks --bundle=build/app/outputs/bundle/release/app-release.aab --output=test.apks

# Install on connected device
java -jar bundletool.jar install-apks --apks=test.apks

Testing Checklist

App installs without errors
API connection works correctly
Push notifications function properly
All features work as expected
App performance is satisfactory

7. Build Automation Script

Create scripts to automate the build process:

Build Script for Both Apps

#!/bin/bash
# build_android_apps.sh

echo "Building Mighty School Android Apps..."

# Build Parent App
echo "Building Parent App..."
cd parent_app
flutter clean
flutter pub get
flutter build appbundle --release --obfuscate --split-debug-info=build/debug-info
flutter build apk --release

# Build Student App
echo "Building Student App..."
cd ../student_app
flutter clean
flutter pub get
flutter build appbundle --release --obfuscate --split-debug-info=build/debug-info
flutter build apk --release

echo "Build completed!"
echo "Parent App AAB: parent_app/build/app/outputs/bundle/release/"
echo "Parent App APK: parent_app/build/app/outputs/flutter-apk/"
echo "Student App AAB: student_app/build/app/outputs/bundle/release/"
echo "Student App APK: student_app/build/app/outputs/flutter-apk/"
# Make script executable and run
chmod +x build_android_apps.sh
./build_android_apps.sh

Next Steps

iOS Build

Build iOS applications for App Store distribution

Build iOS Apps →

Upload to Stores

Publish your apps to Google Play Store and App Store

Upload to Stores →