Skip to content
/ KMP-Template Public template

A Git repository providing a Kotlin Multiplatform Project template

Notifications You must be signed in to change notification settings

ml-opensource/KMP-Template

Repository files navigation

Kotlin Multiplatform Project Setup

kotlin-version

This Kotlin Multiplatform project targets Android and iOS using Compose Multiplatform.

💻 Techstack

📒 Todo

  • Jetpack Navigation
  • Deeplink Support
  • Build Logic

Project Setup

Android:

  1. Open the project in Android Studio.
  2. Wait for the build to finish.
  3. Select composeApp from the Run/Debug Configurations.
  4. Apply and run.

iOS:

  1. Navigate to the KMP-Template/iosApp directory.
  2. For first-time setup:
    • Open terminal in that directory and run the command pod install.
    • It’ll generate the iosApp.xcworkspace file.
  3. Open the iosApp.xcworkspace file in Xcode.
  4. Choose the correct target for your device or simulator in the scheme chooser at the top of the window.
  5. Build and run.

iOS with Swift UI:

If you want to run the iOS app with swift UI (not compose multiplatform)

  1. Open the iosApp.xcworkspace file in Xcode.
  2. Navigate to the iosApp/presentation/ContentView file in Xcode.
  3. Inside the ContentView body, uncomment the line SplashScreen() and comment out the ComposeView().ignoresSafeArea(.keyboard).
  4. Build and run.

Structure

  • /composeApp: Contains code shared across the Compose Multiplatform applications.

    • commonMain: Holds code that's common for all targets.
    • Platform-specific directories (e.g., androidMain, iosMain): Contain Kotlin code that will compile only for the designated platform. For iOS-specific Kotlin code, such as integration with Apple's CoreCrypto, uses iosMain.
  • /iosApp: Contains the iOS application. This is the necessary entry point for the iOS app, even when sharing UI with Compose Multiplatform. This is also where to add any SwiftUI code for your project.

Architecture

Template implements Clean Architecture and follows best practices provided by Google with some tweaks here and there

Presentation layer

The Presentation layer or UI Layer is our Jetpack Compose UI screens and components, and ViewModels. The Presentation layer interacts with the Domain Layer where our business logic resides.

Domain layer

The domain layer contains the application's business logic. This layer only works with abstractions and as such it never knows about how different layers look like. It doesn't know about any Databases, APIs, or even any Frameworks.

Data layer

The data layer is where the actual interactions happen between different data sources. This layer “implements” parts of the Domain layer and communicates with the APIs, Databases, and other services and SDKs.

Tools

These are the tools used in the template, to improve the development, that you should be aware of:

Spotless is a Gradle plugin used for consistent code formatting and style conventions across the project. You can use it running the following Gradle commands:

./gradlew spotlessCheck - Checks the style formatting and displays any issues

./gradlew spotlessApply - Same as above but automatically tries to fix most of the issues. If for any reason it can't, then a list of problems is displayed.

Additional Resources

For more information on Kotlin Multiplatform, visit the official documentation.