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
| Frontend | Android | Description |
|---|---|---|
| Node.js | JDK (Java Development Kit) | Runtime environment |
| VS Code / WebStorm | Android Studio (based on IntelliJ) | IDE |
| npm / yarn / pnpm | Gradle | Build tool + dependency management |
package.json | build.gradle | Project config + dependency declaration |
node_modules/ | .gradle/ + Maven local repo | Dependency cache |
| Browser DevTools | Android Studio Debugger + Logcat | Debugging tools |
| Chrome / Firefox | Android Emulator / Physical device | Runtime target |
1. Install JDK
Android development requires JDK. Android Studio comes with JetBrains Runtime, but it's recommended to install separately for easier management.
Recommended Versions
- 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):
# Using Scoop
scoop bucket add java
scoop install temurin17-jdk
# Or download from Adoptium: https://adoptium.net/macOS (recommended: Homebrew):
brew install --cask temurin@17Linux (Ubuntu/Debian):
sudo apt install openjdk-17-jdkVerify Installation
java -version
# Should show: openjdk version "17.x.x"
javac -version
# Should show: javac 17.x.xEnvironment Variables
# 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:$PATH2. 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
- Installation Type: Choose "Standard"
- UI Theme: Personal preference (frontend developers usually prefer Dark theme)
- 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 Action | Android Studio Equivalent | Shortcut |
|---|---|---|
| Command Palette | Find Action | Ctrl+Shift+A (Win) / Cmd+Shift+A (Mac) |
| File Search | Navigate to File | Ctrl+Shift+N / Cmd+Shift+O |
| Global Search | Find in Files | Ctrl+Shift+F / Cmd+Shift+F |
| Terminal | Terminal | Alt+F12 / Option+F12 |
| Sidebar | Project Panel | Alt+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 Version | API Level | Codename |
|---|---|---|
| Android 8.0 | 26 | Oreo |
| Android 9.0 | 28 | Pie |
| Android 10 | 29 | Q |
| Android 11 | 30 | R |
| Android 12 | 31 | S |
| Android 13 | 33 | Tiramisu |
| Android 14 | 34 | Upside Down Cake |
| Android 15 | 35 | Vanilla Ice Cream |
SDK Tools
Make sure to install:
- Android SDK Build-Tools (latest version)
- Android SDK Platform-Tools (includes
adbcommand) - 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:
# macOS / Linux
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH4. Create Your First Project
Via Android Studio
File → New → New Project- Choose Empty Views Activity
- 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)
- Name:
- 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 config5. Run the App
Android Emulator
- Open Device Manager:
Tools → Device Manager - Click Create Device
- Choose a device template (e.g., Pixel 7)
- Download a system image (recommend Android 14 / API 34, x86_64)
- Click Finish
- Click the ▶️ button to start the emulator
Real Device
- Enable Developer Options: Go to
Settings → About Phone, tap "Build Number" 7 times - Enable USB Debugging:
Settings → Developer Options → USB Debugging - Connect via USB, authorize the computer
- 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
# 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.png6. 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):
// Top-level build file
plugins {
id 'com.android.application' version '8.2.0' apply false
}Module-level app/build.gradle:
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 Concept | Frontend Equivalent | Description |
|---|---|---|
dependencies {} | package.json dependencies | Dependency declaration |
compileSdk | TypeScript target | Compilation target API level |
minSdk | browserslist | Minimum supported Android version |
buildTypes | NODE_ENV | Build variants (debug/release) |
applicationId | App bundle ID | Unique 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
# 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 lintCommon Environment Issues
When setting up the environment or opening a legacy project, you may encounter these common issues.
Gradle Sync Failures
| Error | Cause | Solution |
|---|---|---|
Could not find com.android.tools.build:gradle:X.X.X | AGP version incompatible with Gradle | Check the AGP/Gradle compatibility table in Module 03 |
Unsupported class file major version XX | JDK version mismatch | Switch to the JDK required by the project (usually 17 or 11) |
Could not resolve all files for configuration | Dependency download failed | Check network, proxy, or mirror configuration |
SDK location not found | SDK path not configured | Check/create local.properties |
Minimum supported Gradle version is X.Y | Gradle Wrapper version too old | Upgrade Gradle Wrapper per compatibility table |
# Stop the Gradle daemon to resolve many cache-related issues
./gradlew --stop
# Clean build cache
./gradlew clean
# Refresh dependencies
./gradlew build --refresh-dependenciesEmulator / Device Connection
# 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.apkJDK 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:
# 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_HOMEenvironment 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 cleanfirst - 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.