Skip to content

Hello World

codepath-wiki-review[bot] edited this page Jun 15, 2026 · 2 revisions

Overview

A "Hello World" project is the smallest possible Android app: a single screen that prints a greeting on launch. This page walks through creating one in Android Studio using Kotlin and Jetpack Compose — the Android team's recommended UI toolkit for new apps. It mirrors the structure of the official Create your first Android app codelab so you can continue there for more depth.

If you are reading or maintaining an existing XML-Views codebase, start instead at Defining Views and their Attributes — Compose and the Views toolkit are different programming models, and mixing the two in one screen is an advanced topic.

Prerequisites

Install the latest stable Android Studio. It bundles the Kotlin plugin, the Compose tooling, and the SDK components you need; no separate downloads are required.

Compose is Kotlin-only and targets minSdk of API 21 (Lollipop) or higher. The codelab template used below defaults to API 24.

Creating the project

  1. Launch Android Studio and choose New Project (or File → New → New Project if a project is already open).
  2. Under Phone and Tablet, select Empty Activity — the Compose-based default template. (The separate Empty Views Activity template generates the older XML-Views project; do not pick it for this guide.) Click Next.
  3. Configure the project:
    • Name: Greeting Card (or any name)
    • Package name: e.g. com.example.greetingcard
    • Language: Kotlin (the only option, because Compose works only with Kotlin classes)
    • Minimum SDK: API 24 ("Android 7.0 (Nougat)") or higher
    • Build configuration language: Kotlin DSL (default)
  4. Click Finish and wait for Gradle sync to complete.

When the project finishes building, the template includes a single screen that displays the text "Hello Android!".

The generated code

Open app/src/main/java/com/example/greetingcard/MainActivity.kt. The default template looks like this:

package com.example.greetingcard

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.greetingcard.ui.theme.GreetingCardTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            GreetingCardTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

Two pieces are worth understanding:

  • setContent { ... } is the Compose equivalent of the older setContentView(R.layout.activity_main). It tells the activity to render the supplied composable function as its UI; there is no XML layout file.
  • @Composable fun Greeting(name: String, ...) is a composable function — a function that describes UI by emitting elements (here, a single Text). Composables are the basic building blocks of Compose: they take inputs as parameters, can be called from other composables, and are previewed in the IDE without running the app. See the official Compose tutorial for the full mental model.

The "Hello Android!" that appears on the device comes from the Greeting("Android") call inside setContent — the string "Android" is interpolated into "Hello $name!" inside the Text composable.

Running the app

Connect a physical device with USB debugging enabled, or start an emulator from Device Manager, then click the Run ▶ button in the toolbar (shortcut: Ctrl+R on macOS, Shift+F10 on Windows/Linux). Android Studio builds the APK, installs it on the selected device, and launches the activity. The screen shows "Hello Android!" on the default theme background.

Changing the greeting

Edit the call site in onCreate to pass a different name:

Greeting("World")

Rerun the app and the screen now displays "Hello World!".

For an interactive preview without restarting the emulator, add a preview composable at the bottom of MainActivity.kt:

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    GreetingCardTheme {
        Greeting("World")
    }
}

Switch the editor to Split or Design view (top-right of the file tab) to render the preview alongside the code. The preview updates when you change the composable, so you can iterate on layout and styling without redeploying.

Next steps

References

Finding these guides helpful?

We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.

Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.

Clone this wiki locally