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

    iamsteveholmes

    06/25/2021, 9:29 PM
    Anyone know of a multiplatform alternative to workmanager? I'm looking for a way to schedule data update tasks so that my app can work offline.
    :not-kotlin: 1
    c
    1 reply · 2 participants
  • p

    phisch

    06/27/2021, 6:52 PM
    I have a project that builds to linux for x11 and wayland. Each of those need different cinterop library definitions. So i thought it's a good idea to split each c library into its own definition file, so i could cherry pick what i need for each target. Like i'd have one
    xcb.def
    (used for x11), one
    cairo.def
    (used for both x11 and wayland), and a
    pango.def
    (also used for both targets). The issue is that a part of the cairo library (which i will extract into its own def file), links against xcb. So if i create its own file for this, the package will be a different one, and in code, i end up with 2 interop types in different packages which are basically the same. So a function from the cairo package might require
    cairo.xcb_visualtype_t
    instead of a
    xcb.xcb_visualtype_t
    and i have no idea how to tell it that it should use the one from the xcb namespace instead. There is probably a really easy way to solve this, but i don't know how yet, and the documentations didn't push me in the right direction.
    2 replies · 1 participant
  • n

    napperley

    06/28/2021, 4:50 AM
    Just wondering if the Kotlin Compiler (with Kotlin 1.4.31) Smart Casting topicPtr into a non null one is correct behaviour? Below is some sample code:
    import kotlinx.cinterop.*
    import platform.linux.free
    import platform.linux.malloc
    
    fun main() {
        var topicPtr = malloc(8uL * 5uL)?.reinterpret<ByteVar>()
        topicPtr?.set(0, '/'.toByte())
        topicPtr?.set(1, 't'.toByte())
        topicPtr?.set(2, 'e'.toByte())
        topicPtr?.set(3, 's'.toByte())
        topicPtr?.set(4, 't'.toByte())
        println("Topic: ${topicPtr?.toKString()}")
        free(topicPtr)
        topicPtr = null
        // Smart Casting occurs here.
        free(topicPtr)
        println("Exiting...")
    }
    d
    2 replies · 2 participants
  • n

    napperley

    06/29/2021, 3:20 AM
    This obscure runtime error appears, and I don't know why this error is appearing:
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
        at ThrowIncorrectDereferenceException (0x28742c)
        at  (0x32cda1)
        at Kotlin_initRuntimeIfNeeded (0x33cd7b)
        at _636f6d2e636861706d616e3a626f6c742d646174612d636f6e73756d6572_kncfun78 (0x32e26c)
        at MQTTClient_run (0x347173)
        at  (0x7fd0e85d86db)
        at clone (0x7fd0e80e9a3f)
        at  ((nil))
    t
    p
    18 replies · 3 participants
  • n

    napperley

    06/30/2021, 2:37 AM
    What are the pitfalls/catches of calling the initRuntimeIfNeeded function?
    k
    1 reply · 2 participants
  • a

    ankushg

    06/30/2021, 4:08 PM
    Anyone have an automated way (plugin or lint rule?) to enforce that public methods are either • annotated with @Throws for iOS, or • intentionally not annotated (either with an ignore, or maybe a different annotation)? We aggressively use `check`/`require` to validate method inputs, and it’s a pain when we encounter it and don't get a catchable exception on iOS 😅
    m
    1 reply · 2 participants
  • s

    Slackbot

    06/30/2021, 8:45 PM
    This message was deleted.
    :homer-disappear: 1
    n
    1 reply · 2 participants
  • m

    Mats Larsen

    07/01/2021, 12:03 AM
    Are the internals of the Kotlin/Native compiler documented anywhere? Specifically the .knt, .knb, .knf, .knd and .knm formats which are produced when running
    -p library
    .
    e
    4 replies · 2 participants
  • m

    Mats Larsen

    07/01/2021, 12:05 AM
    Would also love pointers for dynamically linking the stdlib if possible. Thanks in advance
    n
    2 replies · 2 participants
  • m

    Mohit Khanna

    07/01/2021, 1:54 AM
    Hello, I am trying to use the Stately's Isolate Collections library. However when I'm trying to iterate over an IsoMutableMap, then I get crash saying UnsupportedOperationException("Can't leak mutable reference"). In the IsoMutableMap.kt, this operations is blocked as below. Can someone share why 'entries' can leak mutable reference but not the 'values'? Also, Is there any other way to iterate over the entry set?
    override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
        get() {
            throw UnsupportedOperationException("Can't leak mutable reference")
            // access { IsoMutableSet(fork(it.entries)) }
        }
    Thanks!
    k
    2 replies · 2 participants
  • m

    martmists

    07/02/2021, 11:01 AM
    In kotlin/native, how would I create a frozen reference to a mutable object to read changes across threads? Basically, my front-end is a block editor similar to the Unreal Event Editor, and the back-end has a thread using the configuration from that editor in real-time. However, I can't use the MutableList of nodes I have since either it's not frozen and can't be shared, or it's frozen but then the front-end can't make any changes. I also considered stopping and restarting the backend thread, but since a frozen object can't be un-frozen, that's also not an option. I've tried doing some more hacky stuff with creating a COpaquePointer and pulling it from that, to avoid it from being frozen, but that still made the object exist in two threads and crash. I'd really like to know how to solve this, since I much prefer kotlin over C++ (where I did get this concept working).
    k
    n
    +1
    10 replies · 4 participants
  • m

    martmists

    07/02/2021, 4:16 PM
    Also, how should I go about debugging? the one built into IJ with the gradle task doesn't really catch any errors...
    k
    2 replies · 2 participants
  • m

    martmists

    07/02/2021, 4:20 PM
    Alternatively, if someone could explain what's wrong:
    kotlin
    abstract class Node {
        abstract fun process()
        abstract fun cleanup()
        abstract val inputs: Map<String, CArrayPointer<FloatVar>>
        abstract val outputs: List<String>
    
        fun connect(output: String, receivingNode: Node, input: String) {
            if (!outputs.contains(output)) {
                throw IllegalArgumentException("Unknown node output name! (Connecting ${this::class.simpleName}.$output to ${receivingNode::class.simpleName}.$input)")
            }
            val new = mutableMapOf<String, CArrayPointer<FloatVar>>().also {
                it.putAll(this.connections.value)
                it[output] = receivingNode.getInputBuffer(input)
            }
            this.connections.value = new
        }
    
        fun getOutputBuffer(name: String) : CArrayPointer<FloatVar>? = connections.value[name]
    
        /* internals below */
    
        private val connections = AtomicReference(mapOf<String, CArrayPointer<FloatVar>>())
        private fun getInputBuffer(name: String) : CArrayPointer<FloatVar> = inputs[name] ?: throw IllegalArgumentException("Unknown node input name! (${this::class.simpleName}.$name)");
    }
    For some reason somewhere in
    connect
    , it throws an error because a map that is supposedly already frozen gets modified, but I don't see where that happens.
    k
    1 reply · 2 participants
  • m

    martmists

    07/02/2021, 6:02 PM
    I'm also interested in how these thread-safety features cause an impact on performance, as my application mostly interacts with live audio, and using mutexes or similar to sync threads is not a viable solution to keep up with performance.
    k
    1 reply · 2 participants
  • b

    Big Chungus

    07/03/2021, 9:21 PM
    Is there a dev build of IDEA kotlin plugin with cinterops commonizer support somewhere out there? Everything builds fine with kotlinc dev build I'm using, but idea is unable to recognize my cinterops in intermediate sourceSet
    r
    l
    4 replies · 3 participants
  • m

    martmists

    07/03/2021, 10:55 PM
    How should I deal with resource cleanup on interrupt signals? I had a look at https://dev.to/mreichelt/handling-sigint-in-kotlin-native-2ac6 but it seems like a staticCFunction can't take local variables to stop the loop or similar.
    var loop = true
            // TODO: Make this compatible with windows
            signal(SIGINT, staticCFunction<Int, Unit> {
                loop = false
            })
            while (loop) {
                Pa_Sleep(20)  // Sleep 20ms
            }
            io.cleanup()
            Pa_Terminate()
    e
    n
    10 replies · 3 participants
  • m

    martmists

    07/04/2021, 11:03 AM
    How would I compile C/++ code to statically link against with the gradle plugin?
    n
    b
    +1
    15 replies · 4 participants
  • m

    martmists

    07/04/2021, 4:10 PM
    Is anyone else experiencing odd behavior across platforms? on linux, kotlin/native assumes an
    unsigned long
    is a ULong, but on windows it's parsed as
    UInt
    r
    9 replies · 2 participants
  • m

    martmists

    07/05/2021, 7:13 AM
    Is it common for gradle to run out of memory while compiling a k/n project? I have 16GB available but having only my DE and IJ running takes ~5GB RAM, but I need to exit IJ every 3 times or so just because it keeps running out of memory with the message "Daemon will be stopped at the end of the build after running out of JVM memory"
    d
    l
    +2
    11 replies · 5 participants
  • n

    neugartf

    07/05/2021, 5:22 PM
    Hey 🙂 Was anyone able to bundle a cocoapod dependency with this plugin? It generates the header of the kotlin code but the dependency is not included 🤔
    1 reply · 1 participant
  • c

    Clocks

    07/06/2021, 4:12 AM
    Is it possible to link one def file to another? For example, In my gtk kotlin library I want to separate the different headers of gtk into subprojects to lower build times while developing. If I were to have a def for each, I would have repeated bindings generated. IE GError then another GError then another GError. The idea is that, by linking one def as a requirement for another, It would just build on top of the previous def and not need to regenerate code TLDR; Dependencies of def for a def
    b
    n
    12 replies · 3 participants
  • k

    Karel Petránek

    07/06/2021, 2:44 PM
    Hi, I noticed there is a new "ios_simulator_arm64" target in the 1.5.20 native compiler. Can this already be used together with the multiplatform gradle plugin to compile projects for the M1 simulator? I can’t find anything in the docs but perhaps there’s a way to patch things together already?
    l
    4 replies · 2 participants
  • m

    Matthias Geisler

    07/07/2021, 6:45 PM
    Hello! I am currently exploring the world of kotlin-native in the context of a multiplatform project. However I have some newby problems with converting syntax. How I map
    NSData *nsdataFromBase64String = [[NSData alloc]initWithBase64EncodedString:base64Encoded options:0];
    into Kotlin? I understand what the function wants...but I do not catch the
    [NSData alloc]
    to write in Kotlin. Anybody here maybe knows that?
    s
    6 replies · 2 participants
  • b

    Big Chungus

    07/07/2021, 9:56 PM
    How do I allocate a pointer to pass in c function to store the result at? I am aware about
    memScoped { val result = alloc<T>() }
    , but with that the pointer is gone as soon as memScoped returns and I neet to keep reference to that pointer afer it treturns.
    1 reply · 1 participant
  • a

    ankushg

    07/07/2021, 10:51 PM
    Hey all, have a multiplatform, multi-module project that I'm upgrading from Kotlin 1.5.10 to 1.5.20 When I run
    ./gradlew iosX64Test
    on 1.5.10, everything passes When I run
    ./gradlew iosX64Test
    on 1.5.20, tests for one specific module are consistently giving me a segfault, both on my local machine and on CI (see thread for output) No other changes besides the version number. Any likely-culprit known issues in 1.5.20 that would cause this that I could follow on YT? Any tips on how to track down the issue or work around it?
    1 reply · 1 participant
  • s

    scavenger5

    07/08/2021, 9:01 PM
    I am accessing attributes in iOS (NSBundle.mainBundle().infoDictionary attributes) for my KMM project. I want to be able to mock this in unit tests. Any suggestions on how I can accomplish this?
    k
    1 reply · 2 participants
  • b

    Big Chungus

    07/09/2021, 10:13 AM
    Can I somehow build my project on OSX without shitty xcode installed (only xcode command line tools)?
    1 reply · 1 participant
  • b

    Big Chungus

    07/09/2021, 12:50 PM
    Getting the following error when running commonizer on cinterop (all osx targets + linuxX64)
    Exception in thread "main" java.lang.IllegalStateException: Resolved classifier platform/posix/__darwin_size_t of type TypeAlias. Expected: Class.
    Any tips?
    r
    12 replies · 2 participants
  • r

    ribesg

    07/09/2021, 1:58 PM
    I’m updating an app from Kotlin 1.4.10 to 1.5.20, and a lot of dependencies. It’s an app made with just the UI/View in Swift, Presenter/Model level stuff and above is all Kotlin, so it has a KMP project inside it named
    Mpp
    , which compiles into a Framework. I have this data class in the
    Mpp
    project:
    data class Event(
        // …
        val publicName: String?,
        // …
    ) {
    
        // …
    
        val hasPublicName: Boolean
            get() = !publicName.isNullOrBlank()
    
    }
    Somewhere in Swift, I have this:
    func configure(_ event: Event) {
            if event.hasPublicName {
                eventTypeLabel.isHidden = true
                locationView.isHidden = true
                publicNameLabel.isHidden = false
                publicNameLabel.text = event.publicName
        // …
    I didn’t change any of these files, but I now get this error (worked in 1.4.10):
    2021-07-09 15:46:41.834833+0200 MyApp[25797:9497146] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MppEvent hasPublicName]: unrecognized selector sent to instance 0x600001ae5650'
    Maybe I broke something in the way the project is built, but I don’t know what. I don’t know what could cause this. I also tried to replace
    event.hasPublicName
    in Swift with
    event.publicName != nil
    but then it crashes the same way but on
    publicName
    . I’m tweaking the XCode project a lot, and now I don’t know what could cause this?
    2 replies · 1 participant
  • b

    Big Chungus

    07/09/2021, 8:40 PM
    What gradle build do i run to download kotlin native tooling? I'm after bare-minimum work to get that tooling cached, so
    ./gradlew build
    is a bit too fat for my use case.
    s
    4 replies · 2 participants
Powered by Linen
Title
b

Big Chungus

07/09/2021, 8:40 PM
What gradle build do i run to download kotlin native tooling? I'm after bare-minimum work to get that tooling cached, so
./gradlew build
is a bit too fat for my use case.
s

scavenger5

07/09/2021, 9:24 PM
its currently a one time download, all of it goes to ~./.konan folder. Can you just run a full build once, then rely on the cached artifacts in the konan folder?
b

Big Chungus

07/09/2021, 10:20 PM
I know it's a one-time task, but I'm preparing a base docker image for my builds and would like to cache that. Otherwise they'll be downloaded each time I build via docker.
./gradlew assemble
seems to be lowest option so far, but that still runs through the entire compilation. I'd love to have
nodeJsSetup
like task that you could invoke explicitly...
s

scavenger5

07/09/2021, 10:52 PM
We did something semi custom. We had to set env variables KONAN_DATA_DIR and KONAN_DEPS to directories where we stored the kotlin native binaries. And the gradle property kotlin.native.home. So what we did was cache the libs in our own package, then referenced that package's directory, which avoided the download. This was mostly to make our IT happy. Not sure if it will help you.
View count: 3