Kotlin/Native — what is it, native code compiler and features

Author: IT Sectr Published: 2026-06-05 Reading time: 8 min

Kotlin/Native is a compiler that translates Kotlin code directly into native machine code, running without a virtual machine. Unlike the JVM version, Kotlin/Native uses an LLVM backend to generate executable files for iOS, Android NDK, macOS, Windows, Linux, and WebAssembly. The technology is the foundation of Kotlin Multiplatform and enables shared code execution on platforms where JVM is not available. According to JetBrains, 2025, Kotlin/Native supports 13 target platforms and allows reusing up to 90% of code in KMM projects.

Key Takeaways

  • Kotlin/Native is a compiler that translates Kotlin code into native machine code without using JVM.
  • LLVM is the compiler backend responsible for generating machine code for each target platform.
  • KMM — Kotlin Multiplatform Mobile uses Kotlin/Native to execute shared code on iOS devices.
  • Memory Manager is an automatic garbage collector based on reference counting without thread suspension.
  • Interop is a mechanism for bidirectional interaction with native Objective-C, Swift and C libraries.

What is Kotlin/Native?

Kotlin/Native is a technology for compiling Kotlin code into native machine code, developed by JetBrains. The main difference from Kotlin/JVM is the absence of need for a virtual machine — the resulting executable file contains only machine code and a minimal runtime. This allows running Kotlin applications on devices and systems where JVM is not supported, including iPhone, Apple Watch, and embedded systems.

The history of Kotlin/Native began with a project — an experimental compiler that was integrated into the main Kotlin branch in 2017. In 2019, at KotlinConf, support for iOS as a target platform was announced, which became a turning point for mobile development. Since Kotlin 1.9.20, the Kotlin/Native compiler has achieved stability and is included in Kotlin Multiplatform by default.

The key feature of Kotlin/Native is the use of a common intermediate representation IR, which is compiled into machine code for each platform separately. This provides a unified compilation frontend for all Kotlin backends: JVM, JS, and Native.

How the Kotlin/Native Compiler Works

Compilation in Kotlin/Native goes through several transformation stages. The Kotlin source code is first converted into an internal representation, then optimized and passed to the LLVM backend for machine code generation. The final stage is linking with runtime libraries and creating an executable file or dynamic library.

The architecture includes three key components: frontend (parsing and type checking), IR generator (building intermediate representation), and LLVM backend (machine code generation). This scheme is similar to the approach used in Clang compilers for C++ and Rust.

kotlin
// Kotlin/Native compilation via command line
kotlinc-native hello.kt -o hello -opt

// Build for iOS arm64 via Kotlin Multiplatform
./gradlew :shared:linkDebugFrameworkIosArm64

For memory management, Kotlin/Native uses its own Memory Manager, based on reference counting with a cycle detector. Since Kotlin 1.7.20, the new memory manager works by default and does not require @ThreadLocal or @SharedImmutable annotations. The garbage collector operates without suspending threads, which is critical for iOS, where the system can forcibly terminate an application during prolonged blocking of the main thread.

Stages of Kotlin/Native Compilation

The compilation process is divided into five stages: parsing (source code analysis), semantic analysis (type checking and name resolution), IR generation (building intermediate representation), optimization (simplification and dead code elimination), and code generation via LLVM. Each stage can be executed in parallel for different modules, which speeds up the build of large projects.

StageDurationResult
Parsing~10% of timeAST tree of source code
Semantic Analysis~20% of timeTyped AST
IR Generation~15% of timeKotlin IR (Intermediate Representation)
Optimization~25% of timeOptimized IR
LLVM Code Generation~30% of timeMachine code + executable file

Supported Kotlin/Native Platforms

Kotlin/Native supports 13 target platforms, divided into categories. For mobile development, iOS (arm64), Android (arm32, arm64, x86_64), and watchOS are available. Desktop platforms include macOS (x64, arm64), Windows (mingw x64), and Linux (x64, arm64, arm32). For server and embedded development, WebAssembly and Kotlin/Native on LLVM without OS (standalone) are available. Each platform requires a separate framework or library as output.

Platforms for Mobile Development

For iOS, Kotlin/Native generates a universal framework (.framework) that can be connected to an Xcode project. For Android NDK, native .so libraries are created that can be called via JNI. watchOS is supported since Kotlin 1.6.0, and tvOS since version 1.7.0. Each architecture requires a separate build, but Kotlin Multiplatform automates this process through the Gradle plugin.

Desktop and Server Platforms

macOS and Linux are used for developing native desktop applications in Kotlin using the Compose Multiplatform framework. Windows (MinGW) has been supported since Kotlin 1.3.70 and allows creating Windows applications without installing JVM. For server development, Kotlin/Native can be used in environments where JVM is not available, such as Docker containers with a minimal image based on scratch or Alpine.

CategoryPlatformArchitecture
MobileiOSarm64, simulator (x64, arm64)
MobileAndroid NDKarm32, arm64, x86, x86_64
WearablewatchOSarm64, simulator (x64)
DesktopmacOSx64, arm64
DesktopWindowsmingw x64
DesktopLinuxx64, arm64, arm32

Kotlin/Native for iOS Development

iOS is the primary target platform for Kotlin/Native in the context of KMM. The compiler creates an iOS framework containing all shared code, which is then connected to an Xcode project. The framework supports both static and dynamic linking. Kotlin/Native generates Objective-C wrappers for Kotlin classes and functions, providing direct integration with Swift and Objective-C code.

Integration with iOS requires configuring Xcode to connect the generated framework. Kotlin Multiplatform automates this process using the embedAndSignAppleFrameworkForXcode task, which is invoked from Xcode Build Phases. For debugging, Kotlin/Native supports breakpoints in shared module code when running the application on the iOS simulator.

kotlin
// Kotlin code compiled into iOS framework
package com.itsectr.shared

class GreetingProvider {
    fun createGreeting(): String {
        return "Hello from Kotlin/Native!"
    }

    fun formatVersion(major: Int, minor: Int): String {
        return "v$major.$minor"
    }
}

Objective-C and Swift Interop

Interop with iOS code works in both directions. Kotlin/Native generates Objective-C headers for Kotlin classes, which automatically become accessible from Swift. Reverse communication is provided using the @ObjCName annotation for exporting Kotlin functions under a specified Objective-C name. Kotlin collections are automatically converted to NSArray and NSDictionary, and Kotlin coroutines are wrapped into Combine publishers via the SKIE library. For working with iOS frameworks from Kotlin, cinterop is used — a tool for generating Kotlin bindings to Objective-C headers.

Code Examples: Setup and Compilation

To get started with Kotlin/Native, you need to configure build.gradle.kts with the Kotlin Multiplatform plugin and target platforms. Let's look at a minimal configuration for a KMM project with iOS and Android support.

kotlin
plugins {
    kotlin("multiplatform") version "2.0.21"
}

kotlin {
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        commonMain.dependencies {
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
        }
        iosMain.dependencies {
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
        }
    }
}

After setting up the build, you can add platform-specific code. Kotlin/Native provides access to iOS functions through Kotlin wrappers. For example, getting the device UUID on iOS requires calling NSUUID from Foundation.

kotlin
import platform.Foundation.NSUUID

fun getDeviceId(): String {
    return NSUUID().UUIDString()
}

fun currentTimestampMillis(): Long {
    return (platform.Foundation.NSDate().timeIntervalSince1970 * 1000).toLong()
}

Building an iOS Framework

To generate an iOS framework, the Gradle task linkDebugFrameworkIosArm64 or linkReleaseFrameworkIosArm64 for production is used. After the build, the framework is located in build/bin/iosArm64/debugFramework/. Connecting to an Xcode project is done via Pods Podfile or by adding the framework in General → Frameworks, Libraries and Embedded Content.

kotlin
// Build release framework for iOS arm64
./gradlew :shared:linkReleaseFrameworkIosArm64

// Build universal framework x86_64 + arm64
./gradlew :shared:linkReleaseFrameworkIosX64 \
    :shared:linkReleaseFrameworkIosArm64

// Create XCFramework for App Store
./gradlew :shared:assembleReleaseXCFramework

Kotlin/Native vs Kotlin/JVM: Comparison

Kotlin/Native and Kotlin/JVM differ in architecture, performance, and scope of application. Kotlin/JVM compiles code into bytecode executed on the JVM, which provides access to a vast ecosystem of Java libraries but requires an installed virtual machine. Kotlin/Native generates an executable file with no external dependencies, but with a more limited library ecosystem.

Startup time performance is higher for Kotlin/Native since no JVM loading is required. According to JetBrains benchmarks, a Hello World application on Kotlin/Native starts in 0.003 seconds, while Kotlin/JVM requires 0.5–1 second to load the virtual machine. However, the executable file size of Kotlin/Native can be 2–3 times larger due to the included runtime.

CharacteristicKotlin/NativeKotlin/JVM
Target PlatformsiOS, macOS, Windows, Linux, WebAssembly, embeddedServers, Android, Desktop (JVM)
DependenciesNo runtime (self-contained)Requires JVM (JDK/JRE)
Startup Time~3 ms~500–1000 ms
EcosystemLimited (Kotlin + Interop)Full (Kotlin + Java + Android SDK)
Binary Size~1–5 MB (with runtime)~100–500 KB (JAR)

The choice between Kotlin/Native and Kotlin/JVM depends on the target platform. If the project targets iOS or requires minimal resource consumption, Kotlin/Native is the only option. For Android development, Kotlin/JVM remains the standard, although Kotlin/Native is used for NDK components where native performance is needed. In multiplatform projects, Kotlin Multiplatform combines both approaches: shared code is compiled via Kotlin/Native for iOS and via Kotlin/JVM for Android.

Frequently Asked Questions

How does Kotlin/Native differ from Kotlin/JVM?

Kotlin/Native compiles code into native machine code without a virtual machine, while Kotlin/JVM compiles into bytecode requiring an installed JVM. Kotlin/Native is used for iOS, embedded systems, and WebAssembly, while Kotlin/JVM is used for Android and servers.

Can Kotlin/Native be used without KMM?

Yes, Kotlin/Native can be used as a standalone compiler for creating console applications, native plugins, or libraries for any supported platform. KMM merely simplifies the organization of multiplatform code.

How does Kotlin/Native handle memory on iOS?

The Memory Manager of Kotlin/Native uses reference counting with an automatic cycle detector. Since Kotlin 1.7.20, the garbage collector does not require @ThreadLocal annotations and operates without suspending the main iOS thread.

Which iOS libraries are accessible from Kotlin/Native?

Through cinterop, all iOS frameworks are accessible: Foundation, UIKit, CoreData, CoreBluetooth, MapKit, and hundreds of others. JetBrains provides ready-made bindings for standard iOS libraries as part of Kotlin/Native.

How to debug Kotlin/Native code on iOS?

Debugging is done using Xcode with the connected Kotlin/Native framework. Breakpoints in Kotlin code work when running on the iOS simulator. For a device, a Debug build and an Apple developer profile are required.

Summary

  • Kotlin/Native is a Kotlin-to-native code compiler, the foundation of Kotlin Multiplatform Mobile.
  • LLVM backend provides machine code generation for 13 target platforms, including iOS, Android NDK, macOS, and Windows.
  • Memory Manager with reference counting operates without suspending threads, which is critical for mobile platforms.
  • iOS framework is generated automatically and connected to an Xcode project via embedAndSignAppleFrameworkForXcode.
  • Objective-C and Swift Interop provide bidirectional integration with native iOS code through cinterop and @ObjCName.
  • Startup performance of Kotlin/Native is significantly higher than the JVM version — up to 0.003 seconds instead of 0.5–1 second.
  • Use Kotlin/Native for iOS, embedded systems, and WebAssembly where JVM is unavailable or undesirable.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also