Call Shared Code from the Android App
Wire the shared function into a Jetpack screen.
Call Shared Code from the Android App is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Android Sees Shared Code
The Android app already depends on your shared module, so the greet function is just another Kotlin call from Android's point of view.
No Special Import
Because it is all Kotlin on the JVM, you simply import the shared package like any local class. There is no bridge or wrapper needed.
import com.example.shared.greetCall It Directly
From an Activity or composable you call greet like a normal function. The shared logic runs right inside the Android process.
val message = greet("Android")Show It On Screen
Feed the returned String into a Text composable. The user sees a greeting that was computed by your shared code.
Text(text = greet("Android"))Inside a Composable
Keep the call simple. The composable only displays the result; the wording itself lives safely in commonMain.
@Composable
fun Hello() {
Text(greet("Android"))
}Gradle Wires It Up
The Android module lists the shared module under implementation in its build file. That dependency is what makes the import resolve.
implementation(project(":shared"))Same JVM, Same Types
Android runs on the JVM, just like the shared module's android target. Strings and numbers map across with zero conversion.
Pass Real Data
You can pass any String, like a user's name from state. The shared function stays the same no matter who calls it.
val msg = greet(userName)Build and Run
Hit Run in Android Studio and pick an emulator. Your greeting appears, proving the shared module is fully connected. 🚀
If the Import Fails
An unresolved import usually means a sync is missing. Click sync in Gradle so Android Studio re-reads the dependency.
Logic Stays Shared
Notice you wrote zero greeting logic here. Android is just a consumer, which is exactly the role KMP wants the UI layer to play.
Quick Check
How does Android reach the shared function?
Recap
You wired the shared module into Android with a dependency, imported greet, and showed its result in Compose. No bridge required. 🎉
Frequently asked questions
Is the “Call Shared Code from the Android App” lesson free?
Yes — the full text of “Call Shared Code from the Android App” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.
What will I learn in “Call Shared Code from the Android App”?
Wire the shared function into a Jetpack screen. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Multiplatform Academy?
No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Call Shared Code from the Android App” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Multiplatform Academy lesson?
Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- A Greeting Function in commonMain
- Call Shared Code from the Android App
- Call Shared Code from the iOS App
- Change Once, See It on Both Apps