How to build an android Application

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.

Method 1: Android Studio (Easiest & Best for Beginners)
Method 2: VS Code / Any IDE (More Control with Gradle)
Method 3: Terminal / CLI (Advanced & Automation)
Method 4: Linux / Ubuntu Terminal (Server & Cloud Shell)

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.

Requirements:
  • PC / Laptop
  • Internet connection
  • Android Studio installed

STEP 1: Install Android Studio

  1. Go to https://developer.android.com/studio
  2. Download and install Android Studio
  3. During setup, select:
  • ✔ Android SDK
  • ✔ Platform Tools
  • ✔ Build Tools

STEP 2: Open Project & Sync Gradle

  1. Open Android Studio
  2. Click Open → select project folder
  3. Wait for Gradle Sync to finish

STEP 3: Build APK

  1. Build → Build Bundle(s) / APK(s)
  2. Click Build APK(s)

APK Location:

app/build/outputs/apk/debug/app-debug.apk

Method 2: Build APK using VS Code or Any IDE

For developers who prefer lightweight editors with full Gradle control.

Requirements:
  • 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:

./gradlew assembleDebug

Release APK:

./gradlew assembleRelease

APK Location:

app/build/outputs/apk/
⚠️ Note: For 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.

Requirements:
  • Java installed
  • Android SDK installed
  • Gradle Wrapper files

Steps:

  1. Open terminal and go to project folder:
    cd your-android-project
  2. Make Gradle executable:
    chmod +x gradlew
  3. Build Debug APK:
    ./gradlew assembleDebug
  4. Build Release APK:
    ./gradlew assembleRelease

APK Output:

app/build/outputs/apk/release/app-release.apk
⚠️ Note: Release APK must be signed and verified before Play Store upload. See Method 4, Step 6 for signing instructions.

Method 4: Build APK using Linux / Ubuntu Terminal (Cloud Shell)

Perfect for Linux servers or Google Cloud Shell. No GUI required.

STEP 1: Install Java
sudo apt update
sudo apt install openjdk-17-jdk
java -version

Note: Only java -version is valid. Others like java -v will fail.

STEP 2: Install Android SDK (Command Line)
sudo apt install unzip wget -y
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
STEP 3: Set Environment Variables
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
STEP 4: Install SDK Packages
sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0"
yes | sdkmanager --licenses
STEP 5: Build APK using Gradle
cd your-android-project
chmod +x gradlew
./gradlew assembleDebug
./gradlew assembleRelease

APK Location:

app/build/outputs/apk/
STEP 6: Sign APK for Play Store

Create Keystore:

keytool -genkeypair -v -keystore mykey.jks -keyalg RSA -keysize 2048 -validity 10000 -alias myalias

Sign APK:

jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 \\ -keystore mykey.jks app-release.apk myalias

Verify APK:

jarsigner -verify app-release.apk
STEP 7: Download APK from Cloud Shell
cloudshell download app/build/outputs/apk/debug/app-debug.apk

This will download the APK directly to your computer 💾


Final Notes:
  • 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

Post a Comment

Previous Post Next Post