Skip to content
Educora
Advanced20 min9 / 14

Android Studio and your first app

Install Android Studio, create a Compose project, understand the project structure and the Gradle Kotlin DSL files, run the app on an emulator and on a phone, and read log messages in Logcat.

Check yourself
In this lesson you will learn
  • Install Android Studio and create a project from the Empty Activity template
  • Explain the project structure and the roles of build.gradle.kts and libs.versions.toml
  • Run the app on an emulator and on a real phone
  • Write messages with Log.d and filter them in Logcat

You already know Kotlin: variables, functions, classes, coroutines. Now comes the most exciting moment — seeing your code on your own phone's screen. For this you need Android Studio, Google's official and free development environment for Android apps. It runs on Windows, macOS and Linux. In this lesson you will install it, create your first project, run it on an emulator and on a phone, and learn to read the app's “diary”.

Installation and a new project

Download Android Studio from developer.android.com/studio. On the first launch the Setup Wizard starts and downloads everything you need: the Android SDK (libraries and tools), the emulator and the platform tools. The emulator needs a lot of memory, so the more RAM your computer has, the smoother your work will be.

  1. 1
    Install

    Run the installer, then choose the Standard setup in the Setup Wizard and wait while the components download.

  2. 2
    Pick a template

    Open File › New › New Project…, and under Phone and Tablet choose the Empty Activity template — it is already built with Jetpack Compose.

  3. 3
    Fill in the fields

    Name: Educora Notes, Package name: com.educora.notes. For Minimum SDK pick, for example, API 24 — the wizard shows what share of devices this covers. Keep Kotlin DSL as the Build configuration language and press Finish.

  4. 4
    Wait for the Gradle sync

    The first sync downloads the libraries from the internet and can take a few minutes. You can follow the progress in the status bar at the bottom of the window.

Project structure and Gradle

On the left is the Project window (Alt+1). When the Android view is selected at its top, the files are grouped in a way that is convenient for apps. The most important parts are:

  • MainActivity.kt — the app's starting screen; the Kotlin code lives inside app/src/main, in the com.educora.notes package.
  • The ui/theme/ folder — Color.kt, Type.kt, Theme.kt: the app's Material 3 colours and fonts.
  • AndroidManifest.xml — the app's “passport”: its name, icon, screens (activities) and permissions, such as internet access.
  • res/ — resources: drawable (images), mipmap (launcher icons), values/strings.xml (texts and their translations).
  • The build.gradle.kts files and gradle/libs.versions.toml — the build settings and the version catalog, which keeps all library versions in one place.
Definition
Gradle

The build system of Android projects. It compiles the code, downloads the libraries you need (dependencies) and packs everything into an APK that is installed on a phone or an AAB that is uploaded to Google Play. Its settings are written in Kotlin in .kts files.

Kotlin
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.compose)
}

android {
    namespace = "com.educora.notes"
    compileSdk = 36

    defaultConfig {
        applicationId = "com.educora.notes"
        minSdk = 24
        targetSdk = 36
        versionCode = 1
        versionName = "0.1.0"
    }
    buildFeatures {
        compose = true
    }
}

dependencies {
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.material3)
    implementation(libs.androidx.activity.compose)
}
app/build.gradle.kts (simplified). Projects on AGP 8.x also have the line alias(libs.plugins.kotlin.android); starting with AGP 9, Kotlin support is built into the plugin.
  • applicationId — the app's unique identifier on Google Play.
  • minSdk — the oldest Android version the app runs on; targetSdk — the version the app is tested against and adapted to; compileSdk — the SDK used to compile it.
  • versionCode and versionName — the app's version; we will cover them in detail in the publishing lesson.
  • libs.… — names that come from the version catalog; the Compose BOM (platform(...)) keeps the versions of all Compose libraries in line with each other.
Old: build.gradle (Groovy)
android {
    namespace 'com.educora.notes'
    compileSdk 36
    defaultConfig {
        applicationId "com.educora.notes"
        minSdk 24
        versionCode 1
        versionName "0.1.0"
    }
}
dependencies {
    implementation libs.androidx.material3
}
New: build.gradle.kts (Kotlin DSL)
android {
    namespace = "com.educora.notes"
    compileSdk = 36
    defaultConfig {
        applicationId = "com.educora.notes"
        minSdk = 24
        versionCode = 1
        versionName = "0.1.0"
    }
}
dependencies {
    implementation(libs.androidx.material3)
}
Older projects use Groovy, newer ones use the Kotlin DSL. In the Kotlin DSL assignments use =, strings use double quotes and functions use parentheses, and the editor gives you autocompletion and error checking.

MainActivity: the app's front door

Kotlin
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            EducoraNotesTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(text = "Hello $name!", modifier = modifier)
}
The code the template creates. On screen: the text “Hello Android!” in the top-left corner, below the status bar.

An Activity is a window of the app. When the system creates it, it calls onCreate. enableEdgeToEdge() stretches the content over the whole screen, under the status and navigation bars. setContent { } defines the screen's content with Compose: the theme, the Scaffold frame and the Greeting function. innerPadding keeps the text from hiding under the system bars.

Run it on an emulator and on a phone

You can run the app in two places: on a virtual phone running on your computer — the emulator (an AVD, Android Virtual Device) — or on a real phone connected by USB cable or Wi-Fi. A real device is usually faster and lets you test touch, the camera and sensors for real.

  1. 1
    Create a virtual device

    Open View › Tool Windows › Device Manager, press + and choose Create Virtual Device. Pick a phone model (for example, a Pixel) and a system image with the latest Android version, then press Finish.

  2. 2
    Run

    Choose the device in the toolbar list and press the green Run triangle or Shift+F10. Gradle builds the app, installs it on the device and opens it.

  3. 3
    Unlock developer options on the phone

    In Settings › About phone, tap Build number seven times. Then turn on USB debugging in Developer options (where the menu is may depend on the manufacturer).

  4. 4
    Connect and allow

    Connect the phone by USB and accept the “Allow USB debugging?” prompt on its screen. To work without a cable (Android 11+), turn on Wireless debugging and scan the QR code from Pair Devices Using Wi-Fi in Android Studio.

Logcat: the app's diary

On a phone there is no console where you would see the text from println. On Android, messages go to the system log, and Android Studio shows them in the Logcat window (View › Tool Windows › Logcat). You write messages with the Log class; every message has a tag (the name of its source) and a level: Log.v (verbose), Log.d (debug), Log.i (info), Log.w (warning), Log.e (error).

Kotlin
private const val TAG = "MainActivity"

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "onCreate called")
        val lessons = listOf("Kotlin", "Compose", "Gradle")
        Log.i(TAG, "Loaded ${lessons.size} lessons")
        Log.w(TAG, "No internet, showing cached data")
        // setContent { ... }
    }
}
In Logcat, with the filter tag:MainActivity, you will see three lines with the levels D, I and W; each line shows the time, the package name and the message.
QueryWhat it shows
package:mineonly messages from the apps of the open project
tag:MainActivitymessages with this tag
level:WARNWARN and more serious levels (ERROR, ASSERT)
is:crashapp crashes
-tag:Choreographerhides this tag (- negates)
Queries can be combined: package:mine level:ERROR.
run the app (Mac: Ctrl+R)Shift+F10
run with the debugger (Mac: Ctrl+D)Shift+F9
send changes to the running app — Apply Changes and Restart Activity (Mac: Ctrl+Cmd+R)Ctrl+F10
build the project without running it (Mac: Cmd+F9)Ctrl+F9
show or hide the Logcat window (Mac: Cmd+6)Alt+6
find any command by name — Find Action (Mac: Cmd+Shift+A)Ctrl+Shift+A

Key points

  • Android Studio is Google's official, free environment; the Empty Activity template creates a ready Compose project.
  • Gradle builds the project; settings live in build.gradle.kts, library versions in libs.versions.toml.
  • applicationId is the app's unique name on Google Play and never changes after publishing.
  • The app runs on an emulator (AVD) or on a phone connected by USB or Wi-Fi; on the phone, developer options must be unlocked first.
  • Log.d/i/w/e write messages to Logcat; the filters package:mine, tag: and level: help you find what you need.

Check yourself

10 questions. Every correct answer earns XP.

1 / 10
In which file are applicationId, minSdk and versionCode set?