https://kotlinlang.org logo
Docs
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
  • o

    Oste Hovel

    04/27/2021, 4:35 PM
    Is there a websocket server library that supports Kotlin Native?
    m
    • 2
    • 1
  • m

    Michal Klimczak

    04/27/2021, 5:26 PM
    I don't really get the ios
    ...Protocol
    and
    ...ProtocolMeta
    Let's say I have some code that looks like this:
    val player = AVAudioPlayer(soundUrl, null)
                    player.delegate = object : AVAudioPlayerDelegateProtocol{
                        override fun audioPlayerDidFinishPlaying(
                            player: AVAudioPlayer,
                            successfully: Boolean
                        ) {
                            ...
                        }
                    }
    It complains that it needs to override all these ios NSObjectProtocol methods which is probably not something that I want. But when I try to use
    AVAudioPlayerDelegateProtocol*Meta*
    player.delegate complains that it doesn not conform to
    AVAudioPlayerDelegateProtocol
    Can I make the delegate work without implementing all these weird NSObjectProtocol methods.?
    ✔️ 1
    • 1
    • 1
  • s

    Sam

    04/27/2021, 6:39 PM
    Is support for developing on the Apple M1 going to improve soon? Specifically, will K/N support running in the simulator on an M1? I’ve been able to get by with just running as an iPad app on my Mac up until yesterday when I tried to add SwiftUI to the app. Preview support relies on being able to run the app in a simulator. I gave up and sadly added another storyboard to the app.
    👍 1
    r
    • 2
    • 1
  • n

    napperley

    04/29/2021, 2:04 AM
    Is there a straightforward way to convert Array<String> to CValuesRef<CPointerVar<ByteVar>>? ❔ IntelliJ is showing the following type in the Quick Documentation: CValuesRef<CPointerVar<gcharVar /* = ByteVarOf<gchar /* = Byte */> /> / = CPointerVarOf<CPointer<ByteVarOf<gchar /* = Byte */>>> */>? I'm wondering if I have correctly deciphered the type (into a human readable version) presented by IntelliJ.
    s
    • 2
    • 3
  • m

    Michal Klimczak

    04/29/2021, 3:24 PM
    what is the idea around handling objc checked exceptions in kotlin native (docs only really mention the opposite situation. E.g. consider AVAudioPlayer, in swift you deal with it like that:
    do {
        try AVAudioPlayer(contentsOf: url)
    } catch {
        // handle exception
    }
    In Kotlin Native it's signature is
    public constructor(contentsOfURL: platform.Foundation.NSURL, error: CPointer<ObjCObjectVar<NSError?>>?)
    How do you handle error here?
    s
    • 2
    • 5
  • a

    Arno Mittelbach

    05/01/2021, 12:05 PM
    Hi all. We are currently looking into the possibility of running a K/N library on the Hololens 2 which would require compiling to Windows ARM64. I could not find a lot of information on targeting Windows but it seems that at this point only x64 architectures are supported. If anyone has any experience on this, I’d be grateful for pointers.
    m
    • 2
    • 1
  • j

    jmfayard

    05/02/2021, 9:38 AM
    Hello, I just run my first Hello World with Kotlin Native on macos Next I would like to be able to execute a shell command like
    git log --oneline
    and capture its output and error output. Any idea how I can do that?
    e
    • 2
    • 2
  • j

    jmfayard

    05/03/2021, 8:11 AM
    Hello, I am looking for open-source Kotlin-native based CLI tools for inspiration. Any repo that comes to mind?
    👀 2
    b
    m
    a
    • 4
    • 10
  • m

    Michal Klimczak

    05/03/2021, 12:45 PM
    Any idea how to load a resource file for ios targeted kotlin native tests? Something like this but for ios. https://gist.github.com/dellisd/a1df42787d42b41cd3ce16f573984674#gistcomment-3729700
    👀 1
    m
    j
    • 3
    • 2
  • t

    Toby

    05/04/2021, 11:07 PM
    When building a shared library, is the .klib file cross-compatible or does it just support the builders operating system?
    👀 3
    m
    • 2
    • 2
  • n

    Nikky

    05/05/2021, 8:44 PM
    i am trying to use ktor-curl on windows, i figured out that i need msys2 in the default location.. and then it kinda works.. but only when i execute the produced binary through gitbash (i assume the other things need a environment refresh to pick up the new msys2 location or cmd cannot find the required .dll.a file) but .. could i instead configure kotlin-native to statically link/bundle libcurl so that the produced executable "just works" ?
    m
    • 2
    • 1
  • p

    ptmt

    05/06/2021, 9:53 AM
    Has someone managed to run all K/N shared code (e.g. view models, including initialization) not in main UI thread?
    t
    a
    • 3
    • 3
  • a

    aleksey.tomin

    05/07/2021, 9:01 AM
    Is exists an example of creating a tooltip for an image in minGW? I’ve found a lot of documentation and examples (C/win32) but nothing works for me. PS: I can share my code if someone wants.
    m
    • 2
    • 5
  • u

    ursus

    05/08/2021, 2:46 PM
    Noob question, will freezing be necessary if kotlin gets value types
    :yes: 1
    l
    n
    • 3
    • 7
  • n

    napperley

    05/09/2021, 4:19 AM
    Upon developing a basic program to my horror a critical bug with linking a C library occurs when using Kotlin 1.5.0 (doesn't affect Kotlin 1.4.31):
    > Task :linkRandom_numDebugExecutableLinuxX64 FAILED
    3 actionable tasks: 3 executed
    e: /home/napperley/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors
    
    The /home/napperley/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
    output:
    /home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to 'getentropy', version 'GLIBC_2.25'
    /home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to '__explicit_bzero_chk', version 'GLIBC_2.25'
    /home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to 'getrandom', version 'GLIBC_2.25'
    I have tried nearly all forms of C library linking (except for statically linking the user ver of the libsodium lib), which includes the following: • Statically linking the system ver of the lib • Dynamically linking the system ver of the lib • Dynamically linking the user ver of the lib
    👀 1
    😱 3
    s
    • 2
    • 5
  • m

    mboudraa

    05/10/2021, 7:55 PM
    Hello cross posting here since it seems to be a better channel for asking. The stack trace is the following
    e: Compilation failed: IrTypeAliasSymbol expected: Unbound public symbol for public kotlinx.coroutines/CancellationException|null[0]
     * Source files: 
     * Compiler version info: Konan: 1.5 / Kotlin: 1.5.0
     * Output kind: STATIC_CACHE
    e: java.lang.IllegalStateException: IrTypeAliasSymbol expected: Unbound public symbol for public kotlinx.coroutines/CancellationException|null[0]
    https://kotlinlang.slack.com/archives/C3PQML5NU/p1620671651034400
    s
    j
    +2
    • 5
    • 11
  • t

    Toby

    05/15/2021, 6:40 PM
    How do I implement and use Kotlin/Native libraries without a maven repository in gradle? The library will be provided in (.def), .dll/.so/.dylib, .h and .klib files according to the documentation.
    b
    n
    • 3
    • 6
  • j

    jmfayard

    05/15/2021, 8:16 PM
    val fp = popen(commandToExecute, "r") ?: error("Failed to run command: $command")
        val status = pclose(fp)
    I have a windows specific bug and I have. no idea where to start I implemented a function to execute an external command and get its output It works fine on macOS/Linux but it gives a compilation error on windows https://github.com/jmfayard/kotlin-cli-starter/runs/2583168375?check_suite_focus=true#step:5:73 https://github.com/jmfayard/kotlin-cli-starter/blob/9d9b6a8081281db159e80574c872048332bc254c/src/nativeMain/kotlin/io/NativeActuals.kt#L20-L49
    n
    • 2
    • 1
  • a

    ArcticLampyrid

    05/16/2021, 12:55 AM
    Just curious, is there any progress on the new memory management?
    n
    • 2
    • 1
  • p

    Philip Dukhov

    05/17/2021, 3:28 AM
    Hello!
    Char.Companion.toChars
    marked deprecated, is there any replacement(perfectly available in KMP)?
    l
    • 2
    • 2
  • d

    Daniele B

    05/17/2021, 5:22 PM
    Is it possible to call reified functions from Swift? I wrote in KMP a reified function, that returns a class implementing the interface “ScreenState”. Xcode doesn’t prompt me any error, but it crashes at runtime:
    l
    • 2
    • 4
  • n

    nickheitz

    05/18/2021, 8:53 AM
    Beginner question... Can anyone point me to an example of linking/calling a rust dynamic library from a kotlin native application? I'm expecting some kind of c interop, but the lack of header files in the rust works leaves me a bit puzzled. This is purely for experimental purposes, not for any real world problem.
    t
    • 2
    • 2
  • m

    mbonnin

    05/18/2021, 11:42 AM
    Can I inspect the contents of a
    *.knm
    file somehow? Something like
    objdump
    but for .klib/.knm ? I'm trying to find a place where I'm referencing an internal symbol from my code.
    • 1
    • 1
  • w

    Wietlol

    05/18/2021, 9:49 PM
    for example, I want to make some changes to the Any type and String type, can I clone the sdk and have my own version of it?
    :thread-please: 4
    t
    • 2
    • 1
  • m

    Michal Klimczak

    05/19/2021, 7:59 AM
    I'm a bit lost on the memory management in KMM obj-c. I have
    AvAudioPlayer
    which uses a delegate
    AVAudioPlayerDelegateProtocol
    . Now I wanted to just use an anonymous implementation of that protocol (or a class extending it - they both work the same) and set it more or less like this
    player.delegate = object : NSObject(), AVAudioPlayerDelegateProtocol
    //or
    player.delegate = MyOwnAudioPlayerDelegateImpl()
    The problem is that the delegate is nullified at random times. It works if I make the class containing the player extend
    AvAudioPlayerDelegateProtocol
    and then do
    player.delegate = this
    . But it's a bit ugly and creates different issues. Does anyone know how I can manage memory reliably in the first scenario?
    ✔️ 1
    • 1
    • 1
  • l

    Luoqiaoyou

    05/20/2021, 8:16 AM
    I want to create a struct from c, but get an exception “Native interop types constructors must not be called directly” , so i use
    alloc<*>
    instead. Is it a way to invoke constructor function when i call
    alloc<*>
    ? because the params is final in klib, i can not assign value after
    alloc<*>
    . my code:
    memScoped {
        val info = alloc<GrMtlTextureInfo>()
        info.fTexture = _texture.objcPtr() // fTexture is final in klib
        renderTarget = GrBackendRenderTarget(480, 320, 1, info.reinterpret())
    }
    d
    • 2
    • 4
  • y

    Yaniv Sosnovsky

    05/20/2021, 12:54 PM
    Hi. Can anyone help me with extension function from Kotlin to swift? Seems like I’m not able to access the extension from Swift
    m
    l
    • 3
    • 2
  • a

    Arkadii Ivanov

    05/20/2021, 6:59 PM
    Looks like a while ago we got
    Cleaner
    for automatic resource deallocation! https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/kotlin/kotlin/native/internal/Cleaner.kt
    m
    • 2
    • 6
  • s

    spierce7

    05/20/2021, 11:03 PM
    What would be the proper way to call an objective c function that takes a pointer to a boolean? i.e. https://developer.apple.com/documentation/foundation/nsfilemanager/1410277-fileexistsatpath
    r
    • 2
    • 2
  • h

    Hauke Radtki

    05/21/2021, 7:24 PM
    Anyone having issues returning a native var (e.g. ULongVar) from a suspending function? Im getting a typecast exception from NativePointed to the return type (ULongVar in this instance). Reproducer inside ⬇️
    • 1
    • 4
Powered by Linen
Title
h

Hauke Radtki

05/21/2021, 7:24 PM
Anyone having issues returning a native var (e.g. ULongVar) from a suspending function? Im getting a typecast exception from NativePointed to the return type (ULongVar in this instance). Reproducer inside ⬇️
@Test
    fun suspendReturnNativeVar() {
        suspend fun NativePlacement.returnStruct(): ULongVar {
            val buffer = allocArray<UByteVar>(sizeOf<ULongVar>())

            // Any suspending data fetch function
            delay(1)

            val reinterpret = buffer.reinterpret<ULongVar>()
            reinterpret[0] = 0xAAAAu

            return reinterpret.pointed
        }

        runBlocking {
            memScoped {
                val v = returnStruct()

                assertEquals(0xAAAAu, v.value)
            }
        }
    }
Im getting a
kotlin.ClassCastException: kotlinx.cinterop.NativePointed cannot be cast to kotlinx.cinterop.ULongVarOf
when the coroutine returns to the calling context (when coroutine dispatches the assignment of
val v
)
Removing the suspend keyword (and the delay) makes this work
Tested on 1.4.35 and 1.5.0 with multithreaded coroutines (though no threading involved here)
View count: 11