https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • s

    Skolson5903

    01/19/2022, 12:42 AM
    I have a bytearray of UTF-16 encoded bytes read from a cinterop library COpaquePointer, and need to convert the ByteArray to a String. But native doesn't seem to have Charsets much less Charsets.UTF_16. ByteArray.toKString() is for UTF8. Is there some simple way to do this? My searches are sucking 🙂
    e
    n
    • 3
    • 26
  • s

    saket

    01/19/2022, 4:47 AM
    Is my understanding correct that the
    spec.name
    of a generated podspec can't be changed?
    🔜 1
    v
    • 2
    • 2
  • l

    Landry Norris

    01/20/2022, 4:22 AM
    For one of my projects, I'm trying to compile without stdlib. I created a file (test.kt) with the following code
    fun main() {
    	
    }
    and tried compiling it with
    konanc -nostdlib test.kt
    . I get the following errors:
    error: could not load module <org.jetbrains.kotlinx.kotlinx-cli>
    error: compilation failed: Kotlin IR Linker exception
    Has anyone tried compiling with the nostdlib option?
    n
    • 2
    • 5
  • n

    nfrankel

    01/21/2022, 5:35 PM
    hello 👋 i wanted to try to compile kotlin to wasm the documentation points to an executable named
    kotlinc-native
    https://kotlinlang.org/docs/native-command-line-compiler.html but i’ve installed kotlin with homebrew and i don’t see
    kotlinc-native
    in the available binaries
    $ls /usr/local/Cellar/kotlin/1.6.10/bin
    
    kapt          kotlin        kotlin-dce-js kotlinc       kotlinc-js    kotlinc-jvm
    do i need something additional? or is an issue with the homebrew recipe?
    r
    l
    • 3
    • 4
  • t

    tarek

    01/21/2022, 5:44 PM
    Hi I have an iOS framework that fails to link on arm32 in debug mode without
    -opt
    enabled Do you think I should file a bug ?
    p
    • 2
    • 3
  • b

    Benjamin Deroche

    01/24/2022, 12:24 AM
    Any particular reason why the binding for sfRenderWindow does not get generated? I can use (most?) of csfml from kotlin native, I even have the sfWindow, but no sfRenderWindow, and can't find why My libsfml.def :
    # SFML/Audio.h SFML/Graphics.h SFML/Network.h SFML/System.h SFML/Window.h
    headers = SFML/Graphics.h \
              SFML/System.h \
              SFML/Window.h
    headerFilter = SFML/**
    
    compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu
    
    # -lcsfml-audio -lcsfml-graphics -lcsfml-network -lcsfml-system -lcsfml-window
    linkerOpts.osx = -L/opt/local/lib -lcsfml-graphics -lcsfml-system -lcsfml-window
    linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -lcsfml-graphics -lcsfml-system -lcsfml-window
    l
    • 2
    • 4
  • s

    Skolson5903

    01/24/2022, 11:40 PM
    I've got a KMM framework with native stuff targeting Mac and IOS built and am learning Swift-calling-Kotlin. I have a question about the experimental async/suspend support when calling suspend functions that have suspend lambdas from swift. Say I have a Kotlin function like this:
    suspend fun anyname(arg1:String, block: suspend (arg) -> Unit)
    . What is the best way to invoke this from swift? I'm watching some unresolved issues in Youtrack (https://youtrack.jetbrains.com/issue/KT-47610 ) on making this better, but with current swift and kotlin 1.6.10 am having trouble figuring out if there is a non-messy way to do this. Specifically the best way to code the
    block
    lambda above in the Swift call of
    anyname("xxx") { arg -> ... }
    . I'm currently playing with using a class that implements the kotlin-generated swift protocol
    KotlinSuspendFunction1
    which has an
    invoke
    function that is getting called with arg1: Any? and a completionHandler. Is that the best/only way to make this work, or am I going down a rabbit hole since I'm a Swift newbie? If anyone can point me to an example of doing this better, I'd appreciate it. I guess the real answer I'm asking for is whether this is even a good thing to try to do from Swift until it gets improved 🙂. Thanks in advance for any tips/links.
    e
    • 2
    • 2
  • r

    Racci

    01/25/2022, 6:05 AM
    is there a way to package resources like a json file inside a .kexe or .exe
    👀 2
    d
    b
    +2
    • 5
    • 7
  • l

    Landry Norris

    01/25/2022, 8:47 PM
    I’m using the new Garbage Collector, and in my code I was unintentionally allocating a large UIntArray (~1.3MB) in a loop. The array was only referenced inside the loop. I got a crash on iOS and the stack trace shows that the symbol is
    kotlin::mm::internal::ObjectFactoryStorage<8ul, kotlin::mm::internal::AllocatorWithGC<kotlin::mm::internal::SimpleAllocator, kotlin::gc::SameThreadMarkAndSweep::ThreadData> >::Node::~Node:
    and the error is
    Thread 1: EXC_BAD_ACCESS (code=1, address=0xff000000ff000000)
    How can I confirm if this is a GC bug?
    a
    • 2
    • 10
  • y

    y9san9

    01/26/2022, 6:57 AM
    Hello mates! Is there a possibility to annotate kotlin
    companion object
    somehow, so I can use it without additional
    Companion()
    call from Swift. Seen this one: https://youtrack.jetbrains.com/issue/KT-44862. May be some workaround here?
    a
    p
    • 3
    • 4
  • d

    Daniel Baird

    01/27/2022, 2:55 PM
    Hi folks. we are seeing some
    Attempted to dereference garbage pointer
    exceptions in iOS with a few different stack traces, and we are unable to reproduce it. We do a lot of passing objects around between swift and kotlin native, and I don't feel like I have a good handle on how the memory management works in cases where an object originates in kotlin and gets passed into swift, or situations involving lambdas/closures that should be holding on to things. I have a hunch that these issues are related to issues with how we are handling this though. Does anyone know where I can find detailed documentation of how these situations work, or have any info about potential causes of this error when interoping with kotlin native? I have of course read the main kotlin pages like https://kotlinlang.org/docs/native-objc-interop.html.
    y
    • 2
    • 3
  • w

    wilddev

    01/31/2022, 7:20 PM
    Any ideas, what can be wrong? If i disable bitcode in xcode - build is successfull. What is advantage of building with bitcode vs without bitcode?
    s
    z
    • 3
    • 2
  • g

    Gabi

    02/01/2022, 4:07 AM
    Hello, is anyone with problems with kotlin native debugger in Intellij Idea? I tried in a fresh installation in a windows machine, but didn't success, and tried in a linux machine, both with the latest version, but in linux I tried with EAP, I have installed the Native Debugger Support, should I create an issue in youtrack or something like this?
    :youtrack: 1
    a
    • 2
    • 2
  • f

    Francesco Pedron

    02/01/2022, 8:47 AM
    Hello, I'm trying to use kotlin/native to build a simple .dll, but the resulting .dll is a 2MB file full of zeros, I cannot understand what I'm doing wrong. Here you can find a project that should reproduce the problem: https://github.com/francescopedronomnys/jni-dll-wrapper The gradle tasks I've tried are :linkNative and :build, both producing that empty .dll file. Just to explain the commented code you will find on the repo: my final goal is to wrap an existing .dll in another .dll that will expose JNI functions that will be used by a kotlin/jvm project using Compose as GUI. Thank you
    • 1
    • 1
  • j

    Jim

    02/01/2022, 10:31 PM
    can I force kotlin native to use a slightly older version of xcode?
    k
    • 2
    • 2
  • m

    martmists

    02/05/2022, 2:37 AM
    How do I link and include a static library? The only "documentation" I can find is vague mentions of stuff on youtrack and files on github that don't exist anymore, e.g. https://github.com/JetBrains/kotlin-native/blob/master/FAQ.md#q-how-do-i-create-a-static-library-or-an-object-file
    l
    • 2
    • 1
  • l

    Landry Norris

    02/08/2022, 6:36 PM
    I’m currently using cinterop on a project. I have the .def file set up for the OSs and architectures that I need for devices, but I’m wanting to set up an Arm64 simulator now for M1 Mac. Is there a list of the names supported for identifying OS and architecture (such as android_arm32, android_x64, ios_arm64, etc)? I can’t seem to find the name that matches iosSimulatorArm64.
    a
    • 2
    • 2
  • n

    napperley

    02/10/2022, 2:40 AM
    With the Kotlin Native documentation it would be good to have an article that provides guidance on how to wrap/manage C libraries with Kotlin Native libraries (especially if multiple related libraries are involved). Using the LVGL KT ( https://gitlab.com/embed-soft/lvgl-kt ) libraries as an example they are structured like the following:
    Core (depends on LVGL C lib); targets linuxX64 & linuxArm32Hfp
      |> Drivers (depends on LVGL & LV Drivers C libs); targets linuxX64 & linuxArm32Hfp
            |> SDL 2 (depends on LV Drivers & SDL 2 C libs); targets linuxX64
    If the LVGK KT Widgets library existed then the structure would look like this:
    Core (depends on LVGL C lib); targets linuxX64 & linuxArm32Hfp
      |> Widgets (depends on LVGL C lib); targets linuxX64 & linuxArm32Hfp
      |> Drivers (depends on LVGL & LV Drivers C libs); targets linuxX64 & linuxArm32Hfp
            |> SDL 2 (depends on LV Drivers & SDL 2 C libs); targets linuxX64
    Apparently there is an issue where Kotlin compiler caching can fail when the same C library is used in multiple Kotlin Native libraries that are used by a Kotlin Native program: https://youtrack.jetbrains.com/issue/KT-51190
    💯 3
    👍🏼 1
    👍 3
    • 1
    • 1
  • b

    Bailey Pollard

    02/10/2022, 4:51 PM
    Hey folks, is there any documentation on adding a
    .xcframework
    to a kotlin native project?
    s
    t
    • 3
    • 11
  • u

    ubuntudroid

    02/11/2022, 1:43 PM
    Hi everyone, I have a somewhat strange problem: up until now I’ve used the cocoapods plugin in combination with
    isStatic = true
    to integrate our shared module into the iOS app. However, I now have to make shared dynamic due to some third party library issue which can only be worked around with that due to this Kotlin native issue: https://youtrack.jetbrains.com/issue/KT-50982#focus=Comments-27-5741956.0-0 Apart from that, it seems that using dynamic frameworks is the preferred way anyway, so I am generally fine with that workaround:
    cocoapods {
            ios.deploymentTarget = "14.1"
    
            framework {
                summary = "Shared Module"
                baseName = "shared"
                isStatic = false
                embedBitcode(BITCODE)
                podfile = project.file("../iosApp/Podfile")
            }
        }
    All is good and well and the app builds as it should until I try to export the archive which now fails with the following error message:
    shared not found in dylib search path
    Any idea what I might need to change to make this work?
    k
    s
    • 3
    • 8
  • i

    ishitatsuyuki

    02/13/2022, 9:59 AM
    I'm seeing mentions of JNI in https://github.com/JetBrains/kotlin/blob/f5e4c72f063608220d64da81e0fc6be5c17505fc/[…]etbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt Does this mean that the interop tool actually has partial support for JVM bindings?
    l
    • 2
    • 5
  • s

    sdeleuze

    02/15/2022, 8:42 AM
    Hey, I try to build https://github.com/JetBrains/kotlin/tree/master/kotlin-native/tools/benchmarksAnalyzer and have not played with Kotlin/Native for a very long time so sorry if those are basic questions. When importing the project in IDEA, I had both
    import platform.posix.*
    and
    import libcurl.*
    in red (unresolved reference) in
    kotlin/kotlin-native/tools/benchmarksAnalyzer/src/main/kotlin-native/org/jetbrains/analyzer/Utils.kt
    . I found in Kotlin Native README that I had to run
    ./gradlew :kotlin-native:dist :kotlin-native:distPlatformLibs
    at the root of the
    kotlin
    project to get
    import platform.posix.*
    resolving. This part is now fixed. But I am blocked for libcurl:
    > Task :compileNativeMainKotlinMetadata FAILED
    e: /home/seb/playground/kotlin/kotlin-native/tools/benchmarksAnalyzer/src/main/kotlin-native/org/jetbrains/analyzer/Utils.kt: (10, 8): Unresolved reference: libcurl
    I have libcurl installed (Archlinux) and headers are in
    /usr/local/include
    . I tried to modify the build to specify `compilerOpts '-I/usr/local/include'`:
    fromPreset(presets.linuxX64, 'linux') {
                compilations.main.cinterops {
                    libcurl {
                        compilerOpts '-I/usr/local/include'
    			        includeDirs.headerFilterOnly '/usr/include', '/usr/local/include'
                    }
                }
            }
    But still the same error. When I try to build the project with
    gradle build
    I get:
    > Task :compileNativeMainKotlinMetadata FAILED
    e: /home/seb/playground/kotlin/kotlin-native/tools/benchmarksAnalyzer/src/main/kotlin-native/org/jetbrains/analyzer/Utils.kt: (10, 8): Unresolved reference: libcurl
    The command
    gradle cinteropLibcurlLinux
    seems to run properly and invokes
    cinterop -o /home/seb/playground/kotlin/kotlin-native/tools/benchmarksAnalyzer/build/classes/kotlin/linux/main/cinterop/benchmarksAnalyzer-cinterop-libcurl.klib -target linux_x64 -def /home/seb/playground/kotlin/kotlin-native/tools/benchmarksAnalyzer/src/nativeInterop/cinterop/libcurl.def -compiler-option -I/usr/local/include -Xmodule-name benchmarksAnalyzer-cinterop-libcurl
    which seems to work fine. Could somebody point me to what I am missing to get libcurl resolving both in IDEA and with
    gradle build
    ?
    a
    e
    n
    • 4
    • 7
  • k

    kevin.cianfarini

    02/16/2022, 4:33 PM
    For what reason does Konan require ncurses? I had a native build failing with
    > Task :runtime:linkDebugTestLinuxX64
    e: Unable to compile C bridges
    
    > Task :runtime:linkDebugTestLinuxX64 FAILED
    
    FAILURE: Build failed with an exception.
    Which took a while to debug that it was an issue with the compiler itself, and not the code I was compiling.
    a
    • 2
    • 2
  • s

    Sterling Albury

    02/16/2022, 9:44 PM
    is there a way to call a kotlin suspend function from a flow collector in swift? i tried wrapping the call to the suspend function in a swift Task but get an error saying suspend functions can only be called from the main thread, even though I try to use
    withContext
    in my suspend function. If I try to use
    DispatchQueue.main.async
    it complains about passing a function type
    () aync ->()
    to a param expecting sync function type. I'm using the experimental native memory model in my kotlin module btw.
    • 1
    • 1
  • z

    Zode

    02/17/2022, 3:01 AM
    we know kotlin/native use LLVM backend for native target, how could we set optimize-level for native target, like -O0, -O3, -Oz?
    e
    • 2
    • 3
  • h

    hho

    02/17/2022, 6:35 PM
    Hi! I'm just trying out my first Kotlin native project … and now I have a problem when writing tests: I can't seem to access any of my test resources. Turns out, when I run
    ./gradlew nativeTest
    the task
    nativeTestProcessResources
    is actually never executed. Why is that?
    b
    • 2
    • 3
  • w

    William Reed

    02/17/2022, 7:48 PM
    hi guys, i've been trying to run a
    maxosX64
    target project on my apple silicon mac, and everything with the build goes fine, but the
    run
    task keeps getting skipped.
    > Task :app:compileKotlinMacosX64 UP-TO-DATE
    > Task :app:linkDebugExecutableMacosX64 UP-TO-DATE
    > Task :app:runDebugExecutableMacosX64 SKIPPED
    any ideas? I've tried on multiple projects and running a clean build. kotlin
    1.6.10
    running with
    ./gradlew runDebugExecutableMacosX64
    r
    l
    +2
    • 5
    • 28
  • s

    Shehab Ellithy

    02/18/2022, 5:25 AM
    I have no idea how to include kotlinx's serialization package in a kotlin-native project. Is someone willing to walk me through it? I did do around 3 hours of search and tinkering around but couldn't get it
    a
    r
    • 3
    • 13
  • f

    flygerian.eagle

    02/21/2022, 5:33 AM
    Hi all, check out pic...how can I run 'hello.kt'
    a
    • 2
    • 6
  • w

    William Reed

    02/21/2022, 9:50 PM
    any suggestions for something similar to java's 
    ByteBuffer
     that is kotlin native friendly? I found there is something similar inside 
    kotlinx.serialization
     so I might just copy that file in https://github.com/Kotlin/kotlinx.serialization/blob/v0.9.1/runtime/native/src/main/kotlin/kotlinx/io/Buffers.kt
    p
    • 2
    • 1
Powered by Linen
Title
w

William Reed

02/21/2022, 9:50 PM
any suggestions for something similar to java's 
ByteBuffer
 that is kotlin native friendly? I found there is something similar inside 
kotlinx.serialization
 so I might just copy that file in https://github.com/Kotlin/kotlinx.serialization/blob/v0.9.1/runtime/native/src/main/kotlin/kotlinx/io/Buffers.kt
p

Paul Woitaschek

02/21/2022, 10:11 PM
You can use okio
:thank-you: 1
View count: 13