Setup Workflow
Configure Android development environment including SDK, NDK, command-line tools, and gomobile for both traditional and NixOS setups.
Installation Methods
Choose based on your system:
- Traditional Linux/Mac/Windows: Command-line tools or Android Studio
- NixOS/Nix: Declarative configuration with androidenv
- Android Studio: GUI-based (easiest for beginners)
Traditional Setup (Linux/Mac/Windows)
Option 1: Command-line Tools (Recommended)
Lightweight, scriptable setup without Android Studio.
1. Download Command-line Tools
# Create SDK directory
mkdir -p ~/Android/Sdk
cd ~/Android/Sdk
# Download latest cmdline-tools (Linux)
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
# Or for Mac
# wget https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip
# Extract
unzip commandlinetools-linux-*_latest.zip
rm commandlinetools-linux-*_latest.zip
# Move to correct location
mkdir -p cmdline-tools/latest
mv cmdline-tools/* cmdline-tools/latest/ 2>/dev/null || true
2. Set Environment Variables
Add to ~/.bashrc or ~/.zshrc:
# Android SDK
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
Apply changes:
source ~/.bashrc # or ~/.zshrc
3. Accept Licenses
sdkmanager --licenses
Type y and press Enter for each license.
4. Install SDK Components
# Platform tools (adb, fastboot)
sdkmanager "platform-tools"
# Latest Android platform (API 34 as of 2026)
sdkmanager "platforms;android-34"
# Build tools
sdkmanager "build-tools;34.0.0"
# NDK (required for gomobile)
sdkmanager "ndk;26.1.10909125"
# Emulator (optional)
sdkmanager "emulator"
# System image for emulator (optional)
sdkmanager "system-images;android-34;google_apis;x86_64"
5. Verify Installation
# Check SDK manager
sdkmanager --list
# Check adb
adb version
# Check environment
echo $ANDROID_HOME
ls $ANDROID_HOME
Option 2: Android Studio
Pros: GUI, automatic SDK management, emulator, IDE Cons: Large download (~1GB), more resources
Steps:
- Download Android Studio
- Install and launch
- Follow setup wizard to install SDK and tools
- SDK installed at:
~/Android/Sdk(Linux/Mac) orC:\Users\<user>\AppData\Local\Android\Sdk(Windows)
NixOS / Nix Setup
Why Nix for Android?
Benefits:
- Declarative configuration
- Reproducible builds
- Version pinning
- No manual SDK management
Challenges:
- More complex initial setup
- Not all Android SDK versions available
System Configuration (NixOS)
systems/common/programs/android.nix:
{ config, pkgs, ... }:
{
programs.adb.enable = true;
users.users.youruser.extraGroups = [ "adbusers" ];
environment.systemPackages = with pkgs; [
android-tools # adb, fastboot
];
}
Apply configuration:
sudo nixos-rebuild switch
Home Manager Configuration
home/common/dev/android.nix:
{ config, pkgs, ... }:
let
androidSdk = pkgs.androidenv.composeAndroidPackages {
platformVersions = [ "34" "33" ];
buildToolsVersions = [ "34.0.0" ];
includeNDK = true;
ndkVersion = "26.1.10909125";
includeEmulator = true;
includeSystemImages = true;
systemImageTypes = [ "google_apis" ];
abiVersions = [ "x86_64" "arm64-v8a" ];
};
in
{
home.packages = with pkgs; [
androidSdk.androidsdk
jdk17
go
];
home.sessionVariables = {
ANDROID_HOME = "${androidSdk.androidsdk}/libexec/android-sdk";
ANDROID_SDK_ROOT = "${androidSdk.androidsdk}/libexec/android-sdk";
};
home.sessionPath = [
"${androidSdk.androidsdk}/libexec/android-sdk/platform-tools"
"${androidSdk.androidsdk}/libexec/android-sdk/tools"
"${androidSdk.androidsdk}/libexec/android-sdk/emulator"
];
}
Apply configuration:
home-manager switch --flake .#youruser@hostname
Nix Development Shell (Project-specific)
Create flake.nix in your project:
{
description = "Android development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
androidSdk = pkgs.androidenv.composeAndroidPackages {
platformVersions = [ "34" ];
buildToolsVersions = [ "34.0.0" ];
includeNDK = true;
ndkVersion = "26.1.10909125";
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
androidSdk.androidsdk
jdk17
gradle
go
];
shellHook = ''
export ANDROID_HOME="${androidSdk.androidsdk}/libexec/android-sdk"
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
echo "Android development environment ready!"
echo "ANDROID_HOME: $ANDROID_HOME"
'';
};
}
);
}
Enter development shell:
nix develop
# Or use direnv for automatic activation
echo "use flake" > .envrc
direnv allow
Nix androidenv Options
pkgs.androidenv.composeAndroidPackages {
# Platform versions (Android API levels)
platformVersions = [ "34" "33" "31" ];
# Build tools versions
buildToolsVersions = [ "34.0.0" ];
# Include NDK
includeNDK = true;
ndkVersion = "26.1.10909125";
# Include Android Emulator
includeEmulator = true;
# Include system images for emulator
includeSystemImages = true;
systemImageTypes = [ "google_apis" "google_apis_playstore" ];
abiVersions = [ "x86_64" "arm64-v8a" ];
# Include CMake (for C++ projects)
cmakeVersions = [ "3.22.1" ];
}
Post-Installation (All Methods)
Install Gomobile
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
This downloads additional toolchains for cross-compilation.
Configure Gradle
Create ~/.gradle/gradle.properties:
# Use more memory for Gradle
org.gradle.jvmargs=-Xmx4096m
# Enable Gradle daemon
org.gradle.daemon=true
# Enable parallel execution
org.gradle.parallel=true
# Enable build cache
org.gradle.caching=true
# Use AndroidX
android.useAndroidX=true
android.enableJetifier=true
Setup Device for Development
Enable Developer Options
- Go to Settings → About phone
- Tap Build number 7 times
- Go back to Settings → System → Developer options
- Enable USB debugging
Connect Device
# Connect via USB
adb devices
# Should show:
# List of devices attached
# 1234567890ABCDEF device
# If shows "unauthorized", check phone for authorization prompt
Connect via WiFi (optional)
# First connect via USB
adb tcpip 5555
# Find device IP (Settings → About → Status → IP address)
# Then connect wirelessly
adb connect 192.168.1.100:5555
# Disconnect USB cable
# Verify wireless connection
adb devices
Directory Structure
After setup, your SDK should look like:
~/Android/Sdk/
├── build-tools/
│ └── 34.0.0/
│ ├── aapt
│ ├── aapt2
│ ├── apksigner
│ └── ...
├── cmdline-tools/
│ └── latest/
│ └── bin/
│ ├── sdkmanager
│ ├── avdmanager
│ └── ...
├── emulator/
│ ├── emulator
│ └── ...
├── ndk/
│ └── 26.1.10909125/
├── platform-tools/
│ ├── adb
│ ├── fastboot
│ └── ...
├── platforms/
│ └── android-34/
└── system-images/
└── android-34/
Troubleshooting
sdkmanager: command not found
# Check ANDROID_HOME
echo $ANDROID_HOME
# Check PATH
echo $PATH | grep Android
# Reload shell configuration
source ~/.bashrc
adb: command not found
# Install platform-tools
sdkmanager "platform-tools"
# Add to PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools
gomobile init fails
# Make sure NDK is installed
sdkmanager "ndk;26.1.10909125"
# Check ANDROID_HOME
echo $ANDROID_HOME
# Retry
gomobile init -v
Device not detected
# Check USB debugging is enabled
adb devices
# Restart adb
adb kill-server
adb start-server
# Check USB connection/cable
# Try different USB port
NixOS: adb permission denied
# Add user to adbusers group (in configuration.nix)
programs.adb.enable = true;
users.users.youruser.extraGroups = [ "adbusers" ];
# Rebuild and log out/in
sudo nixos-rebuild switch
Nix: Gradle can’t find Android SDK
# Create local.properties
echo "sdk.dir=$ANDROID_HOME" > local.properties
Updating Components
Traditional Setup
# List installed and available packages
sdkmanager --list
# Update all installed packages
sdkmanager --update
# Install specific version
sdkmanager "platforms;android-35"
sdkmanager "build-tools;35.0.0"
Nix Setup
# Update flake inputs
nix flake update
# Rebuild configuration
nixos-rebuild switch # or home-manager switch
Update Gomobile
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
Next Steps
After successful setup:
- Build Android app - Use the Build workflow
- Debug app - Use the Debug workflow
- Create emulator - See emulator section in Debug workflow