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
  • j

    Jeff Lockhart

    07/21/2022, 1:03 AM
    I'm getting a linker error after declaring a function in my .def file and using it in Kotlin:
    Undefined symbols for architecture x86_64:
      "_OBJC_CLASS_$_CBLC4Document", referenced from:
          objc-class-ref in result.o
      "_c4db_getDoc", referenced from:
          _cocoapods_CouchbaseLite_c4db_getDoc_wrapper0 in result.o
    ld: symbol(s) not found for architecture x86_64
    The function
    c4db_getDoc()
    is implemented in the library here. Its declaration just isn't in the framework's public headers, which is why I added it as a custom definition. Its internal declaration is in this .h file. I've declared it this same way in the .def (along with the struct parameter types):
    C4Document* c4doc_get(C4Database *database, C4String docID, bool mustExist, C4Error* outError);
    Would the issue be that the implementation is in a .cc C++ file and Kotlin doesn't support C++ interop? If so, is there some way I could access this function?
    2 replies · 1 participant
  • n

    napperley

    07/21/2022, 2:16 AM
    Does Kotlin Native have a way to get Kotlin objects out of a callback as output? Below is the defined callback:
    fun runFunction(argPtr: COpaquePointer?): Int = memScoped {
        val tmpCmd = argPtr?.asStableRef<Command>()?.get() ?: throw IllegalStateException("Command cannot be null")
        val argv =
            if (tmpCmd.args.isEmpty()) arrayOf(tmpCmd.filePath, "").toCStringArray(this)
            else arrayOf(tmpCmd.filePath, *tmpCmd.args.toTypedArray()).toCStringArray(this)
        val status = alloc<IntVar>()
        val fileDescriptors = allocArray<IntVar>(2)
        createPipe(fileDescriptors)
        val pid = fork()
    
        if (pid == 0) {
            close(fileDescriptors[READ_POS])
            dup2(fileDescriptors[WRITE_POS], STDOUT_FILENO)
            dup2(fileDescriptors[WRITE_POS], STDERR_FILENO)
            execvp(tmpCmd.filePath, argv)
        }
    
        close(fileDescriptors[WRITE_POS])
        val file = openFileDescriptor(fileDescriptors[READ_POS])
        tmpCmd.output += file.readLines(10u)
        file.close()
        wait_for_process(status.ptr)
        status.value
    }
    In the callback the command output is stored in tmpCmd as a StableRef ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/-stable-ref/ ). Why isn't the changed state of the StableRef accessible outside of the callback?
    1 reply · 1 participant
  • n

    napperley

    07/21/2022, 3:26 AM
    With the Kotlin Native documentation there is an article that isn't applicable to all Kotlin Native targets: https://kotlinlang.org/docs/multiplatform-mobile-concurrency-overview.html This article (is iOS/mobile specific) should be moved somewhere else. Also the article's title should be renamed to Multiplatform Mobile Concurrency Overview.
    a
    a
    +1
    16 replies · 4 participants
  • r

    ribesg

    07/21/2022, 7:47 AM
    Would appreciate any help on this, can't find anything about either error on the internet
    ✅ 1
  • j

    Joey

    07/21/2022, 12:18 PM
    I was trying out Kotlin native for the first time and I was wondering if a kexe file on Mac can be turned into a proper distributable CLI app for other people? Or is this not yet possible?
    m
    k
    3 replies · 3 participants
  • j

    Jeff Lockhart

    07/21/2022, 7:37 PM
    Is it not possible to declare additional
    initWith...
    functions (constructors) in an ObjC category in a .def file? I've had success declaring properties and functions that aren't in the public API of an ObjC class, but adding an
    initWith...
    function doesn't add the constructor definition (or the
    @Deprecated initWith...
    function that is usually generated with the constructor). For example, where
    MyObjCClass
    is previously declared in a public API header:
    @interface MyObjCClass (Internal)
    @property (nonatomic, readonly, nonnull) NSString *foo;
    - (BOOL) isBar;
    - (instancetype) initWithFoo: (NSString)foo bar: (BOOL)bar;
    @end
    Adds extension functions on the class definition, instead of modifying the class defined by the public API header:
    expect val MyObjCClass.foo: NSInteger
    @ObjCCallable external expect fun MyObjCClass.foo(): NSInteger
    @ObjCCallable external expect fun MyObjCClass.isBar(): Boolean
    There is nothing added for the
    initWithFoo:bar:
    constructor though.
    r
    12 replies · 2 participants
  • a

    ankushg

    07/21/2022, 8:51 PM
    Hey all, not sure if this is a known issue or not: I have a Kotlin interface hierarchy with something like this:
    sealed interface MyCollectionClass {
      val collection: Collection<String>
    }
    
    data class MyListClass: MyCollectionClass {
      override val collection: List<String>
    }
    
    data class MySetClass: MyCollectionClass {
      override val collection: Set<String>
    }
    Within Kotlin, when we that our concrete type is a
    MyListClass
    , we also know that
    collection
    is of type
    List<String>
    But in Swift, even when we know we have an instance of
    MyListClass
    , the type of
    collection
    looks like a
    Collection<String>
    I think this is only the case with `sealed interface`s — `sealed class`es seem to be working as expected.
  • t

    Tlaster

    07/22/2022, 5:34 AM
    Can we have something like
    macos()
    instead of
    macosX64() macosArm64()
    like
    ios()
    in kotlin target config?
    b
    j
    3 replies · 3 participants
  • t

    Trey

    07/22/2022, 2:11 PM
    I've run into a blocker when trying to use kotlin native with my project. I created a ticket and a sample project to easily replicate it. Anybody know what may be wrong? https://youtrack.jetbrains.com/issue/KT-53282/Bad-params-issue-with-AudioQueue-on-iOS
    a
    l
    16 replies · 3 participants
  • p

    p4czyk

    07/23/2022, 4:15 PM
    Hey! 😊 Has anybody ever tried bluetooth socket programming (RFCOMM) with Kotlin Native? 🤔 I'm trying to implement this C-example (https://people.csail.mit.edu/albert/bluez-intro/x502.html) in Kotlin Native but it doesn't work. Everything is compiling fine and executing but the socket doesn't accept any connections. 🙁
    t
    n
    11 replies · 3 participants
  • p

    p4czyk

    07/23/2022, 5:41 PM
    Maybe I should add it here that I want to use libbluetooth.so (BlueZ-Stack). 😅
  • j

    Jeff Lockhart

    07/25/2022, 5:19 AM
    What would be the behavior of `pin()`ing a
    ByteArray
    and not `unpin()`ing it? Would this only prevent GC from relocating the memory, or would it cause a memory leak? My issue is with returning a native pointer to an internal
    ByteArray
    buffer as a stable reference, where the caller uses the pointer, but can't call
    unpin()
    after doing so.
    l
    3 replies · 2 participants
  • l

    Landry Norris

    07/25/2022, 7:24 PM
    I need to write a large int[] from C to a Kotlin IntArray in a performant way. Can I assume that an IntArray stores all values sequentially like a C int[] and memcpy the data to Pinned<IntArray>.addressOf(0), or could this break in future Kotlin Native releases?
    j
    3 replies · 2 participants
  • b

    bod

    07/25/2022, 9:45 PM
    Hello, World! I have a behavior difference when using the new memory manager or not with this very simple app (on Apple):
    fun main() {
        runBlocking {
            withContext(Dispatchers.Main) {
                println("Hello, World!")
            }
        }
    }
    With the new memory manager enabled, the message is never printed, the thread seems to be stuck on
    withContext
    . I’m not sure if this is to be expected - something like
    runBlocking
    blocking the main thread and making dispatching ineffective? … But then again it feels like this should work, and also looks like a regression since it works with the old MM? 🤔 Any insight would be appreciated! 🙏 Repro project here.
    a
    9 replies · 2 participants
  • e

    Edoardo Luppi

    07/26/2022, 9:27 AM
    I'm trying to use
    platform.windows.LPWSTR? /* = kotlinx.cinterop.CPointer<platform.windows.WCHARVar /* = kotlinx.cinterop.UShortVarOf<kotlin.UShort> */>
    for creating a https://docs.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_table_entrya struct. I'm stuck on the
    lpServiceName
    member, no idea how to obtain a value for it. Edit: maybe I got it.
    lpServiceName = "MyString".wcstr.ptr
  • e

    Edoardo Luppi

    07/26/2022, 9:55 AM
    Why are functions exported as nullable `val`s? Or better, why the "macro" that gets replace with *A or *W is nullable? Any good reason?
  • m

    Matthew Murray

    07/26/2022, 7:45 PM
    I’m seeing an issue in Kotlin/Native where === is returning false for two variables that both point to same ObjC object (== works fine). Is this a known issue that === doesn’t compare pointers as expected when comparing ObjC objects? Or is my understanding of === equality missing something?
    r
    l
    10 replies · 3 participants
  • m

    Miroslav Sobotka

    07/27/2022, 11:05 PM
    Unfortunately I can't tell you what's wrong, however, I would recommend creating a new issue in youtrack if you suspect a bug. There it will get the appropriate attention.
  • l

    Landry Norris

    07/29/2022, 3:46 PM
    I don’t know that there’s a way to automatically convert, but I generally write a Boolean.toBool(): Int and a Int.toKBoolean(): Boolean and call these.
    1 reply · 1 participant
  • l

    Leon Kiefer

    07/29/2022, 5:12 PM
    How does
    AutofreeScope
    and
    Arena
    work? do they automatically free the allocated memory when they are garbage collected, or is there some other mean to ensure native memory is freed if a kotlin object is garbage collected? We are currently wrapping a native library with a common code api and can not expose native memory management in the common code api.
    l
    a
    11 replies · 3 participants
  • f

    fwsGonzo

    07/31/2022, 6:50 AM
    static_kref_kotlin_Array args;
        args.pinned = NULL;
        syms->kotlin.root.main(args);
    This works fine, but then predictably the program arguments are null Does anyone know how to pass the program arguments to Kotlin?
  • j

    jmfayard

    07/31/2022, 5:14 PM
    Bonjour, how do you distribute on multiple platforms a CLI tool written with Kotlin-native? Last time I checked it was easier to publish via Kotlin-JS on npm... Or do you use your custom brew tap?
    m
    b
    65 replies · 3 participants
  • l

    Landry Norris

    08/01/2022, 5:01 PM
    Is anyone else seeing errors when generating GFM using Dokka where CPointer is used? It can’t correctly resolve any CPointer usages.
    1 reply · 1 participant
  • z

    zt

    08/02/2022, 1:04 AM
    I have the following code, I'm wondering if theres some way I can shorten it into just a one line function such as
    val windowAttributes dpy.getWindowAttributes(window)
    val windowAttributes = nativeHeap.alloc<XWindowAttributes>() {
        XGetWindowAttributes(display.ptr, window, ptr)
    }
    
    // Do some stuff
    
    nativeHeap.free(windowAttributes)
  • z

    zt

    08/02/2022, 8:10 PM
    Are there any tips I can use to further reduce binary size? My release build is 4.3 mb and using the
    strip
    command on it shrinks it to 3.1 mb.
    n
    7 replies · 2 participants
  • j

    Jozef Matus

    08/03/2022, 10:04 AM
    Hi all 🙂, I’m debugging my app in lldb, I would like to inspect variable which happens to be Map<String, String>. How would you do it? I loaded
    konan_lldb.py
    which helps interpretting non-basic structure and tells you little bit more then just
    ObjHeader *
    . But still, output of
    v
    command in lldb is this
    (ObjHeader *) context = [keysArray: ..., valuesArray: ..., presenceArray: ..., hashArray: ..., keysView: ..., valuesView: ..., entriesView: ..., maxProbeDistance: ..., length: ..., hashShift: ..., _size: ..., isReadOnly: ...]
    I would like to be able to print keys/values and I cant find the way to do that. Do anybody know how to do that? Thank you a lot 🙂
    m
    6 replies · 2 participants
  • t

    Tim Ortel

    08/03/2022, 1:59 PM
    I am new to kotlin/native, especially in the iOS area of native development. I want to use the GRPC cocoapod dependency in my kotlin multiplatform project for my iOS target.
    pod("gRPC-ProtoRPC", version = "~> 1.48", moduleName = "ProtoRPC")
    However, my Gradle Task fails with fatal error: module 'ProtoRPC' not found I have tried the steps suggested in https://kotlinlang.org/docs/native-cocoapods.html#possible-issues-and-solutions. However, there was no module.modulemap in build/cocoapods/synthetic/Pods/gRPC-ProtoRPC. I found one in build/cocoapods/synthetic/Pods/Target Support Files/gRPC-ProtoRPC but that one says: framework module ProtoRPC. What is the easiest way of getting access to the Objective-C implementation of GRPC in Kotlin Multiplatform?
  • t

    Trey

    08/03/2022, 7:34 PM
    Can somebody point me to some documentation on how to use the Arena class? I can only find one mention of it in the docs here. https://kotlinlang.org/docs/mapping-struct-union-types-from-c.html#create-struct-and-union-as-cvaluesref-lt-t-gt I would like to understand the difference between it and using nativeHeap.
    l
    2 replies · 2 participants
  • m

    mbonnin

    08/04/2022, 12:47 PM
    Hi 👋 . Looks like compiling a native lib with 1.7 requires consuming it with 1.7 (or we get a
    Incompatible abi version
    ) 1. is that true? 2. could we allow consumption with 1.6 by adding
    languageVersion = "1.6"
    when compiling? Looks like this works for JVM but not for native?
    j
    e
    +1
    13 replies · 4 participants
  • t

    Tim Ortel

    08/04/2022, 2:48 PM
    I am working with cinterops on my M1 Mac. I am writing my .def file, but the compilation fails with: All supported Xcode versions should support objc_fixed_enum. The line triggering this error is in one of the header files I am using, GPBBootstrap.h from Objective-C Protobuf:
    #if !__has_feature(objc_fixed_enum)
     #error All supported Xcode versions should support objc_fixed_enum.
    #endif
    Can I enable this support in my .def file? Sorry if this is not the right place to ask this question.
    l
    5 replies · 2 participants
Powered by Linen
Title
t

Tim Ortel

08/04/2022, 2:48 PM
I am working with cinterops on my M1 Mac. I am writing my .def file, but the compilation fails with: All supported Xcode versions should support objc_fixed_enum. The line triggering this error is in one of the header files I am using, GPBBootstrap.h from Objective-C Protobuf:
#if !__has_feature(objc_fixed_enum)
 #error All supported Xcode versions should support objc_fixed_enum.
#endif
Can I enable this support in my .def file? Sorry if this is not the right place to ask this question.
l

Landry Norris

08/04/2022, 3:03 PM
What XCode versions does the library have support for?
t

Tim Ortel

08/04/2022, 3:04 PM
• According to their Github Page: Xcode 10.3 (or later).
Its this line in this file: https://github.com/protocolbuffers/protobuf/blob/main/objectivec/GPBBootstrap.h#L44
I was wondering, if I maybe have to add some kind of argument to the compileOptions in the .def file.
l

Landry Norris

08/04/2022, 3:07 PM
I wonder if this is because cinterop uses a separate toolchain that provides a raw compiler (at least for C/C++). I wonder if it doesn’t use xcodebuild for Objective-C?
View count: 9