Build a Flutter app so you can run and test it as an app on iPhone or Android smartphones.
Download bundletool
First, if you haven’t downloaded it yet, download Java’s bundletool.
Release 1.4.0 · google/bundletool
Check Build Settings
As preparation, check the following items.
Reviewing the app manifest located in/android/app/src/main e.g. android:label e.g. android.permission.INTERNET
Review the manifest file. For example, for most apps, the permission to enable internet use, android.permission.INTERNET, is said to be essential.
Reviewing the build configuration
build.gradle, located in
Review the build settings. For example, check if applicationId, versionCode, etc. have the correct values.
(Reference)
Build and release an Android app - Flutter
(Build) Generate apks, aab files
There are two ways to build an app from Flutter. First, the more modern method is apks, aab. Next, there is the legacy method of building apk.
Build apks, aab
The procedure to build apks, aab.
Move the directory to the project.
cd C:\pg\flutter\tmpapp\flutter_application_2\
Don’t forget to clean the project.
flutter clean
Build the apks file.
flutter build appbundle
Use the bundletool you downloaded earlier here. Build the apks file.
java -jar C:\pg\_android\bin\bundletool-all-1.4.0.jar build-apks --bundle="build\app\outputs\bundle\release\app-release.aab" --output=./tmp.apks
Deploy the apks file to the device and make it executable. If there are no errors up to this point, you should be able to select and run the app from the device at this stage.
java -jar C:\pg\_android\bin\bundletool-all-1.4.0.jar install-apks --apks=./tmp.apks --device-id BH901B6F5L
Build apk
The procedure to build apk.
First, don’t forget to clean the project.
flutter clean
Build the apk file.
flutter build apk
The built apk file needs to be manually deployed to the device. I set up a web server in my local environment and download and launch the apk file from my smartphone. The apk seems convenient for distribution on Github as well.