Building Android Apps on Arch Linux Without Android Studio
If you want to build an Android app, the official recommendation is to download Android Studio. However, Android Studio is a massive application. It consumes gigabytes of RAM, takes a long time to index files, and can make older hardware grind to a halt.
If you are using Arch Linux, you likely appreciate a system that is lightweight, fast, and exactly what you make of it. You can apply this same philosophy to Android development. You do not need a heavy Integrated Development Environment (IDE) to build an app. All you need is the Android Software Development Kit (SDK), a text editor, and the command line.
Here is how to set up a completely minimalist, terminal-based Android development environment on Arch Linux and build your first “Hello World” application.
Part 1: Setting Up the Arch Environment
To compile Android apps, your computer needs two main tools: Java and the Android SDK.
1. Install Dependencies
Open your terminal and use Arch’s package manager to install the required tools. You will need an AUR helper (like yay or paru) to get the Android packages.
# Install Java 17 and a base version of Gradle
sudo pacman -S jre17-openjdk jdk17-openjdk gradle
# Install the Android SDK components from the AUR
yay -S android-sdk android-sdk-platform-tools android-sdk-build-tools
2. Set Environment Variables
The build tools need to know where Java and the Android SDK are located. Add these lines to your shell configuration file (like ~/.bashrc or ~/.zshrc):
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export ANDROID_HOME=/opt/android-sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools
Save the file and run source ~/.bashrc to apply the changes.
Part 2: Creating the Project Skeleton
Android projects follow a specific folder structure. We will create this structure manually from the terminal.
Create a new folder for your app and build the necessary directories:
mkdir MyMinimalApp
cd MyMinimalApp
# Create the directory tree for the app code
mkdir -p app/src/main/java/com/example/minimal
Setting up the Build System (Gradle)
Gradle is the engine that takes your code and turns it into an Android package (APK). We need three small files to tell Gradle what to do.
1. Create settings.gradle in the root folder:
This file tells Gradle where to download its plugins.
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyMinimalApp"
include ':app'
2. Create build.gradle in the root folder:
This defines the version of the Android build tool we are using.
plugins {
id 'com.android.application' version '8.2.2' apply false
}
3. Create app/build.gradle in the app folder:
This file contains the specific settings for your application.
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.minimal'
compileSdk 34
defaultConfig {
applicationId "com.example.minimal"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
}
}
Finally, generate the Gradle Wrapper. This ensures your project always uses the correct version of Gradle, even if you move to another computer.
gradle wrapper --gradle-version 8.2
Part 3: Writing “Hello World”
Now we write the actual Android application. We only need two files for a minimal setup.
1. The Manifest (app/src/main/AndroidManifest.xml)
This file tells the Android operating system about your app and how to launch it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="Hello Minimal">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
2. The Code (app/src/main/java/com/example/minimal/MainActivity.java)
Instead of using complex XML layout files, we will create the text directly in the Java code to keep things incredibly simple.
package com.example.minimal;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a text view programmatically
TextView text = new TextView(this);
text.setText("Hello World from Arch Linux!");
text.setTextSize(24);
text.setGravity(Gravity.CENTER);
// Display the text on the screen
setContentView(text);
}
}
Part 4: Build and Deploy
Your app is written. Now you just need to compile it and push it to your phone.
First, ensure your Android phone is connected to your computer via USB and that “USB Debugging” is enabled in your phone’s Developer Options.
Instead of typing out long commands every time you change your code, create a simple deployment script.
Create a file named go.sh in your root folder:
#!/bin/bash
# Stop if any command fails
set -e
echo "Compiling the app..."
./gradlew :app:assembleDebug
echo "Installing on phone..."
adb install -r app/build/outputs/apk/debug/app-debug.apk
echo "Launching app..."
adb shell am start -n com.example.minimal/.MainActivity
Make the script executable:
chmod +x go.sh
The Final Test
Run your script from the terminal:
./go.sh
Within a few seconds, the terminal will compile the code, send the APK file over the USB cable, and the “Hello World from Arch Linux!” screen will pop up on your physical device.
You now have a fully functional Android development environment using a fraction of the system resources required by traditional IDEs. From here, you can open your Java files in any text editor you prefer (like Vim, Nano, or VS Code) and develop your application purely from the command line.