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

    Ian Botsford

    04/29/2025, 4:21 PM
    Hi everyone. I'm facing cinterop issues when cross-compiling
    linux_arm64
    on a
    linux_x64
    host. The cinterop task fails with
    UnsatisfiedLinkError
    looking for some newer version of glibc than exists on my host (full error in 🧵). I don't understand why it would be trying to use my host OS libs instead of the corresponding libs from the Konan distribution. 🤔 Anyone have experience debugging cinterops?
    e
    • 2
    • 5
  • l

    lauraldo

    05/02/2025, 2:31 PM
    Hi, I'm new in Kotlin/Native topic, but plan to use it more. I noticed that when I try to compile literally hello world kotlin program with
    kotlinc-native
    , the
    java
    process is launched. I tested it on
    linux_x64
    and
    macos_arm64
    targets. So does Kotlin/Native compiler use Java under the hood by default?
    j
    m
    +3
    • 6
    • 7
  • j

    Jaiden Siu

    05/07/2025, 12:41 AM
    Hey everyone, I've stumbled across a case where an enum entry is prepended with "new" when using K/N for Objective-C interop, and I'm curious to why that is happening. In my KMP commonMain source set, I've defined:
    Copy code
    enum class BananaAge {
        NEW_BANANA,
        OLD_BANANA
    }
    Which generates the following in the header file.
    Copy code
    @property (class, readonly) LibraryNameBananaAge *theNewContact __attribute__((swift_name("theNewBanana")));
    @property (class, readonly) LibraryNameBananaAge *oldBanana __attribute__((swift_name("oldBanana")));
    I get the same result in the header file when using the ObjCName annotation. Anyone have any ideas why or what is happening under the hood?
    l
    • 2
    • 2
  • r

    Raphael TEYSSANDIER

    05/07/2025, 3:11 PM
    Hello, I'm trying to add a
    lib.a
    to my project with
    cinterop
    . And I cannot make it work, is there any example on github to follow ?
    l
    • 2
    • 4
  • m

    Matt Nelson

    05/17/2025, 2:17 PM
    Anyone have a "simple" way for running android native tests on an emulator? I've got a kmp library and want to support android native, but to ensure things work properly, there is some minimal platform specific code that needs to be put under test on a device/emulator.
    j
    h
    • 3
    • 6
  • x

    XinzhengZhang

    05/19/2025, 5:28 PM
    Hello, I'm trying to separate the API and IMPL from Klib, so as to achieve more efficient incremental compilation (based on Bazel's own mechanism that if its input doesn't change, it won't rebuild itself, allowing modules to rely only on API for compile-only). I currently have several ideas, but they all seem not very elegant, and I hope to get some suggestions. 1. Implement a KCP plugin to replace all function bodies with "todo" (this will compile twice). 2. Modify the Klib compilation product to remove the IR directory (this seems very risky). Does KN itself have the ability similar to Bazel's java_library interface.jar, which can improve incremental changes?
  • j

    Jeffrey Bush

    05/20/2025, 2:56 AM
    I ran into a weird issue that took me a long time to figure out. Apparently, Objective-C fields can be specified
    weak
    , `unowned`/`unowned(safe)`, or
    unowned(unsafe)
    . However, these specifications are not propagated into Kotlin in any way which means you can easily end up with memory access errors randomly if you don't save instances of the fields to other variables that you have more control over. Is there any way support for these could be added to the wrappers created by
    cinterop
    and thus allow us to get warnings to greatly assist in tracking down these random and confusing issues?
    g
    • 2
    • 6
  • n

    Nitesh Singh

    05/20/2025, 12:23 PM
    hey there, interviewer asking question how i will give answer could you help me ? because i am give interview from 2 years i didn't clear to interview
    not kotlin but kotlin colored 5
    ❓ 6
  • x

    XinzhengZhang

    05/22/2025, 4:07 AM
    Is there any flag in
    konanc
    for incremental compilation of the compiler frontend (Kotlin Ir klib)? I saw
    -Xuse-fir-ic
    and
    -Xuse-fir-lt
    in
    konanc -X
    , which seem to be only effective for JVM and only for Maven compiler.
    • 1
    • 1
  • d

    dhia chemingui

    05/24/2025, 2:33 PM
    Hi I am thinking of wrapping filament in kmp project and share logic between Ios and android any suggestions filament: https://github.com/google/filament I dont know how to bind this or any thing just I need guidance
    a
    • 2
    • 3
  • l

    loke

    05/25/2025, 5:40 PM
    I'm using pthreads from Kotlin Native, and for the most part it works fine. I just call the functions in
    platform.posix
    . However, I'm trying to use
    pthread_cleanup_push
    and it doesn't seem to exist in this package. In fact, I can't see it anywhere. Is this a bug? Should I report it?
    a
    e
    • 3
    • 15
  • j

    jQrgen

    05/26/2025, 2:03 PM
    Hey, my team is completely lost on what could cause such an error when running
    ./gradlew iosSimulatorArm64Test
    Maybe there is some sub-dependency that is misaligned such as described here? https://kotlinlang.org/docs/whatsnew19.html#library-linkage-in-kotlin-native Logs:
    Copy code
    kotlin.native.internal.IrLinkageError: Function 'CanvasLayersComposeScene' can not be called: No function found for symbol 'androidx.compose.ui.scene/CanvasLayersComposeScene|CanvasLayersComposeScene(androidx.compose.ui.unit.Density;androidx.compose.ui.unit.LayoutDirection;androidx.compose.ui.unit.IntSize?;kotlin.coroutines.CoroutineContext;androidx.compose.ui.scene.ComposeSceneContext;kotlin.Function0<kotlin.Unit>){}[0]'
    kotlin.native.internal.IrLinkageError: Function 'CanvasLayersComposeScene' can not be called: No function found for symbol 'androidx.compose.ui.scene/CanvasLayersComposeScene|CanvasLayersComposeScene(androidx.compose.ui.unit.Density;androidx.compose.ui.unit.LayoutDirection;androidx.compose.ui.unit.IntSize?;kotlin.coroutines.CoroutineContext;androidx.compose.ui.scene.ComposeSceneContext;kotlin.Function0<kotlin.Unit>){}[0]'
    	at kotlin.Throwable#<init>(/opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:30)
    	at kotlin.Error#<init>(/opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:12)
    	at kotlin.native.internal.IrLinkageError#<init>(/opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:133)
    	at kotlin.native.internal#ThrowIrLinkageError(/opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:137)
    	at androidx.compose.ui.test.SkikoComposeUiTest.createUi#internal(/opt/buildAgent/work/8a20760945d0aeba/compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skikoMain.kt:221)
    	at androidx.compose.ui.test.SkikoComposeUiTest.SkikoComposeUiTest$withScene$$FUNCTION_REFERENCE_FOR$createUi$1.invoke#internal(/opt/buildAgent/work/8a20760945d0aeba/compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skikoMain.kt:194)
    	at kotlin.Function0#invoke(/Users/teamcity/.gradle/daemon/8.11.1/[K][Suspend]Functions:1)
    //...
    п
    p
    • 3
    • 8
  • m

    Mikolaj

    05/29/2025, 8:17 AM
    Are there kotlin bindings for libffi?
    l
    • 2
    • 10
  • s

    Stefan Oltmann

    06/04/2025, 4:36 AM
    This looks nice to me. Is there something like that in production ready state? https://github.com/zsqw123/kn-jvm
    b
    • 2
    • 2
  • h

    hugo

    06/04/2025, 3:25 PM
    I'm thinking of building a native cli app and I'm following the docs that say to clone https://github.com/Kotlin/kmp-native-wizard as a starter project. This doesn't use the kmp template that I'm used to with commonMain etc and I'm wondering if I can change to a structure that does? That would also give me the ability to run the app on the jvm if I don't want to compile it down to native code for some reason.
    j
    • 2
    • 10
  • r

    rkechols

    06/06/2025, 5:09 AM
    I'm trying to figure out how to set up dependencies for a KMP library. Supported targets are currently JVM and kotline/native (macOS). For the kotlin/native side, how would I add CoreMIDI as a dependency? I've heard mention of smp4Kmp but it doesn't look like CoreMIDI is actually in SwiftPM... I apologize that part of the problem is my ignorance of the Apple ecosystem.
  • s

    sergey.bogolepov

    06/09/2025, 9:24 AM
    Hey folks! A quick question: does anybody use Kotlin/Native Android NDK targets in production? If so, why?
    e
    m
    s
    • 4
    • 4
  • s

    Stefan Oltmann

    06/10/2025, 7:35 AM
    I'm looking for an example project with a custom c library interop on Windows. In my case it won't find the header file and I don't know what's wrong with my setup.
    ✅ 1
    m
    • 2
    • 3
  • a

    Adolfo Ochagavía

    06/13/2025, 1:55 AM
    What are the implications of the fact that native support on Windows is MinGW-based? Imagine I have a Kotlin library, compiled as a DLL. Can I use it from e.g., Python, which is compiled using the MSVC toolchain? I have a prototype and it seems to work, but I'm asking to be sure things won't accidentally explode depending on which functions are called.
    e
    • 2
    • 17
  • z

    zt

    06/16/2025, 11:39 AM
    Not really an issue I have, but I was wondering if someone using macOS could verify if my native cinterop file works for those systems. It does work on Linux It should generate bindings for libavutil libavcodec and libavformat from ffmpeg.
    Copy code
    headers = libavutil/avutil.h libavutil/pixfmt.h libavutil/pixdesc.h libavutil/dict.h libavutil/crc.h libavutil/hwcontext.h \
        libavutil/imgutils.h libavutil/rational.h libavutil/log.h libavcodec/avcodec.h libavformat/avformat.h
    headerFilter = libavutil/** libavcodec/** libavformat/**
    package = ffmpeg
    
    compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/ffmpeg
    linkerOpts.osx = -L/opt/local/lib -L/usr/local/opt/curl/lib -lavutil -lavcodec -lavformat
    linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -L/usr/lib -lavutil -lavcodec -lavformat
    
    nonStrictEnums = AVCRCId AVHWDeviceType
    
    ---
    
    struct AVDictionary {
        int count;
        AVDictionaryEntry *elems;
    };
    
    typedef void (*simple_log_callback_t)(void*, int, const char*, void*);
    
    static inline simple_log_callback_t av_log_default_callback2() {
        return (simple_log_callback_t)av_log_default_callback;
    }
    
    static inline void av_log_set_callback2(simple_log_callback_t callback) {
        av_log_set_callback((void (*)(void*, int, const char*, va_list))callback);
    }
  • 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
    • 1
  • 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.