- Install Android Studio and create a project from the Empty Activity template
- Explain the project structure and the roles of
build.gradle.ktsandlibs.versions.toml - Run the app on an emulator and on a real phone
- Write messages with
Log.dand 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.
- 1Install
Run the installer, then choose the
Standardsetup in the Setup Wizard and wait while the components download. - 2Pick a template
Open
File › New › New Project…, and underPhone and Tabletchoose theEmpty Activitytemplate — it is already built with Jetpack Compose. - 3Fill in the fields
Name:Educora Notes,Package name:com.educora.notes. ForMinimum SDKpick, for example, API 24 — the wizard shows what share of devices this covers. KeepKotlin DSLas theBuild configuration languageand pressFinish. - 4Wait 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 insideapp/src/main, in thecom.educora.notespackage.- 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.ktsfiles andgradle/libs.versions.toml— the build settings and the version catalog, which keeps all library versions in one place.
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.
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.versionCodeandversionName— 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.
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
}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)
}=, strings use double quotes and functions use parentheses, and the editor gives you autocompletion and error checking.MainActivity: the app's front door
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)
}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.
- 1Create a virtual device
Open
View › Tool Windows › Device Manager, press+and chooseCreate Virtual Device. Pick a phone model (for example, a Pixel) and a system image with the latest Android version, then pressFinish. - 2Run
Choose the device in the toolbar list and press the green
Runtriangle orShift+F10. Gradle builds the app, installs it on the device and opens it. - 3Unlock developer options on the phone
In
Settings › About phone, tapBuild numberseven times. Then turn onUSB debugginginDeveloper options(where the menu is may depend on the manufacturer). - 4Connect 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 debuggingand scan the QR code fromPair Devices Using Wi-Fiin 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).
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 { ... }
}
}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.| Query | What it shows |
|---|---|
package:mine | only messages from the apps of the open project |
tag:MainActivity | messages with this tag |
level:WARN | WARN and more serious levels (ERROR, ASSERT) |
is:crash | app crashes |
-tag:Choreographer | hides this tag (- negates) |
package:mine level:ERROR.Ctrl+R)Shift+F10Ctrl+D)Shift+F9Ctrl+Cmd+R)Ctrl+F10Cmd+F9)Ctrl+F9Cmd+6)Alt+6Cmd+Shift+A)Ctrl+Shift+AKey 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 inlibs.versions.toml. applicationIdis 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/ewrite messages to Logcat; the filterspackage:mine,tag:andlevel:help you find what you need.
Check yourself
10 questions. Every correct answer earns XP.
applicationId, minSdk and versionCode set?