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

    Distractic

    06/21/2025, 7:01 AM
    Hello Is there a way to compile my app for linux including the native libraries? I would like to deploy my app on a distroless image, so there is no curl, etc.
    l
    • 2
    • 1
  • s

    Skolson5903

    06/22/2025, 7:25 PM
    I have a very small C wrapper for the linux system (Ubuntu is the build system) call getrandom, The C code looks like this:
    Copy code
    #include "getrandom_wrapper.h"
    
    ssize_t call_getrandom(void *buf, size_t buflen, unsigned int flags) {
        return getrandom(buf, buflen, flags);
    }
    and the header is this:
    Copy code
    #include <sys/random.h>
    
    // Wrapper function to call getrandom()
    ssize_t wrapper_getrandom(void *buf, size_t buflen, unsigned int flags);
    This compiles and links fine using gcc and produces a small static library. The .def file looks like this:
    Copy code
    headers = getrandom_wrapper.h
    package = com.oldguy.crypto
    linkerOpts = -L.,/usr/include/x86_64-linux-gnu/ -lgetrandom_wrapper
    The gradle setup for linuxX64 cinterop is this:
    Copy code
    compilations.getByName("main") {
                val path = "${project.rootDir}/KmpCrypto/src/linuxMain/cinterop"
                cinterops {
                    val myLibraryCinterop by creating {
                        defFile(project.file("$path/getrandom_wrapper.def"))
                        includeDirs(path, "/usr/include/x86_64-linux-gnu") // Ubuntu location of sys/random.h
                    }
                }
            }
    At cinterop (gradle sync) time, this error pops:
    Copy code
    /usr/include/x86_64-linux-gnu/sys/cdefs.h:153:34: error: function-like macro '__glibc_clang_prereq' is not defined
    Has anyone else seen this and knows what causes it? This macro should be defined by the sys/features.h that gets pulled in by sys/random.h. The code snippet from features.h that isn't working looks like this:
    Copy code
    /* Similarly for clang.  Features added to GCC after version 4.2 may
       or may not also be available in clang, and clang's definitions of
       __GNUC(_MINOR)__ are fixed at 4 and 2 respectively.  Not all such
       features can be queried via __has_extension/__has_feature.  */
    #if defined __clang_major__ && defined __clang_minor__
    # define __glibc_clang_prereq(maj, min) \
      ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
    #else
    # define __glibc_clang_prereq(maj, min) 0
    #endif
    Thanks in advance for any ideas on how to diagnose/fix this.
    a
    • 2
    • 5
  • r

    rkechols

    06/23/2025, 2:51 AM
    I have a KMP shared module/lib being compiled to an Apple native "Framework", and I seem to have discovered that the framework's min OS version is being set higher than I'd like. I can't seem to find docs on how to customize the min OS version (specifically for macOS) in the shared lib's KMP Gradle config. Could anyone point me in the right direction for finding that?
    s
    • 2
    • 13
  • j

    Jimmy Nelle

    06/25/2025, 1:58 PM
    https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1750837326292969 Someone has an idea how to fix this on latest macos beta?
  • s

    Skolson5903

    06/28/2025, 12:03 AM
    I'm trying to use libxml2 in a linuxX64 target and think I'm getting burned by the age of the konan gcc stack again. With libxml2, after getting all the required libraries into the def file linkerOpts.linux clause, trying to run a unit test causes this linker error:
    ld.lld: error: undefined symbol: fcntl64
    I think
    fcntl
    was renamed to
    fcntl64
    in glibc 2.28, and I'm afraid this is newer than the native konan stack is handling. I tried this line in the .def:
    Copy code
    linkerOpts.linux = --allow-shlib-undefined -L/usr/lib/x86_64-linux-gnu -licui18n -licuuc -licudata -lz -llzma -lpthread
    hoping that the --allow option would tell the linker to ignore the missing symbol, but no help. Libxml2 required all those other libs. Has anyone seen this issue with the fcntl64 undefined symbol and have a fix/workaround?
    • 1
    • 3
  • c

    CLOVIS

    06/29/2025, 6:18 PM
    I seem to recall an announcement sometime ago (possibly a year) that it was now possible to compile any target using a Linux machine, but I can't find it mentioned in the documentation. Does someone have a link to the announcement?
    e
    • 2
    • 3
  • h

    Hamid

    06/30/2025, 1:35 PM
    I have this issue with function overloading in Kable (BLE library for kmp) that it crashes on iOS when calling LogMessage.detail() function. It actually picks the wrong function. These are the functions
    Copy code
    internal fun LogMessage.detail(data: NSData?, operation: Operation) {
        detail(data?.toByteArray(), operation)
    }
    
    internal fun LogMessage.detail(error: NSError?) {
        if (error != null) detail("error", error.toString())
    }
    
    internal fun LogMessage.detail(service: CBService? = null) {
        detail("service", service?.UUID?.UUIDString ?: "Unknown UUID")
    }
    
    internal fun LogMessage.detail(characteristic: CBCharacteristic) {
        val serviceUuid = characteristic.service
            ?.UUID
            ?.toUuid()
        if (serviceUuid == null) {
            detail("service", "Unknown (null value)")
            return
        }
    
        detail(serviceUuid, characteristic.UUID.toUuid())
    }
    
    internal fun LogMessage.detail(descriptor: CBDescriptor) {
        val characteristic = descriptor.characteristic
        if (characteristic == null) {
            detail("characteristic", "Unknown (null value)")
            return
        }
    
        val serviceUuid = characteristic.service
            ?.UUID
            ?.toUuid()
    
        if (serviceUuid == null) {
            detail("service", "Unknown (null value)")
            return
        }
    
        detail(
            serviceUuid,
            characteristic.UUID.toUuid(),
            descriptor.UUID.toUuid(),
        )
    }
    and this is the error I got.
    Copy code
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CBDescriptor service]: unrecognized selector sent to instance 0x1086a94d0'
    *** First throw call stack:
    (0x193fff21c 0x191499abc 0x194069614 0x193f13a1c 0x193f13aa0 0x10dddacf0 0x10ddd1a98 0x10ddd4538 0x1bd7cad94 0x1bd7caec4 0x1bd7c7a18 0x1bd786a40 0x1bd78422c 0x1bd784114 0x1034a8584 0x1034c2064 0x1034b091c 0x1034b15d8 0x1034b0758 0x1034b15a4 0x1034bd894 0x1034bceb0 0x21e5f4a0c 0x21e5f4aac)
    libc++abi: terminating due to uncaught exception of type NSException
    and I also attached the XCode error. Anyone has any idea how to fix it? please let me know if more information is needed. Thread in Slack Conversation
  • u

    אליהו הדס

    07/01/2025, 2:33 AM
    https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1751337142181969
    j
    • 2
    • 4
  • v

    Vaibhav Jaiswal

    07/01/2025, 11:19 AM
    Hi everyone, I am trying to migrate from Cocoapods to SPM Is there any way to add ios libraries to a KMP module via SPM, as of now i have added them as pod dependencies using the
    kotlin.native.cocoapods
    plugin and by using this
    Copy code
    pod("...") { ..... }
    f
    • 2
    • 4
  • m

    Mats-Hjalmar

    07/02/2025, 8:02 AM
    Hello all, i am having an issue. i get this when building for iPad Pro os: 15.1
    Copy code
    dyld[4166]: Symbol not found: __ZTINSt3__117bad_function_callE
      Referenced from:
    /private/var/containers/Bundle/Application/[my app].debug.dylib
      Expected in: /usr/lib/libc++.1.dylib
    It was working before then i upgraded a few libraries. My current versions:
    Copy code
    kotlin = "2.2.0"
    agp = "8.5.2"
    compose = "1.8.2"
    composeCompiler = "1.5.15"
    However, when i build the app for iPhone XS it works. And if i revert to these versions
    Copy code
    kotlin = "2.0.20"
    agp = "8.5.0"
    compose = "1.7.0"
    composeCompiler = "1.5.14"
    It works on both iPad and iPhone.
  • z

    zt

    07/04/2025, 4:01 AM
    how can I efficiently copy a Kotlin ByteArray into a pointer to the first byte of an array?
    e
    • 2
    • 3
  • z

    zt

    07/04/2025, 11:50 PM
    Uhh, so how do I debug this? why is the error message blank?
    b
    • 2
    • 1
  • 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
    • 78
  • 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