Skip to content

Module 01: Development Environment Setup

Goal: Set up a complete development environment that can compile and run Java Android projects.

Frontend vs. Android Development Environment

FrontendAndroidDescription
Node.jsJDK (Java Development Kit)Runtime environment
VS Code / WebStormAndroid Studio (based on IntelliJ)IDE
npm / yarn / pnpmGradleBuild tool + dependency management
package.jsonbuild.gradleProject config + dependency declaration
node_modules/.gradle/ + Maven local repoDependency cache
Browser DevToolsAndroid Studio Debugger + LogcatDebugging tools
Chrome / FirefoxAndroid Emulator / Physical deviceRuntime target

1. Install JDK

Android development requires JDK. Android Studio comes with JetBrains Runtime, but it's recommended to install separately for easier management.

  • JDK 17: Minimum requirement for current Android Gradle Plugin 8.x, also compatible with most legacy projects
  • JDK 21: Supported by newer AGP, preferred for new projects

Legacy Project Note: If you're taking over a project using an older Gradle version (like 6.x or 7.x), you may need JDK 11 or even JDK 8. Read the project documentation first before deciding.

Installation

Windows (recommended: Scoop or manual download):

bash
# Using Scoop
scoop bucket add java
scoop install temurin17-jdk

# Or download from Adoptium: https://adoptium.net/

macOS (recommended: Homebrew):

bash
brew install --cask temurin@17

Linux (Ubuntu/Debian):

bash
sudo apt install openjdk-17-jdk

Verify Installation

bash
java -version
# Should show: openjdk version "17.x.x"

javac -version
# Should show: javac 17.x.x

Environment Variables

bash
# Windows (PowerShell, permanent)
[System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\path\to\jdk-17", "User")

# macOS / Linux (~/.zshrc or ~/.bashrc)
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export PATH=$JAVA_HOME/bin:$PATH

2. Install Android Studio

Download

Download the latest Android Studio from the official website: https://developer.android.com/studio

Choose the latest stable version (e.g., Hedgehog 2023.1, Iguana 2023.2, Jellyfish 2023.3, etc.).

First Launch Configuration

  1. Installation Type: Choose "Standard"
  2. UI Theme: Personal preference (frontend developers usually prefer Dark theme)
  3. SDK Components: Default selections are fine, ensure these are checked:
    • Android SDK
    • Android SDK Platform
    • Android Virtual Device (AVD)

Getting Familiar with the IDE

Android Studio is based on IntelliJ IDEA. If you're a VS Code user, note these differences:

VS Code ActionAndroid Studio EquivalentShortcut
Command PaletteFind ActionCtrl+Shift+A (Win) / Cmd+Shift+A (Mac)
File SearchNavigate to FileCtrl+Shift+N / Cmd+Shift+O
Global SearchFind in FilesCtrl+Shift+F / Cmd+Shift+F
TerminalTerminalAlt+F12 / Option+F12
SidebarProject PanelAlt+1 / Cmd+1

Tip: You can switch to VS Code keymap in File → Settings → Keymap.

3. Android SDK Management

SDK Manager

Open via: File → Settings → Languages & Frameworks → Android SDK (on Mac: Android Studio → Settings)

The SDK has three tabs:

SDK Platforms

  • Check the latest Android 14 (API 34) or higher
  • If the legacy project you're taking over has a lower compileSdkVersion (e.g., 28, 30), download those versions too
  • API Level Reference (common):
Android VersionAPI LevelCodename
Android 8.026Oreo
Android 9.028Pie
Android 1029Q
Android 1130R
Android 1231S
Android 1333Tiramisu
Android 1434Upside Down Cake
Android 1535Vanilla Ice Cream

SDK Tools

Make sure to install:

  • Android SDK Build-Tools (latest version)
  • Android SDK Platform-Tools (includes adb command)
  • Android SDK Command-line Tools
  • Android Emulator

SDK Update Sites

Keep defaults.

SDK Path

Default SDK installation location:

  • Windows: C:\Users\<username>\AppData\Local\Android\Sdk
  • macOS: ~/Library/Android/sdk
  • Linux: ~/Android/Sdk

Remember this path — you'll need it when configuring environment variables:

bash
# macOS / Linux
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH

4. Create Your First Project

Via Android Studio

  1. File → New → New Project
  2. Choose Empty Views Activity
  3. Fill in project info:
    • Name: HelloAndroid
    • Package name: com.example.helloandroid
    • Language: Java (this tutorial focuses on Java)
    • Minimum SDK: API 24 (Android 7.0, covers 95%+ devices)
  4. Click Finish

Key Files

app/
├── src/main/
│   ├── java/com/example/helloandroid/
│   │   └── MainActivity.java      ← Main entry point
│   ├── res/
│   │   ├── layout/
│   │   │   └── activity_main.xml  ← UI layout
│   │   └── values/
│   │       ├── strings.xml        ← String resources
│   │       ├── colors.xml         ← Color definitions
│   │       └── themes.xml         ← Theme config
│   └── AndroidManifest.xml        ← App manifest
└── build.gradle                   ← Module-level build config

5. Run the App

Android Emulator

  1. Open Device Manager: Tools → Device Manager
  2. Click Create Device
  3. Choose a device template (e.g., Pixel 7)
  4. Download a system image (recommend Android 14 / API 34, x86_64)
  5. Click Finish
  6. Click the ▶️ button to start the emulator

Real Device

  1. Enable Developer Options: Go to Settings → About Phone, tap "Build Number" 7 times
  2. Enable USB Debugging: Settings → Developer Options → USB Debugging
  3. Connect via USB, authorize the computer
  4. The device will appear in Android Studio's device dropdown

Run

Click the green ▶️ button (or Shift+F10), choose the target device, and wait for compilation and installation.

ADB Commands

bash
# List connected devices
adb devices

# Install APK
adb install app/build/outputs/apk/debug/app-debug.apk

# View logs
adb logcat

# Filter logs by tag
adb logcat -s "MainActivity"

# Enter device shell
adb shell

# Screenshot
adb exec-out screencap -p > screenshot.png

6. Gradle Configuration

Gradle is Android's build system — similar to frontend build tools like Vite or Webpack, but more powerful.

Two build.gradle Files

Project-level build.gradle (root directory):

groovy
// Top-level build file
plugins {
    id 'com.android.application' version '8.2.0' apply false
}

Module-level app/build.gradle:

groovy
plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.helloandroid'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.helloandroid"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

Key Concepts

Gradle ConceptFrontend EquivalentDescription
dependencies {}package.json dependenciesDependency declaration
compileSdkTypeScript targetCompilation target API level
minSdkbrowserslistMinimum supported Android version
buildTypesNODE_ENVBuild variants (debug/release)
applicationIdApp bundle IDUnique app identifier

Sync Gradle

After modifying build.gradle, click the Sync Now banner at the top, or: File → Sync Project with Gradle Files

Common Commands

bash
# Clean build
./gradlew clean

# Build debug APK
./gradlew assembleDebug

# Build release APK
./gradlew assembleRelease

# Install to device
./gradlew installDebug

# Run tests
./gradlew test

# Run lint checks
./gradlew lint

Common Environment Issues

When setting up the environment or opening a legacy project, you may encounter these common issues.

Gradle Sync Failures

ErrorCauseSolution
Could not find com.android.tools.build:gradle:X.X.XAGP version incompatible with GradleCheck the AGP/Gradle compatibility table in Module 03
Unsupported class file major version XXJDK version mismatchSwitch to the JDK required by the project (usually 17 or 11)
Could not resolve all files for configurationDependency download failedCheck network, proxy, or mirror configuration
SDK location not foundSDK path not configuredCheck/create local.properties
Minimum supported Gradle version is X.YGradle Wrapper version too oldUpgrade Gradle Wrapper per compatibility table
bash
# Stop the Gradle daemon to resolve many cache-related issues
./gradlew --stop

# Clean build cache
./gradlew clean

# Refresh dependencies
./gradlew build --refresh-dependencies

Emulator / Device Connection

bash
# adb cannot see the device
adb kill-server
adb start-server
adb devices

# Wireless debugging disconnected
adb connect <phone-ip>:5555

# APK install failed (signature conflict or downgrade)
adb install -r -d app-debug.apk

JDK Version Switching

Android Studio lets you configure the JDK per project:

File → Settings → Build, Execution, Deployment → Build Tools → Gradle → Gradle JDK

Frontend analogy: This is similar to .nvmrc + nvm use; each Android project should pin its own JDK.

Gradle Daemon and Cache

The Gradle Daemon is like node_modules cache — it speeds up subsequent builds but consumes memory:

bash
# List running daemons
./gradlew --status

# Stop all daemons
./gradlew --stop

# Delete Gradle cache (like deleting node_modules/.cache)
rm -rf ~/.gradle/caches/

Quick Reference

  • Cannot find SDK: Ensure ANDROID_HOME environment variable is set correctly
  • Emulator too slow: Enable HAXM (Intel) or HAXM equivalent; or use a physical device
  • Gradle sync fails: Check internet connection; Gradle needs to download dependencies
  • Compilation errors: Run ./gradlew clean first
  • Device not recognized: Check USB debugging authorization; try adb kill-server && adb start-server

Next Steps

Environment setup is complete! Now let's learn the Java basics.

A Java Android development tutorial for frontend developers