Personal blog

www.milovetingting.cn

KMM cross-platform development environment construction

KMM is what

Kotlin Multiplatform Mobile (KMM) is a cross-platform Mobile development SDK provided by Jetbrains. With Kotlin’s cross-platform capabilities, you can compile for multiple platforms using a single project.

With KMM, you have flexibility while retaining the benefits of native programming. Use a single code base for business logic code for Android/iOS applications and write platform-specific code only when needed, such as implementing native UI, using platform-specific apis, and so on.

KMM can be seamlessly integrated into your project. Shared code, written in Kotlin, compiled into JVM bytecode using Kotlin/JVM, and compiled into binary using Kotlin/Native, so you can use the KMM business logic module just as you would any other generic class library.

KMM environment construction

Configure the KMM plug-in

  1. Open Android Studio and hit configure-plugins

  2. Search for KMM in plugins and select Install

  3. You need to restart the IDE after installation

  4. Click on the Restart

  5. After restarting the IDE, select create the Android Studio project, and when creating the project, select KMM Application

  6. Configure the project name and package name

  7. After the project is created, the following error may occur. This error occurs because KMM requires Kotlin to be at least 1.4.10

  8. After the project is synchronized, the project directories are as follows: androidApp, iosApp, and shared directories, which correspond to Android, IOS, and shared modules respectively.

  9. Run the App on your phone

Reference documentation

Hello World — Use Kotlin to develop cross-platform applications

Kotlin Multiplatform Mobile Docs

conclusion

In setting up the environment, the process varies depending on the network, as the dependencies need to be downloaded. KMM requires kotlin to be at least 1.4.10 or the project will not be built.