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.
Configure Android-specific settings before building your applications:
# 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
<!-- 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>
Create a signing key for your Android applications:
# 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
# parent_app/android/key.properties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=parent-app
storeFile=../../../parent-app-key.jks
// 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'
}
}
}
Generate APK files for direct installation or testing:
# 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
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
# Switch to student app and build
cd ../student_app
flutter build apk --release
build/app/outputs/flutter-apk/ directory.
Generate Android App Bundle (AAB) files for Google Play Store distribution:
cd parent_app
flutter build appbundle --release
# Build with obfuscation for better security
flutter build appbundle --obfuscate --split-debug-info=build/debug-info --release
cd ../student_app
flutter build appbundle --release --obfuscate --split-debug-info=build/debug-info
Configure build optimizations for better performance and smaller file sizes:
# 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
# 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.** { *; }
Verify that your built applications work correctly:
# 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
# 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
Create scripts to automate the build process:
#!/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