Kotlin & Android Setup Guide - CodeSwordsman

Set up Kotlin and Android: Android Studio, cmdline-tools and SDKs, ANDROID_HOME, Gradle mirrors, emulators, adb debugging and common error fixes.

Kotlin 2.x / AGP 8.xUpdated 2026-10-2929 commands

Install & Version Management

Install Android Studio on Windows; the first-run wizard downloads the SDK and an emulator

winget install Google.AndroidStudio

Make sure the wizard selects Android SDK, SDK Platform-Tools and at least one API level

Install Android Studio with Homebrew on macOS or snap on Ubuntu

# macOS
brew install --cask android-studio
# Ubuntu
sudo snap install android-studio --classic

Install platform-tools, a specific API platform and build tools from the CLI

sdkmanager --list
sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0"

sdkmanager lives in cmdline-tools/latest/bin; add it to PATH first

Install a system image for creating AVDs

sdkmanager --install "system-images;android-34;google_apis;x86_64"

AGP 8.x requires JDK 17, so install one for Gradle to use

winget install EclipseAdoptium.Temurin.17.JDK

Mirrors & Proxy

Add the Aliyun repo to pluginManagement in settings.gradle.kts to speed up plugin resolution

pluginManagement {
  repositories {
    maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
    google()
    mavenCentral()
  }
}

Declare dependency repositories once in settings.gradle.kts instead of per module

dependencyResolutionManagement {
  repositories {
    maven { url = uri("https://maven.aliyun.com/repository/public") }
    google()
    mavenCentral()
  }
}

Inspect global Gradle properties where proxy and JVM memory settings live

# Windows
type %USERPROFILE%\.gradle\gradle.properties
# macOS / Linux
cat ~/.gradle/gradle.properties

Write this into ~/.gradle/gradle.properties so Gradle downloads go through the proxy

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890

Raise the Gradle heap and pin file encoding to avoid stalls and mojibake

org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8

Environment Variables

Set ANDROID_HOME and add platform-tools to PATH so adb can be called directly

# Windows
setx ANDROID_HOME "%LOCALAPPDATA%\Android\Sdk"
setx PATH "%PATH%;%ANDROID_HOME%\platform-tools"
# macOS / Linux
echo 'export ANDROID_HOME="$HOME/Library/Android/sdk"' >> ~/.zshrc

Confirm the variable points at a real SDK directory containing platforms and build-tools

echo %ANDROID_HOME%
# macOS / Linux
echo $ANDROID_HOME

Point Gradle at JDK 17 to avoid AGP version checks failing

# Windows PowerShell
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-17", "User")

Verify adb works and list connected devices or emulators

adb version
adb devices

Create & Verify

Verify the JDK and Gradle wrapper versions; always use the wrapper instead of a local gradle

java -version
./gradlew --version

List and create AVDs; the Device Manager in Android Studio does the same

avdmanager list avd
avdmanager create avd -n pixel_34 -k "system-images;android-34;google_apis;x86_64"

Launch an emulator from the CLI; add -no-window on headless machines

emulator -list-avds
emulator -avd pixel_34

Build the debug APK under app/build/outputs/apk/debug

./gradlew assembleDebug

Install on the device and launch the main activity

./gradlew installDebug
adb shell am start -n com.example.app/.MainActivity

Check the standalone Kotlin compiler version; Android projects usually let the Gradle plugin manage it

kotlinc -version

IDE & Plugins

Install Kotlin language support and the Gradle task panel in VS Code

code --install-extension mathiasfrohlich.kotlin
code --install-extension vscjava.vscode-gradle

IntelliJ IDEA Community works for pure Kotlin/JVM; Android still favors Android Studio

winget install JetBrains.IntelliJIDEA.Community

Filter logcat down to crash logs for fast runtime stack traces

adb logcat -s AndroidRuntime

Troubleshooting

Accept the SDK licenses when builds fail on unaccepted agreements

sdkmanager --licenses

Restart the adb server when the device list is empty or shows offline

adb kill-server
adb start-server
adb devices

Stop the Gradle daemon and rebuild without it when builds hang

./gradlew --stop
./gradlew clean assembleDebug --no-daemon
Risky

Delete the module cache when dependencies are corrupt; the next build re-downloads them

rm -rf ~/.gradle/caches/modules-2

Trace dependency conflicts and duplicate or mismatched library versions

./gradlew :app:dependencies --configuration debugRuntimeClasspath

Route device traffic through the host proxy for packet capture debugging

adb shell settings put global http_proxy 127.0.0.1:7890

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.