How to build apk using shell file in flutter

Chandrakant Vemula
Canadiv’s Technology and Design
2 min readDec 15, 2023

Hello in this article we are gonna learn about to build apk in only one command so let’s get started, let’s start with the normal process how we gonna build apks in flutter

First we clean the our project code using flutter clean command then we get all the packages using flutter pub get command then if we have localization in our app then we run another command flutter genl10n and after all this of command then we run flutter build apk this how we need to write commands step by step in our terminal.

So in this article we are gonna build apk in another method using only one command.

  1. Create a new text file in your Flutter project directory and give it a meaningful name, such as build_apk.sh
  2. Open the build_apk.sh file in a text editor and add the following lines:

# Set the desired build flavor (e.g., release, debug)
BUILD_FLAVOR="release"

# Set the output directory for the build
OUTPUT_DIR="C:/Users/Your/OneDrive/Desktop"

# Clean the previous build outputs
flutter clean

# Localize the app
flutter gen-l10n

# Generate the APK build
flutter build apk --split-per-abi

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Build completed successfully."
else
echo "Build failed. Exiting."
# exit 1
fi

# Create the output directory if it doesn't exist
# mkdir -p $OUTPUT_DIR

# Copy the APK file to the output directory
cp -R build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk $OUTPUT_DIR
echo "APK file copied to $OUTPUT_DIR"

echo "Build process completed successfully."

Replace /path/to/your/flutter/project with the actual path to your Flutter project directory.

  1. Save the build_apk.sh file.
  2. Make the script executable by running the following command in your terminal:

Now, you can build the APK by simply running the shell script using the following command:

./build_apk.sh

Make sure the above command run in the project root directory.

This script will navigate to your Flutter project directory, build the release APK, and optionally copy it to a specified location. After running the script, you will see the “APK built successfully!” message and automatically copy and paste your apk to your desktop.

Make sure you have the Flutter CLI installed and configured properly on your system before running the script.

--

--