This is a Kotlin Multiplatform login/logout demo for Android and iOS. The session state and Compose UI live in the shared KMP module, while Android and iOS only host that shared UI.
androidApp: Android application entry point.iosApp: iOS SwiftUI application entry point.shared: Shared Kotlin and Compose Multiplatform code.shared/src/commonMain/kotlin/com/io/kmm/SessionManager.kt: Shared session logic withlogin()andlogout().shared/src/commonMain/kotlin/com/io/kmm/App.kt: Shared Compose UI used by Android and iOS.shared/src/iosMain/kotlin/com/io/kmm/MainViewController.kt: Exposes the shared Compose UI as an iOSUIViewController.iosApp/iosApp/ContentView.swift: Hosts the sharedMainViewController()inside SwiftUI.
- Android Studio with Kotlin Multiplatform support.
- JDK 11 or newer.
- Android SDK installed with the compile SDK configured by the project.
- For iOS: macOS with Xcode installed. iOS apps cannot be run from Windows.
- Open this project in Android Studio.
- Let Gradle sync finish.
- Select the
androidApprun configuration. - Choose an Android emulator or connected device.
- Click Run.
Build the debug APK from a terminal:
./gradlew :androidApp:assembleDebugOn Windows PowerShell:
.\gradlew.bat :androidApp:assembleDebugThe APK is generated at:
androidApp/build/outputs/apk/debug/androidApp-debug.apk
- Open
iosApp/iosApp.xcodeprojin Xcode on macOS. - Select the
iosAppscheme. - Choose an iPhone simulator or a connected iPhone.
- Click Run.
The Xcode project already includes a build phase that runs:
./gradlew :shared:embedAndSignAppleFrameworkForXcodeThat task builds and embeds the Shared KMP framework used by the SwiftUI app. The iOS screen calls MainViewControllerKt.MainViewController(), which renders the same shared login/logout UI used by Android.
Run the shared module tests:
./gradlew :shared:allTestsOn Windows PowerShell:
.\gradlew.bat :shared:allTests