Creating an Android APK in Flutter
An APK (Android Package Kit) is the package file format used to install Android applications. In Flutter, an Android APK can be generated from a Flutter project using the flutter build apk command.
Flutter supports both APK and Android App Bundle (AAB) release formats. Google Play generally recommends App Bundles, while APKs are useful for direct installation, testing, and distribution through channels that require APK files. :contentReference[oaicite:0]{index=0}
1. What is an APK?
APK stands for Android Package Kit. It is an installable package containing the components required to install an Android application on a device.
A Flutter APK generally contains the compiled application code, Flutter runtime components, native Android resources, assets, and other required files.
Simple Flow
Flutter Project
↓
Dart Code
↓
Flutter Build Process
↓
Android Build System
↓
APK
↓
Android Device
2. Why Create an APK?
- To install a Flutter application directly on an Android device.
- To test an application outside the development environment.
- To share an application with testers.
- To distribute an application through channels that accept APK files.
- To create a release artifact for Android.
- To test different Android architectures when using split APKs.
3. Requirements for Creating an APK
Before creating an APK, make sure the Flutter development environment and Android tooling are properly configured.
- Flutter SDK
- Dart SDK, which is included with Flutter
- Android Studio or the required Android development tools
- Android SDK
- Java/JDK required by the configured Android tooling
- A Flutter project
- Android device or emulator for testing
Check Flutter Installation
flutter doctor
The flutter doctor command helps identify problems with the Flutter SDK, Android tooling, connected devices, licenses, and other development requirements.
4. Create a Flutter Project
If you do not already have a project, create one using the Flutter CLI.
flutter create my_app
Move into the project directory:
cd my_app
5. Flutter Project Structure
my_app/
├── android/
├── ios/
├── lib/
│ └── main.dart
├── test/
├── web/
├── windows/
├── macos/
├── linux/
├── assets/
├── pubspec.yaml
└── build/
The android/ directory contains the Android-specific project configuration used when creating an Android build.
6. Check Dependencies
Before creating an APK, make sure all packages declared in pubspec.yaml are resolved.
flutter pub get
This downloads or resolves the dependencies required by the Flutter project.
7. Test the Flutter Application
It is good practice to test the application before generating a release APK.
flutter test
You can also run the application on an Android device or emulator:
flutter run
8. Basic APK Command
The basic command for creating an Android APK is:
flutter build apk
The flutter build command defaults to a release build unless another build mode is explicitly selected. :contentReference[oaicite:1]{index=1}
9. Step-by-Step: Creating a Release APK
Step 1: Open the Project
cd my_app
Step 2: Check Flutter
flutter doctor
Step 3: Get Dependencies
flutter pub get
Step 4: Run Tests
flutter test
Step 5: Create the APK
flutter build apk
Step 6: Find the APK
The generated release APK is placed in the Flutter project's build output directory.
build/app/outputs/flutter-apk/app-release.apk
The exact generated files can vary depending on the build options used.
10. Release APK Build Flow
Source Code
↓
pubspec.yaml
↓
Dependency Resolution
↓
Dart Compilation
↓
Flutter Build
↓
Android/Gradle Build
↓
Release Packaging
↓
APK
↓
Testing / Distribution
11. Debug APK
A debug APK can be useful for development and testing. To explicitly create a debug APK, use:
flutter build apk --debug
A debug APK is intended for development/testing and should not be treated as a production release artifact.
12. Profile APK
Profile mode is designed for performance analysis.
flutter build apk --profile
Profile builds are useful when analyzing application performance in an environment closer to release behavior.
13. Release APK
A release APK is intended for production-oriented testing and distribution.
flutter build apk --release
Because flutter build apk defaults to release mode, the following is also commonly used:
flutter build apk
14. Debug vs Profile vs Release APK
| Mode | Command | Purpose |
|---|
| Debug | flutter build apk --debug | Development and debugging |
| Profile | flutter build apk --profile | Performance analysis |
| Release | flutter build apk --release | Production-oriented build and distribution |
15. What Happens During APK Creation?
When you run flutter build apk, several stages take place.
- Flutter reads the project configuration.
- Dependencies are resolved.
- Dart and Flutter application code is prepared for the selected build mode.
- Assets and resources are processed.
- The Android project is built using the Android build system.
- Flutter runtime components are packaged.
- Android resources are packaged.
- The APK is generated.
- The release APK is signed when release signing is configured.
16. Understanding APK Architectures
Android devices can use different CPU architectures. Flutter's Android release documentation identifies armeabi-v7a, arm64-v8a, and x86-64 as supported release architectures. :contentReference[oaicite:2]{index=2}
| ABI | Description |
|---|
| armeabi-v7a | ARM 32-bit architecture. |
| arm64-v8a | ARM 64-bit architecture. |
| x86_64 | 64-bit x86 architecture, commonly relevant to certain emulators and devices. |
17. Split APKs
Flutter can generate separate APK files for different Android architectures.
flutter build apk --split-per-abi
This creates separate APKs instead of one APK containing binaries for all supported target ABIs. Flutter's Android documentation recommends split APKs when distributing APKs because a single fat APK can be larger than necessary. :contentReference[oaicite:3]{index=3}
Typical Output
build/app/outputs/flutter-apk/
├── app-armeabi-v7a-release.apk
├── app-arm64-v8a-release.apk
└── app-x86_64-release.apk
18. Fat APK
A fat APK is a single APK that contains binaries for multiple supported ABIs.
flutter build apk
The advantage is that one APK can support multiple architectures. The disadvantage is that the APK can be larger because it contains native binaries that may not be needed by a particular device. :contentReference[oaicite:4]{index=4}
19. Split APK vs Fat APK
| Feature | Split APK | Fat APK |
|---|
| Command | flutter build apk --split-per-abi | flutter build apk |
| Number of APKs | Multiple | Single |
| File Size | Usually smaller per architecture | Usually larger |
| Architecture | Architecture-specific | Multiple architectures |
| Distribution | Requires selecting the appropriate APK | Simple single-file distribution |
20. Android Application ID
The Android applicationId uniquely identifies the Android application. It is normally configured in the Android project's Gradle configuration.
Example
defaultConfig {
applicationId = "com.example.myapp"
}
For an application intended for distribution, use a unique application ID rather than leaving a generic example identifier. Flutter's Android documentation notes that the application ID identifies the app on Google Play and on Android devices. :contentReference[oaicite:5]{index=5}
21. Application Version
Flutter application version information can be specified in pubspec.yaml.
version: 1.0.0+1
| Value | Meaning |
|---|
| 1.0.0 | Version name |
| 1 | Build number |
For Android, Flutter maps the build name to versionName and the build number to versionCode. :contentReference[oaicite:6]{index=6}
22. Override Version During Build
The build name and build number can also be specified during the build.
flutter build apk --build-name=1.2.0 --build-number=10
This can be useful when automated build systems need to generate versioned APKs.
23. Android Manifest
The Android manifest is located at:
android/app/src/main/AndroidManifest.xml
It contains Android-specific application configuration such as the application label and permissions.
Example
android:label="My Flutter App"
android:icon="@mipmap/ic_launcher">
24. Internet Permission
If the Flutter application needs Internet access, verify that the Android manifest contains the required Internet permission.
This is particularly important for applications that communicate with REST APIs, Firebase services, web services, or other Internet-based systems. Flutter's Android release documentation specifically describes reviewing the manifest and adding the Internet permission when the application needs Internet access. :contentReference[oaicite:7]{index=7}
25. Application Icon
An Android application needs an appropriate launcher icon. Flutter projects include a default launcher icon that can be replaced with a custom icon.
Android launcher resources are commonly located under:
android/app/src/main/res/
The Android manifest references the launcher icon through the application's android:icon attribute. :contentReference[oaicite:8]{index=8}
26. Signing an Android APK
Android release applications need appropriate signing for distribution. For Play Store publishing, Flutter's Android release documentation explains the use of an upload key and Play App Signing. :contentReference[oaicite:9]{index=9}
Keystore
↓
Signing Configuration
↓
Release Build
↓
Signed APK
27. Creating an Upload Keystore
A keystore can be generated using Java's keytool.
Windows PowerShell Example
keytool -genkey -v -keystore $env:USERPROFILE\upload-keystore.jks `
-storetype JKS -keyalg RSA -keysize 2048 -validity 10000 `
-alias upload
macOS/Linux Example
keytool -genkey -v -keystore ~/upload-keystore.jks \
-keyalg RSA -storetype JKS -keysize 2048 -validity 10000 \
-alias upload
Keep the keystore private and do not commit it to a public source-control repository. :contentReference[oaicite:10]{index=10}
28. key.properties
A Flutter Android project can use a key.properties file to reference signing information.
storePassword=
keyPassword=
keyAlias=upload
storeFile=
This file contains sensitive information and should be kept private. :contentReference[oaicite:11]{index=11}
29. Release Signing Flow
Upload Keystore
↓
key.properties
↓
Gradle Signing Configuration
↓
Release Build
↓
Signed APK
30. Code Shrinking
Flutter's Android release documentation states that R8 code shrinking is enabled by default for release APK and App Bundle builds. :contentReference[oaicite:12]{index=12}
Code shrinking can reduce the amount of unused Android code included in the final application.
31. APK Obfuscation
Flutter supports Dart code obfuscation for APK builds.
flutter build apk --obfuscate --split-debug-info=build/symbols
Obfuscation renames Dart symbols to make the compiled code more difficult to understand. It is not encryption. Flutter recommends securely keeping the generated symbol information because it may be needed to interpret obfuscated stack traces later. :contentReference[oaicite:13]{index=13}
32. Clean Build Before APK Creation
If the project has stale generated files or unexpected build problems, you can clean the build artifacts.
flutter clean
flutter pub get
flutter build apk
A clean build is useful for troubleshooting but does not need to be performed before every APK build.
33. Installing the APK on an Android Device
After connecting an Android device with developer options enabled, Flutter provides the flutter install command for installing an APK.
flutter install
Flutter's Android release documentation lists connecting the device, navigating to the project, and running flutter install as the installation process. :contentReference[oaicite:14]{index=14}
34. Testing the APK
After creating the APK, test the actual generated application rather than relying only on the development build.
- Install the APK on an Android device.
- Launch the application.
- Test the login functionality.
- Test navigation.
- Test forms and validation.
- Test API communication.
- Test local storage.
- Test permissions.
- Test notifications if applicable.
- Test application behavior after restarting.
35. APK Installation Flow
Build APK
↓
Locate app-release.apk
↓
Transfer to Android Device
↓
Install APK
↓
Launch Application
↓
Test Functionality
36. Creating an APK with a Flavor
Flutter Android flavors can be used when an application has separate configurations such as development, staging, and production.
Example
flutter build apk --flavor staging
The Flutter documentation provides the --flavor option for building an APK or App Bundle for a configured Android product flavor. :contentReference[oaicite:15]{index=15}
37. Example: Development and Production APKs
Development
↓
staging flavor
↓
flutter build apk --flavor staging
Production
↓
production flavor
↓
flutter build apk --flavor production
Flavors can be configured to use different API endpoints, themes, application behavior, or other environment-specific settings.
38. APK vs AAB
| Feature | APK | AAB |
|---|
| Full Name | Android Package Kit | Android App Bundle |
| Direct Installation | Yes | Not normally installed directly as a single file |
| Testing | Very convenient | Can be tested through appropriate tooling/channels |
| Google Play | Supported distribution format in relevant contexts | Preferred format |
| Flutter Command | flutter build apk | flutter build appbundle |
Google Play recommends app bundles because they allow more efficient delivery to users, while APKs remain useful for direct distribution and stores that do not support app bundles. :contentReference[oaicite:16]{index=16}
39. Common APK Build Errors
Error 1: Flutter Command Not Found
Possible Cause: Flutter is not correctly added to the system PATH.
Check:
flutter doctor
Error 2: Android SDK Not Found
Possible Cause: Android SDK or Android development environment is not correctly configured.
Solution: Open Android Studio, verify the Android SDK configuration, and run:
flutter doctor
Error 3: Dependency Error
Possible Cause: Packages are missing or incompatible.
Try:
flutter pub get
Error 4: Gradle Build Failure
Possible Causes:
- Android Gradle configuration issue.
- Incompatible dependency.
- Incorrect Android SDK configuration.
- Signing configuration problem.
- Stale build files.
A clean rebuild can sometimes help identify whether generated files are contributing to the problem.
flutter clean
flutter pub get
flutter build apk
Error 5: Missing Asset
Possible Cause: An asset path is missing or incorrectly declared in pubspec.yaml.
flutter:
assets:
- assets/images/
Error 6: Signing Error
Possible Cause: The keystore, signing properties, alias, password, or Gradle signing configuration is incorrect.
40. Common Mistakes While Creating APK
- Not running
flutter pub get after dependency changes.
- Ignoring
flutter doctor errors.
- Using an incorrect application ID.
- Forgetting to update the application version.
- Using incorrect asset paths.
- Sharing private keystore credentials.
- Committing
key.properties to public source control.
- Testing only the debug application.
- Not testing the actual release APK.
- Using a fat APK when architecture-specific APKs would be more appropriate.
- Not configuring release signing before production distribution.
41. Best Practices for APK Creation
- Run
flutter doctor before troubleshooting environment problems.
- Keep dependencies compatible and up to date.
- Test the application before building.
- Use release mode for production-oriented APKs.
- Maintain proper version numbers.
- Use a unique application ID.
- Configure proper release signing.
- Protect keystore and signing credentials.
- Keep obfuscation symbol files securely when using obfuscation.
- Test the generated APK on physical Android devices.
- Use split APKs when architecture-specific distribution is appropriate.
- Consider AAB instead of APK when publishing through Google Play.
42. Complete APK Creation Workflow
1. Create Flutter Project
↓
2. Configure Application
↓
3. Add Dependencies
↓
4. Configure Assets
↓
5. Set Application ID
↓
6. Set Version
↓
7. Configure Android Settings
↓
8. Configure Signing
↓
9. Run Tests
↓
10. Build Release APK
↓
11. Install APK
↓
12. Test APK
↓
13. Distribute APK
43. Complete Command Example
flutter doctor
flutter pub get
flutter test
flutter clean
flutter pub get
flutter build apk --release
44. Architecture-Specific APK Example
flutter clean
flutter pub get
flutter build apk --release --split-per-abi
This produces separate release APKs for supported Android ABIs instead of one fat APK. :contentReference[oaicite:17]{index=17}
45. Obfuscated Release APK Example
flutter build apk --release \
--obfuscate \
--split-debug-info=build/symbols
On Windows, use the appropriate command-line continuation syntax for the shell being used.
46. Real-World Example
Suppose you have developed a Flutter food-delivery application containing login, restaurant listing, cart, payment, and order tracking.
Flutter Food Delivery App
↓
Test Login
↓
Test Restaurant Listing
↓
Test Cart
↓
Test Payment
↓
Test Orders
↓
Configure Version
↓
Configure Signing
↓
Build APK
↓
app-release.apk
↓
Install on Android Device
↓
Final Testing
↓
Distribution
47. APK Creation Checklist
| Task | Status |
|---|
| Flutter environment checked | ☐ |
| Android SDK configured | ☐ |
| Dependencies installed | ☐ |
| Application tested | ☐ |
| Application ID configured | ☐ |
| Version updated | ☐ |
| Assets verified | ☐ |
| Signing configured | ☐ |
| Release APK generated | ☐ |
| APK installed on device | ☐ |
| Release APK tested | ☐ |
48. Interview Questions
Q1. What is an APK?
APK stands for Android Package Kit and is an installable Android application package.
Q2. Which command creates an APK in Flutter?
flutter build apk
Q3. How do you create a release APK?
flutter build apk --release
Q4. How do you create architecture-specific APKs?
flutter build apk --split-per-abi
Q5. What is a fat APK?
A fat APK is a single APK containing binaries for multiple Android architectures.
Q6. What is the difference between APK and AAB?
An APK is an installable Android package, while an AAB is an Android App Bundle intended primarily for store distribution and optimized delivery.
Q7. Where is the release APK generated?
It is generated under the project's build/app/outputs/flutter-apk/ directory.
Q8. Why is application signing important?
Signing establishes the application's signing identity and is required for appropriate Android release distribution.
Q9. How can you obfuscate a Flutter APK?
flutter build apk --obfuscate --split-debug-info=build/symbols
Q10. How can you install a generated APK using Flutter?
flutter install
49. Summary
Creating an Android APK in Flutter involves preparing the Flutter project, resolving dependencies, testing the application, configuring Android settings, selecting the appropriate build mode, and running the Flutter build command.
The most important commands are:
flutter doctor
flutter pub get
flutter test
flutter clean
flutter build apk
flutter build apk --release
flutter build apk --debug
flutter build apk --profile
flutter build apk --split-per-abi
flutter install
For production distribution, also pay attention to application ID, versioning, release signing, code shrinking, testing, and secure handling of signing credentials. When publishing through Google Play, consider using an Android App Bundle because Google Play recommends AAB for more efficient application delivery. :contentReference[oaicite:18]{index=18}
50. Learn Flutter with JustAcademy
JustAcademy Flutter Training Course
Register for Flutter Course Demo