https://kotlinlang.org logo
Join Slack
Powered by
# kotlin-native
  • f

    François

    07/05/2025, 9:18 AM
    hi, I’m looking for a way to override the default values of the compiler’s konan.properties inside the gradle configuration. I don’t want to modify the file
    • 1
    • 1
  • d

    Dan Kaser

    07/07/2025, 2:28 PM
    Hi, since we have bumped up kotlin to 2.2.0, iOS app hangs on simulator for any call Throwable.printStackTrace() while using up cpu to 100 % Any suggestions?
    plus1 1
    m
    • 2
    • 1
  • g

    Ghasem Shirdel

    07/07/2025, 6:09 PM
    Hello, I was checking the performance and memory leaks of the iOS app, and two things caught my attention. The first issue is a leak related to
    supportsMainMenu
    , which I naturally don’t use anywhere in the iOSApp code. Is this being used in the background by Compose? The second issue happens when the function
    stackTraceToString
    is called — a leak occurs. Libraries like Napier and other logging libraries use this function. Is this problem only present in debug mode? My Compose version is 1.8.1 and Kotlin version is 2.2.0. Thread in Slack Conversation
    👍 1
  • g

    Ghasem Shirdel

    07/07/2025, 6:09 PM
    Same issue
  • c

    cafonsomota

    07/10/2025, 4:55 PM
    hello all, I’ve just tested the
    smallBinary
    feature released on 2.2.20-Beta1 but I didn’t noticed any change on the frameworks size; I’ve tested both added on
    gradle.properties
    and on
    build.gradle.kts
    . Am I missing something? 🤔
    s
    • 2
    • 6
  • m

    Mikolaj

    07/15/2025, 1:13 PM
    Hello! How can I enforce recompilation of Klib artifact that is linked with a static library using 'staticLibraries' option in def file? I even tried to remove the .a file and my app still magically runs 🪄
    t
    • 2
    • 3
  • d

    Dmitriy Tarasevich

    07/18/2025, 2:28 AM
    👋 I have a very strange problem. After updating some ObjectiveC that i then consume in KM I get the following only in CI / CD on bitrise. If i ssh into the box and re run the task it runs and succeeds... also this all works locally...
    Copy code
    Exception in thread "main" java.lang.IllegalStateException: Unresolved classifier: platform/darwin/NSObjectProtocolMeta
    	at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.type(CirDeserializers.kt:655)
    	at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.clazz(CirDeserializers.kt:241)
    	at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreeClassDeserializer.invoke(CirTreeClassDeserializer.kt:32)
    	at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreePackageDeserializer.invoke(CirTreePackageDeserializer.kt:41)
    	at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreeModuleDeserializer.invoke(CirTreeModuleDeserializer.kt:32)
    	at org.jetbrains.kotlin.commonizer.tree.deserializer.RootCirTreeDeserializer.invoke(RootCirTreeDeserializer.kt:37)
    	at org.jetbrains.kotlin.commonizer.FacadeKt.deserializeTarget(facade.kt:38)
    	at org.jetbrains.kotlin.commonizer.FacadeKt.deserializeTarget(facade.kt:44)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueueKt.CommonizerQueue$lambda$1$lambda$0(CommonizerQueue.kt:22)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueue.deserializedTargets$lambda$1$lambda$0(CommonizerQueue.kt:56)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:408)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueue.commonize(CommonizerQueue.kt:106)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueue.enqueue$lambda$6(CommonizerQueue.kt:97)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:408)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueue.invokeTarget(CommonizerQueue.kt:90)
    	at org.jetbrains.kotlin.commonizer.CommonizerQueue.invokeAll(CommonizerQueue.kt:83)
    	at org.jetbrains.kotlin.commonizer.FacadeKt.runCommonization(facade.kt:32)
    	at org.jetbrains.kotlin.commonizer.konan.LibraryCommonizer.commonizeAndSaveResults(LibraryCommonizer.kt:51)
    	at org.jetbrains.kotlin.commonizer.konan.LibraryCommonizer.run(LibraryCommonizer.kt:30)
    	at org.jetbrains.kotlin.commonizer.cli.NativeKlibCommonize.execute(nativeTasks.kt:79)
    	at org.jetbrains.kotlin.commonizer.cli.CommonizerCLI.executeTasks(cli.kt:60)
    	at org.jetbrains.kotlin.commonizer.cli.CommonizerCLI.main(cli.kt:17)
    No idea where to go from here
    f
    • 2
    • 3
  • j

    Johannes Zottele

    07/18/2025, 3:07 PM
    I have two questions regarding
    Pinned
    objects in K/N. 1. If I pin an object using the
    pin()
    extension function and never
    unpin()
    it, will the garbage collector eventually collect it? I found a thread on this channel that suggests that a pinned object remains unchanged and is not moved or freed. However, I’ve written a test program that demonstrates that the callback passed to createCleaner is invoked for both the pinned value object and the Pinned -Object itself.
    Copy code
    @OptIn(ExperimentalNativeApi::class, ExperimentalForeignApi::class)
    private fun allocate(): Unit {
        // create a dummy resource and pin it (but never unpin)
        val dummy = Any()
        val pinned = dummy.pin()
    
        // setup clean-up callbacks for both, the pinned value and the pinned-object
        createCleaner(dummy) {
            println("Cleaning up dummy (${markNow()})")
        }
        createCleaner(pinned) {
            println("Cleaning up pinned (${markNow()})")
        }
    }
    
    @OptIn(NativeRuntimeApi::class)
    fun main() {
        allocate()
        // trigger garbage collection manually
        GC.collect()
        runBlocking {
            // wait 10 secs to see cleaner callbacks
            delay(10000)
        }
        println("Done. (${markNow()})")
    }
    This outputs
    Copy code
    Cleaning up pinned (ValueTimeMark(reading=15083))
    Cleaning up dummy (ValueTimeMark(reading=129458))
    Done. (ValueTimeMark(reading=10002954250))
    So, according to this, the garbage collector actually recognizes both objects, implying that they are being freed. Is that accurate, or are those callbacks triggered even though the underlying object memory remains valid? 2. Assuming pinned is getting collected by the GC, will it
    unpin()
    the dummy object automatically?
    n
    l
    • 3
    • 5
  • n

    Nikolay Kasyanov

    07/29/2025, 2:52 PM
    Hello folks, today I learned that
    @Volatile
    cannot be applied to local variables, which makes sense historically, but applies to JVM only, what about native?
  • w

    wwalkingg

    07/30/2025, 5:51 AM
    Hello, if I write screen recording code using Kotlin Native, how can I grant the program macOS recording permissions? I've tried adding IDEA, Gradle, and kexe to the authorization list, but none of them worked. The error message is "The user declined TCCs for application, window, display capture."
  • a

    altavir

    08/01/2025, 7:25 AM
    I am getting strange error on Kotlin 2.2.20 on Windows:
    .konan\dependencies\msys2-mingw-w64-x86_64-2\bin\ld.gold: error: cannot find -lunistring
    does anybody know how to fix it? For some reason it happens only on some projects.
    n
    • 2
    • 2
  • g

    Ghasem Shirdel

    08/04/2025, 6:31 AM
    https://youtrack.jetbrains.com/issue/CMP-8223/Kotlin-2.1.21.-After-the-app-is-launched-f[…]rowable.stackTraceToString-causes-the-CPU-to-spike-to-100 https://youtrack.jetbrains.com/issue/CMP-8523/IOS-memory-leak Any updates on this issue? Deploying to production without a proper stack trace makes debugging extremely difficult. Thread in Slack Conversation
  • v

    Vishal kumar singhvi

    08/05/2025, 8:37 AM
    Hi everyone, I'm currently working on implementing Picture-in-Picture (PiP) functionality for a video player in a Kotlin Multiplatform (KMP) project. Specifically, I'm looking to: • Enable PiP when the user presses the home button • Support automatic PiP activation • Maintain compatibility with iOS/Android through KMP If anyone has experience with this or can recommend any helpful articles, tutorials, or blog posts on implementing PiP in KMP, I would greatly appreciate your suggestions. for IOS I am looking android i have created Slack Conversation
  • d

    Didier Villevalois

    08/07/2025, 2:41 PM
    Hey! It seems that there is no
    kotlin-native-prebuilt-2.2.0-linux-aarch64.tar.gz
    on Maven Central... Is that expected? I encountered that while loading the MCP SDK to make some PRs. I run Fedora Linux (Asahi) on an M1 MBP. I will disable the native targets for now, but that's quite uncomfortable... 😭
    o
    • 2
    • 2
  • r

    Raed Ghazal

    08/08/2025, 1:17 PM
    Hey, is it fine to use kotlin 2.2.0 without updating gradle to 9.0.0? apparently bitrise doesn't support building projects with gradle 9 yet, and I tested without it and it works fine, but here its mentioned that minimum gradle is 9 for kotlin 2.2
    j
    • 2
    • 3
  • s

    Stefan Oltmann

    08/17/2025, 6:37 PM
    If you’re considering writing your first Kotlin library and thinking about making a logging library… just don’t. 😬 What the ecosystem really needs is a pure Kotlin SigV4 library (that also works for Kotlin/Native). We now have the kotlin-native-aws-lambda-runtime to write our AWS lambdas in Kotlin/Native, but to interact with DynamoDB we seem to need to use something called "_AWS Signature Version 4"_ which isn't available to Kotlin/Native as far as I can see.
    h
    c
    +4
    • 7
    • 84
  • a

    Adam S

    08/22/2025, 8:42 AM
    What does the
    -include-binary
    KN compiler arg actually do? Does it just tell the compiler to package the files into the
    my-lib.klib
    in the
    /my-lib/default/targets/${targetName}/included/
    dir? Context: I have two
    .a
    static library files ( 'debug' and 'release'). I can't see how my subproject
    my-app
    can only use the debug
    my-lib
    when running
    runMyAppDebugExecutableMacosArm64
    and the release
    my-lib
    when running
    runMyAppReleaseExecutableMacosArm64
    . I was thinking about making two variants of my library, one that produces a
    my-lib-release.klib
    and another that produces
    my-lib-debug.klib
    . The only difference being the included static libs. If I can build the
    .klib
    manually, and just update the included files, that'd be a solution (albeit complicated and something I'd prefer to avoid).
    e
    • 2
    • 3
  • l

    loke

    08/25/2025, 5:30 AM
    I have a multiplatform project where the JVM implementation embeds some datafiles (JSON files, in this particular case) as resources which I load using the classloader. I need to do the same in the native backend, but I can't find a good way to do it. Ideally, I'd want to just link it as an ELF object, but that doesn't actually seem possible. Is there some nice gradle way I can transform the content to a string that becomes accessible as a variable during runtime? Or is there some other solution? What I really don't want to do is to convert the (rather large, some 10's of MB) text file into a string and saving it as a
    .kt
    source file.
    a
    • 2
    • 5
  • t

    tylerwilson

    09/12/2025, 3:27 AM
    What is the current best practice for Kotlin 2.2 and iOS GC. I have these in my gradle.properties. Do we think any or all of these are still needed, or would actually makes things worse?
    Copy code
    kotlin.native.binary.objcDisposeOnMain = false
    kotlin.native.binary.mimallocUseCompaction = true
    kotlin.native.toolchain.enabled = false
    kotlin.incremental.native = true
    👀 1
  • i

    Ian Botsford

    09/15/2025, 4:03 PM
    I'm confused about how Platform Library implementations are linked by the compiler. kodee lost From the docs: > The packages from platform libraries are available by default. You don't need to specify additional link options to use them. The Kotlin/Native compiler automatically detects which platform libraries are accessed and links the necessary ones. That doesn't match my experience on Windows using platform.windows. When I import and use the bindings for some Win32 APIs, I get link errors when building my test binaries:
    ld.lld: error: undefined symbol: <name of symbol>
    . The problem goes away if I specify
    -lversion
    as a linker argument. The specific APIs are GetFileVersionInfoSizeW, GetFileVersionInfoW, and VerQueryValueW, all of which are declared in *winver.h*, which is included in *windows.h*, which is specified as one of the headers bound in the *platform.windows* DEF file. Why aren't the platform library implementations properly automatically linked by the compiler?
    • 1
    • 3
  • s

    Sergey Chelombitko

    09/15/2025, 8:35 PM
    Hey! Is there a way to prepend an include path before the sysroot path?
    Copy code
    kotlin {
        androidNativeArm64 {
            compilations.named("main") {
                cinterops.register("main") {
                    compilerOpts("-ID:/Apps/VulkanSDK/Include")
                }
            }
        }
    }
    I want to use the latest version of Vulkan headers from Vulkan SDK, but the headers from the sysroot path always get the priority:
    Copy code
    // This includes Vulkan 1.0 header from $HOME\.konan\dependencies\target-toolchain-2-windows-android_ndk/sysroot/usr/include\vulkan/vulkan.h
    #include <vulkan/vulkan.h>
    m
    • 2
    • 2
  • p

    Piotr Krzemiński

    09/20/2025, 7:29 AM
    I'd like to revive the efforts of compiling Kotlin to Python, but using a different approach than before (which was working on a fork of Kotlin monorepo). Instead, I'd like to work on klib - parse the IR stored there, and produce Python from it. This way I need to create a separate building block with well-defined API instead of fighting with the whole monorepo which is hard to work with. Does this idea make sense to you? For it to succeed, I need a library that can parse serialized IR from within the klib files - is there a library like this published somewhere? I don't mind unstable API, I just want to experiment 😁
    a
    y
    • 3
    • 4
  • u

    ursus

    09/20/2025, 12:53 PM
    If my ios project already uses SPM modules, and I want the SPM modules to depend on KMP code - is
    xcframework
    my only option?
  • u

    陈雄

    09/22/2025, 12:30 PM
    Does anyone know how to set "-fsanitize-coverage=func,trace-pc-guard" in build.gradle.kts for Kotlin/Native on iOS? Or how to configure the sanitizer?
  • o

    Omico

    09/24/2025, 3:09 AM
    Anyone can explain what does this commit do? And why? I’m unable to view KT-68583. https://github.com/JetBrains/kotlin/commit/1c025985ee822504b1891e5e18b5ad222b54e218
    g
    • 2
    • 4
  • h

    Huan

    10/06/2025, 2:14 PM
    hello, I am trying to reproduce a video using media3. The cell is inside a lazy column. I need that video continue playing when user scrolls and the cell is hidden. Currently i got that the video restarts, ¿Is possible that the video continue playing even if the composable is not visible and when it becomes visible just shows the current time where it was?
    c
    • 2
    • 2
  • l

    loke

    10/18/2025, 12:59 PM
    I note that
    memScoped
    uses
    nativeHeap
    , which eventually calls
    malloc
    for every allocation. I have a highly performance-intensive function where I need to allocate memory on the stack. Is there a way to get stack allocation instead?
    e
    a
    • 3
    • 3
  • l

    loke

    10/18/2025, 5:21 PM
    Is there a way to declare a function in Kotlin code which can be called from an inline C function in the cinterop definition file? I tried declaring it using
    @CName
    but when I link the code, I still get a symbol not found error.
  • v

    Vitaliy Zarubin

    10/24/2025, 8:49 AM
    Hello. Prompt why so can happen. Trying to compile a static library on macOS and Linux. The library that is compiled on Linux - works fine, but the library that is compiled on macOS does not work in Qt:
    Copy code
    undefined reference to `ac_path_info_get_app_cache'
    Here is the result of outputting nm on Linux:
    Copy code
    nm libdemo_kmp.a | grep ac_path_info_get_app_cache
    00000000000000 T ac_path_info_get_app_cache 
    U ac_path_info_get_app_cache
    
    nm -A libdemo_kmp.a | grep ac_path_info_get_app_cache
    libdemo_kmp.a:ac_path_info.ac_path_info.bb51b92a2c3716b4-cgu.0.rcgu.o:00000000000000 T ac_path_info_get_app_cache
    libdemo_kmp.a:libdemo_kmp.a.o: U ac_path_info_get_app_cache
    Here is the output of nm on macOS:
    Copy code
    nm libdemo_kmp.a | grep ac_path_info_get_app_cache 
    U ac_path_info_get_app_cache
    
    nm -A libdemo_kmp.a | grep ac_path_info_get_app_cache
    libdemo_kmp.a:/private/var/folders/v1/0hmt9k0s2rj_wfvb9kkm43rw0000gn/T/konan_temp8842548127760527663/libdemo_kmp.a.oac_path_info_get_app_cache
  • t

    tylerwilson

    10/28/2025, 3:39 AM
    With the latest Kotlin 2.2.21 I am getting an error when running gradle task 'commonizeCInterop'. It shows a weird call stack like so:
    Copy code
    Exception in thread "main" org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException: Protocol message tag had invalid wire type.
    	at org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:99)
    	at org.jetbrains.kotlin.protobuf.CodedInputStream.skipField(CodedInputStream.java:262)
    	at org.jetbrains.kotlin.protobuf.GeneratedMessageLite.parseUnknownField(GeneratedMessageLite.java:540)
    	at org.jetbrains.kotlin.protobuf.GeneratedMessageLite.access$100(GeneratedMessageLite.java:49)
    	at org.jetbrains.kotlin.protobuf.GeneratedMessageLite$ExtendableMessage.parseUnknownField(GeneratedMessageLite.java:246)
    	at org.jetbrains.kotlin.metadata.ProtoBuf$PackageFragment.<init>(ProtoBuf.java:28327)
    	at org.jetbrains.kotlin.metadata.ProtoBuf$PackageFragment.<init>(ProtoBuf.java:28285)
    	at org.jetbrains.kotlin.metadata.ProtoBuf$PackageFragment$1.parsePartialFrom(ProtoBuf.java:28407)
    If I put it back to Kotlin 2.2.20, it works fine. Known issue? I will check the release notes again, perhaps I missed something there.
    • 1
    • 1