https://kotlinlang.org logo
Join SlackCommunities
Powered by
# kotlin-native
  • n

    napperley

    03/07/2025, 12:37 AM
    In IntelliJ with the linuxArm64 target (using Kotlin 2.1.10) only variables are visible with code completion. This issue occurs with the platform.posix and platform.linux packages. By the way the same also occurs with the linuxX64 target. I was trying to get auto complete for the libgpiod library (a user space library that is officially part of the Linux kernel - https://web.git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git ).
    • 1
    • 1
  • k

    katokay

    03/07/2025, 4:24 AM
    I could use some help. I have a multiplatform library project that has github actions setup for running nativeTest, jvmTest each on the matrix of operating systems linux, windows, and macos. All pass with the exception of linux nativeTest and it fails to compile with the error
    Copy code
    file:///home/runner/work/kotlin-lmdb/kotlin-lmdb/src/nativeMain/kotlin/Env.kt:111:78 Argument type mismatch: actual type is 'kotlin.UShort', but 'kotlin.UInt' was expected.
    The project is located at https://github.com/CoreyKaylor/kotlin-lmdb and the failure I'm referring to is here. https://github.com/CoreyKaylor/kotlin-lmdb/actions/runs/13713581077 This seems like a possible bug with the compiler, or am I missing something?
    a
    • 2
    • 2
  • n

    napperley

    03/08/2025, 10:06 PM
    Kotlin classes aren't being generated for blank C Structs. Is this normal behaviour for K/N C interop? Below is the definition of the structs from the gpiod.h file:
    struct gpiod_chip;
    struct gpiod_line;
    struct gpiod_chip_iter;
    struct gpiod_line_iter;
    struct gpiod_line_bulk;
    a
    • 2
    • 6
  • s

    suresh

    03/09/2025, 10:41 PM
    Hello, I’ve noticed that whenever a new release is available, the Gradle plugin downloads the Kotlin/Native prebuilt, which is ~ 350MB, and then executes the
    commonizeNativeDistribution
    task. On my M1 machine, this task consistently takes over 10 minutes to complete. Any idea why it takes so long and are there any potential optimizations to improve its performance?
    • 1
    • 1
  • p

    Piasy

    03/12/2025, 10:08 AM
    Hi guys, could you please help me on this? thanks!
  • p

    Piasy

    03/13/2025, 1:23 AM
    Hey guys, following this tutorial https://kotlinlang.org/docs/native-dynamic-libraries.html , how can I generate symbol file for windows dynamic library? I believe I need such file to symbolicate crash in the future. I tried this:
    Copy code
    kotlin {
        targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
            binaries.all {
                freeCompilerArgs += "-Xadd-light-debug=enable"
            }
        }
    }
    from this tutorial https://kotlinlang.org/docs/native-ios-symbolication.html#producing-dsym-for-release-kotlin-binaries , but it doesn’t generate any new file.
  • n

    Nick

    03/14/2025, 1:48 AM
    i'm having trouble converting a skiko Bitmap to an NSImage. wondering if anyone has got this working. here's what i've tried; but it throws an NPE:
    Copy code
    val nsImage = bitmap.readPixels()?.let { pixels ->
        NSImage(data = pixels.usePinned {
            NSData.create(it.addressOf(0), pixels.size.convert())
        })
    }
    i've also only found this helper for NSData -> skiko Image. nothing for the other direction: https://github.com/JetBrains/skiko/blob/master/skiko/src/darwinMain/kotlin/org/jetbrains/skia/Image.darwin.kt
    j
    • 2
    • 2
  • d

    darkmoon_uk

    03/19/2025, 3:56 AM
    When setting up an IntelliJ Run Configuration for Gradle task
    runDebugExecutableMacos
    (given I've named my target
    macos
    ) Is there a way to pass arguments to that? I've tried a few forms but nothing's working! Args work on CLI but I need to be able to Debug with them.
    • 1
    • 1
  • n

    Nitesh Singh

    03/22/2025, 5:43 PM
    Copy code
    kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "2.0.21" }
        alias(libs.plugins.kapt)
        kapt(libs.hilt.compiler)
    
    hey There my kapt() is not working could help me where my mistek
    - Problem: In version catalog libs, version reference '2.0.21' doesn't exist. Reason: Plugin 'org.jetbrains.kotlin.kapt' references version '2.0.21' which doesn't exist. kapt(libs.hilt.compiler) this bundles is not importing
    y
    • 2
    • 1
  • w

    Waldemar Kornewald

    03/26/2025, 11:46 AM
    We have huge issues with the build times (now at 2:30 hours) because we have to build different SDKs from the same monorepo. These SDKs share the same underlying modules (i.e. shared APIs) and these shared APIs be compatible between those SDKs. However, publishing fully separate XCFrameworks leads to duplicate copies of the same shared APIs such that they become fully separate and incompatible duplicate APIs. That’s why we resort to workarounds like building different combinations of SDKs (A + B + C, A + B, A + C, B + C, A, B, C) each as a single combined XCFramework. Of course this blows up build times and we have to be careful which combinations are actually needed in practice. Now to my feature request: Would it be possible to build the whole repository into a set of multiple XCFrameworks (e.g. one XCFramework per Gradle/KMP module) which depend on each other in the same way as the Kotlin modules depend on each other? Then we could build every module exactly once and use just the necessary subset of those XCFrameworks in each app. If this is not an option for the Objective-C export, could you please at least consider doing this for the Swift export?
    p
    s
    • 3
    • 7
  • w

    Waldemar Kornewald

    03/26/2025, 11:57 AM
    Different topic: My bug report got closed but the reason doesn’t make sense to me and the issue is not limited to Swift: https://youtrack.jetbrains.com/issue/KT-75100 We get bitten by forgotten
    @Throws
    annotations every now and then. On
    suspend fun
    this is especially annoying because they already generate an Objective-C / Swift API which requires error handling, so even the iOS developers won’t notice that something is missing. Making the app crash for missing
    @Throws
    annotations is just bad behavior. Can Kotlin please be changed (at least for Swift export) to treat
    suspend fun
    as having
    @Throws(Throwable::class)
    by default (unless there’s an explicit annotation of course)? This is much better than hard-crashing by default.
    • 1
    • 2
  • k

    katokay

    03/26/2025, 2:52 PM
    I am in the process of preparing a multiplatform project to be published to maven for a Kotlin-centric API around LMDB key/value store located here. https://github.com/crowded-libs/kotlin-lmdb I am wondering if there is any creative ways to package the native libs directly with the klib? I've seen this issue that it's not currently supported here https://youtrack.jetbrains.com/issue/KT-24649 You can see my def file definition here that references the precompiled binaries matching the target name for supported targets. This is similar to how I needed to accomplish the same thing in .NET with nuget, however I don't see any options without the end-user being passed on this burden and ensuring the lib is in the path correctly before using. https://github.com/crowded-libs/kotlin-lmdb/blob/main/src/nativeInterop/cinterop/liblmdb.def Any help would be greatly appreciated. Thanks
    a
    m
    • 3
    • 6
  • m

    martmists

    03/30/2025, 11:20 AM
    How can I use functions like HidD_GetProductString in mingw sourcesets while compiling from Linux? They don't seem to be bundled with Kotlin Multiplatform.
    l
    • 2
    • 4
  • s

    Smoothie

    04/01/2025, 2:35 PM
    JsonUtilities and PlatformUtilities are KMP libraries, they can export to xcframework.
    Copy code
    commonMain.dependencies {
                implementation(libs.kotlinx.serialization.json)
                implementation(libs.kotlinx.coroutines.core)
                api(project(":JsonUtilities"))
                api(project(":PlatformUtilities"))
            }
    Is it possible in the xcframework exported by this project (the one using these two dependencies) to not embed them ? So the final xcframework would depend on these two xcframework ? my conf right now is this
    Copy code
    val xcf = XCFramework("MyLibrary")
    listOf(
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { target ->
        target.binaries.framework {
            baseName = "MyLibrary"
            isStatic = true
            compilerOptions {
                freeCompilerArgs.add("-Xexpect-actual-classes")
            }
            optimized = true
    
            export(project(":JsonUtilities"))
            export(project(":PlatformUtilities"))
            xcf.add(this)
        }
    }
    Is it also possible to make kotlin itself in a xcframework to avoid conflict and inconpatible type ? Ty
    • 1
    • 1
  • m

    MJegorovas

    04/03/2025, 1:03 PM
    Anybody knows how kotlin-native objects are garbage collected? This sample manages to crash the app
    Copy code
    val array = Random.nextBytes(1000000)
    for (i in 0..10000) {
        array.usePinned {
            NSData.create(bytes = it.addressOf(0), length = array.size.convert())
        }
    }
    e
    • 2
    • 5
  • a

    abdelrahmanesam20000

    04/04/2025, 5:53 AM
    HI guys .... anybody knows how to generate generic/agnostic c headers for common main code ? ..... let's say I have a c app and I want to embed a kotlin code (from common main) to it ....so I wanna generate generic/agnostic c headers for common main code to call it .... is there anyway to do that ?
  • s

    Smoothie

    04/07/2025, 1:49 PM
    When I try to pass a (kotlinx serializer) JsonObject to a Kotlin listener that is used in a Swift app, that contain a JsonArray I get the error "Could not cast value of type `KListAsNSArray' to "Kotlinx_serialization_jsonJsonElement', there seem to be an issue in interop of kotlinx.serializer ? Anyone else can reproduce this issue ?
  • s

    Smoothie

    04/07/2025, 2:31 PM
    https://github.com/Kotlin/kotlinx.serialization/issues/2973 I openned an issue with reproduction code
  • n

    Neeme Praks

    04/09/2025, 7:38 PM
    Support for kotlin-native on Linux ARM32 soft-float ABI? I see there was a previous question on this channel about this topic which also referenced an obsolete kotlin-native Github issue #3350. But all this happened in 2019 — have there been any updates? Are there any plans for making it happen? We are running Java 8 SE on an IoT device with ARM926EJ-S processor (with thousands deployed) and we are looking for ways to modernise our stack. OpenJDK is too slow (well, the garbage collector pauses are already now causing issues) so ideally we would like to run a native binary. So far, the top contender is Rust (
    armv5te-unknown-linux-gnueabi
    target architecture) but Kotlin would be so much easier, considering that our cloud stack is all Kotlin (running on JVM). I’m not sure how much effort would the initial development be? And the later maintenance? We might be willing hack on this in case it isn’t too hard. As much as I understand, both Rust and Kotlin-native compilers use LLVM underneath so if it works with Rust then it should not be too hard to make it work with Kotlin-native?
    h
    m
    • 3
    • 8
  • m

    Mohamed Mabrouki

    04/14/2025, 10:39 AM
    I've encountered an issue where im trying to implement a delegateProtocol on kotlin side but the methods never get's called and the same code works on swift . i create an insance of the delegate in the class i will add the delegate to and calls addDelegate initially also tried to log the delegates of that class in ios side and it was added also i tried some other solutions but none of them worked. did anyone face the same problem or is something missing would appreciate help?
    • 1
    • 1
  • s

    Smoothie

    04/14/2025, 3:20 PM
    When using kotlin exception in swift, we can't check their type ? Either throwed from Kotlin or throwed from swift ?
    Copy code
    do {
    	//try Library.companion.getData()
    	throw SealedClass.NotInitialized().asError()
    }
    catch let error as SealedClass {
    	print("SealedClass")
    }
    catch let error as SealedClass.NotInitialized {
    	print("NotInitialized")
    }
    catch let error {
    	print("It's another type\(error)")
    }
    e
    • 2
    • 1
  • s

    Smoothie

    04/14/2025, 3:20 PM
    I always get in the generic catch
    • 1
    • 1
  • s

    Smoothie

    04/14/2025, 3:56 PM
    I can't even seem to pass data or info to it, the only information I can be sure to always get is the message
    🧵 2
  • s

    Smoothie

    04/14/2025, 3:57 PM
    I wanted to check them with error code
  • f

    François

    04/16/2025, 7:22 AM
    Hello, I'm trying to understand why a dynamic iOS library is missing build information. @rpath/ComposeApp.framework/ComposeApp (compatibility version: 0.0.0, current version: 0.0.0) These values shouldn't be 0.0.0, I guess it Konan who did the job. FYI: I'm using the latest version of Kotlin
  • w

    Waldemar Kornewald

    04/29/2025, 1:36 PM
    We’re facing some not so nice exception conversion when going through Swift -> Kotlin -> Swift. The inner Swift code’s exception gets wrapped at the Kotlin layer but when bubbling out of Kotlin back into the outer Swift layer the original inner Swift exception is still wrapped and thus can’t be caught in an intuitive way. Maybe that’s done to track the stack trace correctly, but the resulting wrapping is not what developers expect when using our SDK. We currently have to surround Swift -> Kotlin calls with an unwrapper helper and Swift implementations of Kotlin interfaces with an exception wrapper helper to preserve the original exception types (especially Swift Error types). Are there any plans to improve exception handling such that the wrapping becomes unnecessary?
  • 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