Skip to content

Kotlin Android Setup — Complete Development Environment Guide

DodaTech Updated 2026-06-28 7 min read

In this tutorial, you will learn about Kotlin Android Setup. We cover key concepts, practical examples, and best practices to help you master this topic.

Setting up Android development with Kotlin requires Android Studio, the Android SDK, a Gradle build configuration with Kotlin plugins, and either an emulator or physical device for testing apps.

What You'll Learn

  • Install Android Studio and configure the Android SDK
  • Create a new Android project with Kotlin support
  • Understand the Gradle build files (settings, project, app level)
  • Configure Kotlin compiler options and Java compatibility
  • Set up and run the Android Emulator
  • Connect a physical device for testing
  • Debug your first Kotlin Android app

Why It Matters

Android is the largest mobile platform globally, and Kotlin is its official language. Setting up the development environment correctly is the first step toward building Android apps. The setup process involves multiple components: Android Studio, SDK versions, Gradle configuration, and emulator setup. Doing this correctly once saves hours of troubleshooting later.

Real-World Use

DodaTech's Android configuration utility uses the standard Kotlin + Jetpack Compose setup described here. The same Gradle configuration pattern applies to all Android projects at DodaTech, from simple utilities to complex multi-module applications.

Learning Path

flowchart LR
  A[Generics] --> B[Android Setup\nYou are here]
  B --> C[Activities & Fragments]
  style B fill:#f90,color:#fff

Installing Android Studio

Download Android Studio from developer.android.com. Choose the version for your operating system.

  1. Run the installer. On macOS, drag it to Applications. On Windows, run the .exe. On Linux, extract the tar.gz to /opt.
  2. Launch Android Studio. The setup wizard runs on first launch.
  3. Select Standard installation type (recommended).
  4. The wizard downloads the latest Android SDK, platform tools, and a system image for the emulator.
  5. Click Finish.

Creating a New Project

// The main activity generated by the template
package com.example.myfirstapp

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Text("Hello, Kotlin Android!")
        }
    }
}
  1. Open Android Studio and click New Project.
  2. Select Empty Compose Activity (uses Kotlin + Jetpack Compose).
  3. Configure: Name = MyFirstApp, Package = com.example.myfirstapp, Minimum SDK = API 24 (Android 7.0).
  4. Click Finish.

Android Studio generates a project with the Kotlin DSL Gradle configuration.

Understanding the Gradle Build Files

Android projects use Gradle with Kotlin DSL (build.gradle.kts).

settings.gradle.kts

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolution {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "MyFirstApp"
include(":app")

Project-level build.gradle.kts

plugins {
    id("com.android.application") version "8.5.0" apply false
    id("org.jetbrains.kotlin.android") version "2.0.21" apply false
    id("org.jetbrains.kotlin.plugin.compose") version "2.0.21" apply false
}

App-level build.gradle.kts

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    namespace = "com.example.myfirstapp"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.example.myfirstapp"
        minSdk = 24
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"
    }

    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2024.06.00"))
    implementation("androidx.core:core-ktx:1.13.1")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
    implementation("androidx.activity:activity-compose:1.9.0")
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.material3:material3")
}

Output: The build files configure the Android Gradle plugin, Kotlin compiler, Java compatibility, and dependencies for Jetpack Compose.

Running on the Emulator

The Android Emulator simulates a real device on your computer.

  1. In Android Studio, click the Device Manager icon (or Tools > Device Manager).
  2. Click Create device.
  3. Select a device definition (e.g., Pixel 8).
  4. Select a system image (e.g., API 35, Android 15). Download if not installed.
  5. Click Finish.
  6. Click the play icon on the emulator entry to start it.
  7. Click Run > Run 'app' (or the green triangle). Select the emulator and click OK.

The app compiles, installs on the emulator, and launches automatically.

Running on a Physical Device

  1. Enable Developer Options on your Android phone: Settings > About Phone > Tap Build Number 7 times.
  2. Enable USB Debugging: Settings > Developer Options > USB Debugging.
  3. Connect your phone to your computer via USB.
  4. On first connection, accept the RSA key fingerprint on the phone.
  5. In Android Studio, click Run > Run 'app'. Select your device from the list.

The app installs and launches on your phone.

Debugging with Logcat

Logcat is Android's logging system. Use it to debug your app.

import android.util.Log

class MainActivity : ComponentActivity() {
    companion object {
        private const val TAG = "MainActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "Activity created")
        Log.i(TAG, "Starting with intent: ${intent.action}")
        
        setContent {
            Greeting("Android Debugging")
        }
    }
}

@Composable
fun Greeting(name: String) {
    Log.d("Greeting", "Composing greeting for $name")
    Text("Hello, $name!")
}

Output: Logcat shows log messages with tag, level, and timestamp. Filter by tag or level (VERBOSE, DEBUG, INFO, WARN, ERROR).

Open Logcat in Android Studio: View > Tool Windows > Logcat. Use the search bar to filter by tag.

Common Gradle Configuration Issues

Java/Kotlin Version Mismatch

// Ensure consistency across all Kotlin and Java settings
kotlinOptions {
    jvmTarget = "17"
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

Dependency Version Conflicts

Use the Compose BOM (Bill of Materials) to align Compose library versions:

implementation(platform("androidx.compose:compose-bom:2024.06.00"))
implementation("androidx.compose.ui:ui")
// No version needed: BOM manages versions

ProGuard/R8 Configuration

For release builds, configure ProGuard rules in proguard-rules.pro to keep Kotlin-specific classes:

-keep class kotlin.Metadata { *; }
-keepclassmembers class * {
    @kotlin.Metadata <fields>;
}

Common Mistakes

  1. Using wrong compileSdk version: compileSdk must be at least the version of your dependencies. Use compileSdk = 35 for the latest features.

  2. Forgetting the Kotlin plugin in build.gradle.kts: The kotlin.android plugin must be applied. Without it, .kt files are not compiled.

  3. Mixing Java and Kotlin DSL in build files: Use .kts extensions for all build files. Mixing Groovy (.gradle) and Kotlin (.gradle.kts) causes build failures.

  4. Not configuring jvmTarget: Android requires Java 17 bytecode. Set kotlinOptions.jvmTarget = "17" and compileOptions accordingly.

  5. Running on emulator without hardware acceleration: Emulator performance is poor without hardware acceleration. Enable Intel HAXM or Windows Hyper-V.

  6. Ignoring lint warnings: Android Lint catches potential bugs. Address warnings before committing code.

Practice Questions

  1. What is the purpose of compileSdk versus minSdk?

Answer: compileSdk is the Android API level used to compile your app. minSdk is the minimum API level a device must have to install your app. compileSdk should always be the latest stable version.

  1. How do you view debug logs in Android?

Answer: Use Log.d(TAG, message) in your code and view output in the Logcat tool window. Filter by tag, level, or search text.

  1. What is the Compose BOM and why should you use it?

Answer: The Compose Bill of Materials (BOM) manages Compose library versions. Instead of specifying individual versions, you add the BOM once and omit versions from Compose dependencies.

  1. How do you enable USB debugging on a physical device?

Answer: Go to Settings > About Phone > Tap Build Number 7 times to enable Developer Options. Then Settings > Developer Options > USB Debugging.

  1. Challenge: Create a project that uses different build flavors for development and production. Configure the Gradle file to have dev and prod flavors with different application IDs and API endpoints.

Answer:

android {
    flavorDimensions += "environment"
    productFlavors {
        create("dev") {
            dimension = "environment"
            applicationId = "com.example.app.dev"
            versionNameSuffix = "-dev"
        }
        create("prod") {
            dimension = "environment"
            applicationId = "com.example.app"
        }
    }
}

Create src/dev/res/ and src/prod/res/ directories with different config.xml files.

Mini Project

Create a project setup script that automates Android project creation. Requirements:

  • Prompt for project name and package name
  • Generate the directory structure
  • Create build.gradle.kts files with correct configuration
  • Generate a minimal MainActivity.kt with Compose
  • Create a .gitignore file for Android projects
  • Initialize a git Repository

This project reinforces understanding of Android project structure and Gradle configuration.

FAQ

Do I need a Mac to develop Android apps?

No. Android Studio runs on Windows, macOS, and Linux. You can develop, build, and test on all three platforms.

Can I use Kotlin without Android Studio?

Yes. You can build Android apps from the command line with Gradle. Android Studio is recommended for its visual tools and emulator integration.

What is the minimum Android version I should support?

API 24 (Android 7.0) covers 95%+ of active devices. Newer apps often target API 26 (Android 8.0) as minimum.

How do I update the Kotlin version in an existing project?

Update the Kotlin plugin version in the project-level build.gradle.kts: id('org.jetbrains.kotlin.android') version '2.0.21'. Sync the project.

Why is my emulator so slow?

Enable hardware acceleration. On Intel, use HAXM. On AMD, use Hyper-V or WHPX. Also use a lower API level system image for faster boot.

What's Next

After setting up Android, learn about activities and fragments for managing screens. You can also explore Jetpack Compose basics for modern UI development.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro