How to Build Android APK – Complete Guide (With Gradle & Linux)
There are many ways to build an Android application. Here I explain 4 best methods, step by step, so anyone can build an APK successfully.
Let’s start properly 🚀
What is Gradle? (Very Important)
Gradle is the official build system for Android. It compiles your code, downloads dependencies, and generates APKs.
Every Android project includes a Gradle Wrapper, so you usually do NOT need to install Gradle manually.
- Android Studio → Gradle runs automatically
- VS Code → Gradle runs via terminal
- Linux / Cloud Shell → Gradle runs fully via CLI
Commands like assembleDebug and assembleRelease are Gradle tasks.
Method 1: Build APK using Android Studio
Easy and beginner-friendly. Gradle runs in the background.
- PC / Laptop
- Internet connection
- Android Studio installed
STEP 1: Install Android Studio
- Go to https://developer.android.com/studio
- Download and install Android Studio
- During setup, select:
- ✔ Android SDK
- ✔ Platform Tools
- ✔ Build Tools
STEP 2: Open Project & Sync Gradle
- Open Android Studio
- Click Open → select project folder
- Wait for Gradle Sync to finish
STEP 3: Build APK
- Build → Build Bundle(s) / APK(s)
- Click Build APK(s)
APK Location:
Method 2: Build APK using VS Code or Any IDE
For developers who prefer lightweight editors with full Gradle control.
- Java JDK (8 / 11 / 17)
- Android SDK
- Gradle Wrapper (gradlew)
- VS Code or any IDE
STEP 1: Open Project
Open your Android project folder in VS Code.
STEP 2: Open Terminal
cd your-android-project
STEP 3: Build APK using Gradle
Debug APK:
Release APK:
APK Location:
assembleRelease, you need to sign and verify your APK.
Check Method 4, Step 6 for signing instructions.
Method 3: Build APK using Terminal (CLI Only)
Advanced users and CI/CD systems often use this method.
- Java installed
- Android SDK installed
- Gradle Wrapper files
Steps:
- Open terminal and go to project folder:
cd your-android-project
- Make Gradle executable:
chmod +x gradlew
- Build Debug APK:
./gradlew assembleDebug
- Build Release APK:
./gradlew assembleRelease
APK Output:
Method 4: Build APK using Linux / Ubuntu Terminal (Cloud Shell)
Perfect for Linux servers or Google Cloud Shell. No GUI required.
sudo apt install openjdk-17-jdk
java -version
Note: Only java -version is valid. Others like java -v will fail.
wget https://dl.google.com/android/repository/commandlinetools-linux-latest.zip
mkdir -p $HOME/Android/Sdk/cmdline-tools
unzip commandlinetools-linux-*.zip
mv cmdline-tools $HOME/Android/Sdk/cmdline-tools/latest
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
yes | sdkmanager --licenses
chmod +x gradlew
./gradlew assembleDebug
./gradlew assembleRelease
APK Location:
Create Keystore:
Sign APK:
Verify APK:
This will download the APK directly to your computer 💾
- Gradle is required in all methods
- Debug APK → for testing
- Release APK → must be signed & verified before Play Store upload
- Linux / Cloud Shell → CLI only, no GUI
