KMP: Essential Tools and Plugins for Kotlin Multiplatform Application Development

Santiago Mattiauda
13 min readJun 4, 2024

--

In this article, I attempt to provide a brief overview of various tools and plugins that facilitate and optimize the development of applications with Kotlin Multiplatform. I explore the functionalities and benefits of each tool, which include SKIE, KMMBridge, Xcode Kotlin, KMM Plugin, Dokka, and DeteKt. Each section details the main features, integration with other development tools, and how each one enhances the developer’s experience. Overall, this document serves as a comprehensive guide for developers interested in exploring and understanding the ecosystem of Kotlin Multiplatform tools.

KDoctor

KDoctor ensures that all required components are properly installed and ready for use. If something is missed or not configured, KDoctor highlights the problem and suggests how to fix the problem.

KDoctor runs the following diagnostics:

  • System — checks an operating system version
  • JDK — checks that JDK installation and JAVA_HOME setting
  • Android Studio — checks Android Studio installation, Kotlin and Kotlin Multiplatform Mobile plugins
  • Xcode — checks Xcode installation and setup
  • CocoaPods — checks ruby environment and cocoapods gem installation

Extra diagnostics:

SKIE

One of the main disadvantages of Kotlin Multiplatform is the lack of direct interaction with Swift. Without this, Swift can only communicate with Kotlin indirectly, through Objective-C. This approach, although functional, has many limitations and causes Kotlin to lose support for many of its language features.

SKIE is a specialized plugin of the Kotlin native compiler that recovers support for some of these features by modifying the Xcode framework produced by the Kotlin compiler.

Thanks to this, it is not necessary to change the way you distribute and consume your Kotlin Multiplatform frameworks.

Developed by TouchLab, SKIE is designed to facilitate the development of projects with Kotlin Multiplatform, focusing on improving interoperability and the safe export of interfaces between different platforms. Below, its features oriented to Kotlin Multiplatform are described.

SKIE Features

  • Safe Interface Exportation: Verifies type compatibility between platforms and ensures multi-platform interoperability.
  • Export Process Automation: Automatically generates the necessary code and simplifies configuration with a Gradle DSL.
  • Multi-platform Compatibility: Compatible with all Kotlin Multiplatform targets and integrates well with existing tools.
  • Support and Extensibility: Provides comprehensive documentation and allows extensions to adapt to project needs.
  • Active Maintenance: TouchLab regularly updates SKIE and has the backing of an active community.

SKIE is a powerful and essential tool for Kotlin Multiplatform developers. It allows them to safely and efficiently export interfaces between different platforms. With features that automate the export process and ensure type compatibility, SKIE significantly improves the development experience. In addition, it facilitates the creation of robust and easy-to-maintain multi-platform applications.

Next, we see an example of the use of Sealed Classes in Swift:

sealed class Status {
object Loading : Status()
data class Error(val message: String) : Status()
data class Success(val result: SomeData) : Status()
}

Swift without SKIE:

func updateStatus(status: Status) {
switch status {
case _ as Status.Loading:
showLoading()
case let error as Status.Error:
showError(message: error.message)
case let success as Status.Success:
showResult(data: success.result)
default:
fatalError("Unknown status")
}
}

Swift with SKIE

func updateStatus(status: Status) {
switch onEnum(of: status) {
case .loading:
showLoading()
case .error(let error):
showError(message: error.message)
case .success(let success):
showResult(data: success.result)
}
}

To see more features of SKIE, I leave its documentation below.

KMMBridge

KMMBridge is a Gradle tool that simplifies the publication of Kotlin Multiplatform framework binaries for Xcode. It allows publication on different backends and its use through CocoaPods or Swift Package Manager.

  • Creates and publishes XCFramework zip files of your Kotlin modules
  • Publishes on various online storage platforms
  • Configures and publishes versions for SPM and CocoaPods for other developers

It offers a local development flow for SPM in addition to its publication functionality.

It is aimed at those who need to publish Xcode frameworks from Kotlin for iOS developers, useful for teams testing KMP, needing modularization, or publishing SDKs.

Xcode Kotlin

The xcode-kotlin plugin allows you to debug Kotlin code running in an iOS application, directly from Xcode.

This provides a smoother development and integration experience for iOS developers using Kotlin shared code. In addition, it allows a more accessible experience for large teams, where not all members can directly edit the shared code.

TouchLab’s Xcode Kotlin integrates Kotlin into Xcode projects for iOS development, enhancing the experience of developers using Kotlin Multiplatform. It allows native integration of Kotlin code into Swift and Objective-C projects. Its main features are:

Features

Integration with Xcode

  • Direct support for Xcode: It enables the inclusion of Kotlin code in Xcode projects, improving interoperability with Swift and Objective-C.
  • Compatibility with Xcode tools: Ensures that Xcode tools, such as the debugger and compiler, work correctly with Kotlin.

Ease of configuration

  • Simplified configuration: It offers predefined scripts and configurations to integrate Kotlin into Xcode, minimizing complexity and potential errors.
  • Detailed documentation: Provides comprehensive guides for setting up and using Kotlin in iOS projects.

Automatic generation of bindings

  • Automatic bindings: Automatically creates the necessary bindings to access Kotlin code from Swift and Objective-C, avoiding the manual writing of bridge code.

Improvement of the developer experience

  • Simplified workflow: By automating the integration of Kotlin into Xcode.

KMM Plugin

The KMM Plugin is an essential tool for developers using Kotlin Multiplatform in Android Studio. This plugin offers complete integration with Android Studio, thus making the creation, compilation, and debugging of KMP projects easier.

With the KMM Plugin, developers can easily create Kotlin Multiplatform projects and access all the features of Kotlin Multiplatform directly from Android Studio. This includes the ability to define shared modules, manage dependencies, and perform unit tests on shared code, all within the familiar Android Studio development environment.

Plugin Features

Integration with Android Studio

  • Integrates with Android Studio providing tools for cross-platform development.
  • Facilitates the creation of KMP projects with automatic wizards.

Advanced Development Tools

  • Offers autocomplete and refactoring tools.
  • Provides advanced navigation and code search.

Debugging and Testing

  • Supports Kotlin code debugging on Android and iOS.
  • Facilitates unit and integration testing for shared code.

Performance Optimization

  • Optimizes compilation for cross-platform projects.
  • Applications with KMM Plugin maintain performance close to native.

Developer Experience

  • Automates repetitive tasks of cross-platform development.
  • Provides clear and detailed error messages.

The KMM Plugin from JetBrains is an essential tool for Kotlin Multiplatform developers seeking seamless integration between Android and iOS. With features that simplify project setup and significantly improve developer experience, this plugin allows creating cross-platform applications, taking full advantage of Android Studio and Kotlin capabilities.

Kotlin Multiplatform Wizard

Kotlin Multiplatform Wizard is a tool from JetBrains designed to simplify the creation of new Kotlin Multiplatform projects. It has an intuitive user interface that guides developers through the initial project setup.

Features

  • Helps to set up the structure and dependencies of new Kotlin Multiplatform projects.
  • Allows selecting the platforms (JVM, JS, Android, iOS, etc.) for the project.
  • Kotlin Multiplatform Wizard generates the base code, including configuration and sample code, saving time.

Kotlin Multiplatform Wizard is an excellent tool for any developer looking for a quick and easy way to start with Kotlin Multiplatform. With its focus on ease of use and customization, it facilitates the creation of new projects, allowing developers to focus on what really matters: writing high-quality code.

In addition, on the website you will find a gallery of other templates with different configurations. For example, you will find one based on Amper that we will see later.

Dokka: Generating Clear and Concise Documentation

Documentation is essential in any software development project. Dokka is a documentation generation tool specifically designed for Kotlin projects, including Kotlin Multiplatform.

Dokka analyzes the source code and generates clear and concise documentation in HTML, Markdown, or Javadoc formats. This documentation describes the public API of a Kotlin Multiplatform project, making it easier for developers to understand how to use the different parts of the shared code. In addition, it promotes good development practices by making the documentation easily accessible for the entire team.

Dokka Features

Automatic Documentation Generation

  • Automatically generates documentation from KDoc comments in Kotlin source code.
  • Supports Kotlin Multiplatform projects, including modules for JVM, JS and Native.

Flexible Configuration

  • Integrates with Gradle, allowing documentation generation to be configured from build.gradle.
  • Offers advanced configurations to customize the format and content of the documentation.

Output in Multiple Formats

  • Generates documentation in several formats, including HTML and Markdown.
  • Can generate documentation in a format similar to Javadoc.

Integration with Build Tools

  • Compatible with integration and continuous delivery (CI/CD) systems.
  • Integrates with IntelliJ IDEA and other JetBrains-based IDEs.

Documentation Enrichment

  • Allows the inclusion of images, links and other external resources in the documentation.
  • Can include code examples and snippets in the documentation.

Optimization of the Developer Experience

  • Generates documentation with a clear and easy-to-navigate structure.
  • Supports the inclusion of annotations and comments in the documentation.

Dokka, essential for Kotlin developers, supports clear and up-to-date documentation of projects, including Kotlin Multiplatform. It facilitates the generation of documentation, supports various formats and integrates with build tools and CI/CD, improving the quality and accessibility of code documentation. This benefits the understanding and maintenance of projects, for individual developers and teams.

DeteKt: Code Quality Improvement

Code quality is essential for the maintainability and scalability of any software project. DeteKt is a static code analysis tool designed to identify and correct common quality problems in Kotlin projects.

With DeteKt, developers can automatically analyze their Kotlin Multiplatform code for errors, redundancies, incorrect naming conventions, and other potential problems. This helps ensure that shared code is clean, consistent, and easy to maintain over time.

DeteKt Features

Static Code Analysis

  • Code Problem Detection: Analyzes source code to identify common issues such as style errors, potential failures, and complexity problems. This helps improve code quality.
  • Code Quality Report: Generates detailed reports highlighting areas of the code that require attention, thus facilitating the identification and correction of problems.

Support for Kotlin Multiplatform

  • Multiple Target Analysis: It is compatible with Kotlin Multiplatform projects and allows analysis of shared and platform-specific code (JVM, JS, Native).
  • Code Consistency: Ensures that code quality rules are consistently applied across different platforms, maintaining a uniform standard.

Flexible and Customizable Configuration

  • Gradle Plugin: Easily integrates with Gradle, allowing code analysis to be configured and run as part of the build process.
  • Customizable Rules: Provides a wide range of predefined rules and allows developers to define custom rules to suit the specific standards of their project.

Integration with Development Tools

  • CI/CD Integration: It is compatible with continuous integration and delivery (CI/CD) systems, which facilitates the incorporation of static analysis into the development pipeline.
  • IDE Compatibility: Works well with IntelliJ IDEA and Android Studio, allowing developers to view and correct code quality problems directly in their development environment.

Detailed and Actionable Reports

  • Various Report Formats: Generates reports in various formats, such as HTML, XML, and plain text, which facilitates their integration with other tools and systems.
  • Link to Source Code: Provides direct links to the lines of code that have problems, making it easier to review and correct them.

Continuous Code Improvement

  • Best Practice Rules: Includes rules based on Kotlin development best practices, helping developers write cleaner and more maintainable code.
  • Code Smell Detection: Identifies code smells like long classes, complex methods, and code duplication, promoting healthier software design.

Extensibility

  • Plugins and Extensions: Allows the creation of plugins and extensions to add additional functionality or adapt DeteKt to the specific needs of the project.
  • Exception Configuration: Offers options for configuring exceptions and exclusions, allowing the analysis to be tailored to the specific contexts of the project.

DeteKt is a powerful and essential tool for Kotlin developers looking to maintain high-quality, clean, and error-free code. With features that facilitate the static analysis of Kotlin Multiplatform projects, ensure code consistency, and allow smooth integration with development tools and CI/CD, DeteKt significantly improves code quality and team productivity. This tool allows developers to proactively detect and correct problems, promoting best practices and healthier software design.

Kover

Kover is a code coverage tool for Kotlin, developed by JetBrains. It focuses on measuring and reporting test coverage in Kotlin projects, including those using Kotlin Multiplatform. Below are its main features oriented towards Kotlin Multiplatform:

Features

  • Evaluates test coverage and is compatible with Kotlin Multiplatform projects.
  • Integrates with Gradle and offers intuitive configuration in build.gradle.
  • Generates reports in various formats and provides detailed visual reports.
  • Compatible with CI/CD systems and allows automatic generation of coverage reports.
  • Measures code coverage in a Kotlin Multiplatform project and provides unified reports.
  • Helps identify untested parts of the code and promotes good practices in test writing.

Kover is an indispensable tool for Kotlin developers who want to measure and improve test coverage in their projects, including those using Kotlin Multiplatform. It offers features that facilitate integration with Gradle, provides detailed and visual reports, and ensures compatibility with CI/CD systems. Kover significantly improves code quality by helping developers identify areas that have not been tested and promoting the creation of more tests. This tool maintains a high standard of test coverage, ensuring that the code is well tested and more resilient.

Fleet

Fleet is an integrated development environment (IDE) created by JetBrains. It has been designed to be lightweight, fast, and versatile. Its aim is to provide a modern and efficient programming experience, being especially relevant for Kotlin Multiplatform. This technology allows sharing code between various platforms (iOS, Android, Web, etc.) using Kotlin.

Fleet Features

  • It has a clean design and a zen mode for a distraction-free writing experience.
  • Supports Kotlin Multiplatform projects and offers simplified configuration.
  • It starts quickly and is efficient even in large projects.
  • Allows real-time collaboration and instant synchronization.
  • Offers advanced autocompletion, refactoring tools, and improved navigation.
  • Has an integrated debugger and supports multiplatform testing.
  • Allows plugins and extensions and offers an API for customization.
  • Supports VCS and integrates with CI/CD tools.
  • Offers customization options and configuration profiles.

Fleet represents a modern and efficient approach to software development, particularly in the context of Kotlin Multiplatform. With its minimalist interface, optimized performance, and advanced collaboration and editing capabilities, Fleet positions itself as a powerful tool for developers seeking a smooth and productive development experience.

Amper

Amper is a build system developed by JetBrains, specifically designed for the Kotlin ecosystem, including Kotlin Multiplatform projects. Below, its main features focused on Kotlin Multiplatform are described.

Amper Features

Process Optimization

  • Build Efficiency: Optimizes the construction process by reducing compilation times and improving the overall workflow efficiency.
  • Incremental Compilation: Supports incremental compilation, where only recent changes in the source code are recompiled, speeding up the build process.

Support for Kotlin Multiplatform

  • Multiplatform Compatibility: It is designed to handle Kotlin Multiplatform projects, allowing the construction of common and platform-specific modules (JVM, JS, Native) efficiently.
  • Simplified Configuration: Provides simplified configuration for multiplatform projects, making it easier to manage and maintain build configurations.

Dependency Management

  • Efficient Dependency Handling: Provides an advanced system for dependency management, ensuring that all necessary libraries and frameworks are correctly integrated and updated.
  • Conflict Resolution: Automatically handles dependency conflicts, facilitating the integration of multiple libraries and components into a project.

Task Automation

  • Customizable Build Tasks: Allows the creation and configuration of customizable build tasks, adapting to the specific requirements of each project.
  • Support for Common Tasks: Includes support for common tasks such as compilation, packaging, test execution, and documentation generation, facilitating the development workflow.

Amper is an advanced and efficient build system developed by JetBrains, ideal for Kotlin projects, including Kotlin Multiplatform. Its features optimize the construction process, facilitate dependency management, and provide seamless integration with JetBrains tools and ecosystems. In this way, Amper significantly improves the efficiency and productivity of the development workflow. This tool allows developers to manage complex projects more effectively, ensuring fast, reliable, and well-integrated builds in the development environment.

Conclusion

In summary, this article provides a comprehensive overview of the various tools and technologies available for efficient application development using Kotlin Multiplatform. From SKIE and KMMBridge to facilitate integration with Xcode, to Dokka and DeteKt for enhancing code quality and documentation. The importance of analysis tools and code coverage tools like DeteKt and Kover, and IDEs and build systems like Fleet and Amper are also highlighted. Each tool has a specific purpose, but all work together to provide a smooth and efficient development experience on Kotlin Multiplatform. Through this article, developers can gain a deeper understanding of these tools and how they can enhance their application development process.

References

--

--