How to Export APK in Flutter
To export an APK (Android Package) file in Flutter, follow this step-by-step guide. This guide will allow you to generate a release version of your Flutter app and prepare it for distribution or installation on Android devices.
Step 1: Set Up Your Environment
Make sure you have Flutter and Android Studio installed on your machine. You’ll also need an emulator or a connected Android device to test the APK.
Make sure Android SDK and Android Studio are properly installed.
Ensure that your Flutter project is working correctly.
You can verify your environment by running:
flutter doctor
Fix any issues reported by flutter doctor
before proceeding.
Step 2: Configure Your App for Release
Before exporting the APK, you need to configure your Flutter app for release mode.
Update
android/app/build.gradle
:Open
android/app/build.gradle
.Locate the
buildTypes
block and ensure therelease
block is properly set up. Here's a default release configuration:
android {
compileSdkVersion 34
defaultConfig {
applicationId "com.example.myapp" //make sure the name is from your company and prohect name
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
buildTypes {
release {
// Shrinks, optimizes, and obfuscates your code by default
minifyEnabled true
// Enables ProGuard for code obfuscation (optional)
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
Step 4: Build the APK
Now that the project is set up for release, you can generate the APK.
Run the Flutter Build Command: Run the following command in the terminal from your project’s root directory:
flutter build apk --release
This command builds the release APK and stores it in the
build/app/outputs/flutter-apk
directory.
Check the APK: The APK will be located at:
build/app/outputs/flutter-apk/app-release.apk
Step 5: Test the APK on an Android Device
Transfer the APK to your Android device via USB, email, or cloud storage.
💡In my case I use TelegramOpen the APK file on your device and install it.
💡That’s All! I think this is simply exporting Flutter app to APK, If your Flutter app has many features I think you will encounter some issues but you can simply search for the error or fix soulotion by prompting CHAT GPT xD