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

    v79

    11/25/2020, 9:10 AM
    Is there a current guide to creating a Kotlin native library with gradle anywhere? https://kotlinlang.org/docs/reference/native/gradle_plugin.html makes reference to things like:
    components.main {
        // Compile the component into an executable and a Kotlin/Native library.
        outputKinds = [EXECUTABLE, KLIBRARY]
    }
    Which we all know doesn't work,
    components.main
    is completely invalid syntax. I tried creating an empty Kotlin/Native library using Intellij's new project wizard did not add anything like
    outputKinds = KLIBRARY
    .
    a
    • 2
    • 10
  • f

    Frankablu

    11/26/2020, 6:55 PM
    I would like to read/write to a text file in windows. How do I do that?
    • 1
    • 1
  • n

    napperley

    11/26/2020, 9:15 PM
    Here are some good questions for today: 1. Are C Libraries targeting ARM11 ( https://en.wikipedia.org/wiki/ARM11 ) compatible with Kotlin Native? 2. If the C libraries are compatible would they work with the linuxArm32Hfp (ARMv7), and linuxArm64 (ARMv8) targets? This is the C library I intend to use in a prototype type project: https://github.com/eclipse/paho.mqtt.c
    a
    • 2
    • 2
  • s

    serebit

    11/27/2020, 6:40 PM
    Will 1.4.20 be tagged in the Kotlin/Native GitHub repository?
    a
    • 2
    • 2
  • f

    Frankablu

    11/27/2020, 9:16 PM
    What does "Uncaught Kotlin exception: kotlin.IllegalStateException: Illegal transfer state" in the context of using concurrency workers mean and how do I avoid it?
    a
    • 2
    • 7
  • v

    v79

    11/28/2020, 4:56 PM
    Can anyone make sense of this
    Event
    class? https://github.com/JetBrains/kotlin-native/blob/master/samples/weather_function/function/src/main/kotlin/org/example/weather_func/events.kt ? I'm trying to understand how the libcurl examples from the Kotlin native samples code work. It only seems to work for short HTTP responses; when libcurl starts chunking larger responses I lose most of it.
    t
    • 2
    • 1
  • n

    napperley

    11/30/2020, 12:15 AM
    After updating the KMQTT Client library ( https://gitlab.com/napperley/kmqtt-client ) to use Kotlin 1.4.0 the callback handling breaks. What changes were made to CFunction in Kotlin 1.4.0?
    l
    • 2
    • 4
  • a

    Arkadii Ivanov

    11/30/2020, 4:00 PM
    Hello! I'm playing with SQLDelight + Kotlin Multiplatform + iOS, and trying to create a test in-memory database for unit tests. I'm using the following code:
    TodoDatabase(
            NativeSqliteDriver(
                DatabaseConfiguration(
                    name = "",
                    version = 1,
                    create = { wrapConnection(it, TodoDatabase.Schema::create) },
                    inMemory = true
                )
            )
        )
    I added some logs and it seems that it actually executes Schema.create. However all queries to this database in tests are failing with errors like
    no such table
    . Also I see the following message in the logs: Invalid connection:
    com.apple.coresymbolicationd
    . Not sure if it is related actually. Could somebody give me some advice?
    k
    r
    b
    • 4
    • 6
  • l

    Luigi Scarminio

    11/30/2020, 4:29 PM
    I have updated my intellij to 2020.2.4. My Kotlin plugin is updated too. I am using Kotlin 1.4.20. I'm trying to create a new multiplatform library. But everytime I try to create an "actual" implementation of an "expected" class, I get this this error: - Cannot perform operation. Too complex, sorry. Anyone had this issue also?
    m
    • 2
    • 2
  • a

    Arkadii Ivanov

    11/30/2020, 8:27 PM
    More questions about SQLDelight + iOS from my side 🙂 1. I am creating a new in-memory database instance for every test case. But on iOS it may contain data from previous test cases. On Android it is always clean. Is it expected behaviour? 2. Looks like last_insert_rowid() does not work on iOS, but works on Android. Is it just not implemented yet?
    b
    r
    +3
    • 6
    • 17
  • n

    napperley

    12/01/2020, 3:23 AM
    In a callback a kotlin.native.IncorrectDereferenceException is thrown after fetching a Stable Reference. Below is the stack trace:
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared org.digieng.kmqtt.client.MqttClient@add4d8 from other thread
        at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x2a7e09)
        at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x2a1a07)
        at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x2a1bb7)
        at kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} (0x2cb1c7)
        at ThrowIllegalObjectSharingException (0x2cd977)
        at  (0x3e4acb)
        at _ZNK16KRefSharedHolder3refIL11ErrorPolicy2EEEP9ObjHeaderv (0x3e48f3)
        at Kotlin_Interop_derefStablePointer (0x3e488e)
        at kfun:kotlinx.cinterop.StableRef#get(){}1:0 (0x2692e6)
        at kfun:org.digieng.kmqtt.client.onDeliveryComplete#internal (0x37522e)
        at _6f72672e64696769656e673a6b6d7174742d636c69656e74_knbridge46 (0x37602b)
        at MQTTClient_cycle (0x410d46)
        at MQTTClient_run (0x40c4dd)
        at  (0x7f7a508b56db)
        at clone (0x7f7a503c6a3f)
        at  ((nil))
    Aborted (core dumped)
    What is the way to resolve this issue? Note that the Linux platform is used as the target, which does allow for multi-threading. However the synchronous version of the Paho MQTT library is used which is single threaded.
    • 1
    • 1
  • a

    Animesh Sahu

    12/02/2020, 6:59 AM
    Creating a mutable variable in a singleton results in the following warning:
    object MySingleton {
        private var testingVar = false
    }
    Variable in singleton without @ThreadLocal can't be changed after initialization.
    On annotating with @ThreadLocal results in error:
    @ThreadLocal is applicable only to top level declarations
    t
    • 2
    • 9
  • v

    v79

    12/02/2020, 7:07 AM
    I had been a bit frustrated with the lack of proper date/time support in Kotlin/Native, especially for my chosen platform,
    linuxArm32Hfp
    for the Raspberry Pi. So I checked out the kotlinx-datetime code, and took a look - perhaps I could make it work? After all, what's the different between
    linuxX64
    and
    linuxArm32Hfp
    - both are POSIX, both are likely to include the same core libraries. It turns out, there isn't a difference - I took kotlinx-datetime, added a single line to
    build.gradle.kts
    - I added
    target("linuxArm32Hfp")
    , compiled, deployed to maven local, and it worked. I was able to use kotlinx-datetime in my Raspberry Pi code just fine. I haven't fully tested it, but for my simple use case, it seems to be working just fine. So I'm beginning to wonder, what other Kotlin/Native libraries will 'just work' on "unsupported" platforms with just a small change to the build configuration?
    🤔 2
    a
    • 2
    • 1
  • a

    Animesh Sahu

    12/02/2020, 3:18 PM
    message has been deleted
    t
    • 2
    • 2
  • m

    mkrussel

    12/02/2020, 4:25 PM
    Intellij is unable to resolve any of the references for classes that come from cinterop. All of the code is in
    iosMain
    source set. This used to work correctly but has not for awhile. I've tried invalidating my cache, doing a full build, but the warnings will not go away. I'm using 2020.3 community edition. Kotlin plugin 203-1.4.10-relase-IJ5981.133 Kotlin 1.4.10 Is this a known problem or just something broken with me
    m
    • 2
    • 4
  • h

    HankG

    12/02/2020, 7:04 PM
    I'm trying to work with Kotlin Native, Kotlin Multiplatform, and KMM, on Apple Silicon...anyone else here got that working?
    m
    • 2
    • 9
  • h

    HankG

    12/02/2020, 7:11 PM
    under a native JVM (Azul Systems) it complains about compatible dylibs, I'm guessing it's downloading the x64 ones or can't differentiat between processors with macOS?
    k
    n
    • 3
    • 18
  • n

    napperley

    12/02/2020, 11:40 PM
    Seems as though the issue I am running into is a severe bug with Kotlin Native's memory model when Kotlin Coroutines are used, and C callbacks are involved. Below is the stack trace:
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared org.digieng.kmqtt.client.MqttClient@66c4d8 from other thread
        at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x2a7e09)
        at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x2a1a07)
        at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x2a1bb7)
        at kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} (0x2cb1c7)
        at ThrowIllegalObjectSharingException (0x2cd977)
        at  (0x3e4b1b)
        at _ZNK16KRefSharedHolder3refIL11ErrorPolicy2EEEP9ObjHeaderv (0x3e4943)
        at Kotlin_Interop_derefStablePointer (0x3e48de)
        at kfun:kotlinx.cinterop.StableRef#get(){}1:0 (0x2692e6)
        at kfun:org.digieng.kmqtt.client.onDeliveryComplete#internal (0x37529e)
        at _6f72672e64696769656e673a6b6d7174742d636c69656e74_knbridge46 (0x37609b)
        at MQTTClient_cycle (0x410d96)
        at MQTTClient_run (0x40c52d)
        at  (0x7f4eb1b756db)
        at clone (0x7f4eb1686a3f)
        at  ((nil))
    Aborted (core dumped)
    After examining the libcurl ( https://github.com/JetBrains/kotlin-native/tree/master/samples/libcurl ) and curl ( https://github.com/JetBrains/kotlin-native/tree/master/samples/curl ) Kotlin Native samples there are two major differences (stuff not present). First difference is that the initRuntimeIfNeeded function isn't called inside the event handlers (C callbacks), and the second difference is that Kotlin Coroutines aren't used. Is the issue that is being encountered one of the corner cases mentioned in the article ( https://blog.jetbrains.com/kotlin/2020/07/kotlin-native-memory-management-roadmap/ )? Would highly appreciate some guidance from the Kotlin Native team on using Kotlin Coroutines with Kotlin Native's memory model (guides, key things to avoid, best practices etc).
    • 1
    • 1
  • a

    Animesh Sahu

    12/03/2020, 5:00 AM
    Is yielding (yield) from a
    memScoped{}
    block safe/ok?
    d
    • 2
    • 3
  • m

    mkrussel

    12/03/2020, 4:35 PM
    Does anyone know how to get frameworks to be found when running unit tests. I have a module that depends on another module which is using cinterops to talk to an iOS framework. I was able to get the test app to build by adding this.
    kotlin {
        ios {
            val frameworkLocation = File(rootDir, "native/TestApp/Pods/Mapbox-iOS-SDK/dynamic/").absolutePath
            val frameworks = "-F$frameworkLocation"
    
            binaries.configureEach {
                linkerOpts(frameworks)
            }
        }
    }
    I get the following error when it runs the tests.
    dyld: Library not loaded: @rpath/Mapbox.framework/Mapbox
      Referenced from: /Users/mkrussel/pangea/pangea-android/test-app-shared/build/bin/iosX64/debugTest/test.kexe
      Reason: image not found
    👀 2
    a
    • 2
    • 4
  • a

    Animesh Sahu

    12/04/2020, 5:20 AM
    How to include a header whose definition may be present or absent the host machine? I want to check that on runtime, and if was absent I wanna use a fallback. By the way if you wanted to know the use case, I wanted to do this for X11 header, as some linux may have a desktop and some don't...
    👀 1
    • 1
    • 1
  • a

    Animesh Sahu

    12/04/2020, 11:15 AM
    I'm not able to generate Kotlin bindings for C headers on WSL using the gradlew, the task runs and in under 3 seconds build gets successful and no bindings are getting generated. Anybody encountered the issue, and any solutions?
    a
    • 2
    • 6
  • a

    Alex Gladkov

    12/04/2020, 3:46 PM
    Hello, does anybody know how to specify KMM module in iOS project? I have core data model ("Order" for example) and have Order in my KMM Module, so xcode can't resolve from which module model is.
    k
    • 2
    • 5
  • k

    kevin.cianfarini

    12/04/2020, 7:26 PM
    Are polymorphic calls in Kotlin/Native static or dynamic?
    👀 1
    d
    • 2
    • 44
  • a

    Animesh Sahu

    12/05/2020, 4:24 AM
    Can I debug it further, I don't see where could a worker be leaked?
    Unfinished workers detected, 1 workers leaked!
    Use `Platform.isMemoryLeakCheckerActive = false` to avoid this check.
    Here's a small repro:
    object Testing {
        val event = MutableSharedFlow<Int>(extraBufferCapacity = 8)
    
        init {
            event.subscriptionCount
                    // .onEach { println("Subscription Count: $it") }  // Stub, For seeing the behavior
                    .launchIn(CoroutineScope(Dispatchers.Unconfined))
        }
    }
    
    fun main() = runBlocking {
        Testing
    }
    Edit: Sometimes the following error is generated as well:
    Memory leaks detected, 76 objects leaked!
    Use `Platform.isMemoryLeakCheckerActive = false` to avoid this check.
    d
    n
    • 3
    • 14
  • a

    Animesh Sahu

    12/05/2020, 4:04 PM
    Is there way to create CPointer of Kotlin Objects?
    • 1
    • 1
  • a

    Animesh Sahu

    12/05/2020, 4:42 PM
    Is there way to create sth like
    commonNativeMain
    module for all native modules? If yes how, and how to access kotlin.native packages there. I tried using
    val commonNativeMain by creating { ... }
    But that doesn't seem to access kotlin.native packages...
    d
    k
    • 3
    • 6
  • v

    v79

    12/05/2020, 9:58 PM
    Are enums always 'frozen' after creation? Is there any way around that?
    m
    d
    b
    • 4
    • 4
  • a

    Animesh Sahu

    12/06/2020, 10:52 AM
    How do you include some cinterop headers in a library? I've added the headers like this
    linuxX64 {
        val main by compilations.getting
        main.cinterops.create("x11") {
            defFile("src/linuxX64Main/cinterop/x11.def")
            compilerOpts.add("-I" + rootDir.resolve("include"))
        }
    }
    library compiles fine, and published to mavenLocal fine, but when some other project add it as a dependency and runs the linker, it produces the following
    > Task :linkReleaseExecutableLinuxX64
    e: C:\Users\Animesh\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/ld.lld invocation reported errors
    
    The C:\Users\Animesh\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/ld.lld command returned non-zero exit code: 1.
    output:
    ld.lld: error: undefined symbol: XOpenDisplay
    >>> referenced by out
    >>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#prepare(){})
    
    ld.lld: error: undefined symbol: XPeekEvent
    >>> referenced by out
    >>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#readEvents(){})
    
    ld.lld: error: undefined symbol: XCloseDisplay
    >>> referenced by out
    >>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#cleanup(){})
    
    > Task :linkReleaseExecutableLinuxX64 FAILED
    Don't the c-interop symbols get shipped with the artifact?
    n
    • 2
    • 1
  • p

    Paul Woitaschek

    12/07/2020, 1:19 PM
    Shouldnt the commonizer use some sort of caching? I have about 6 gradle modules and whenever I change something with the targets it runs the commonizer on each of them taking about 25 minutes on my mbp2019
    a
    • 2
    • 1
Powered by Linen
Title
p

Paul Woitaschek

12/07/2020, 1:19 PM
Shouldnt the commonizer use some sort of caching? I have about 6 gradle modules and whenever I change something with the targets it runs the commonizer on each of them taking about 25 minutes on my mbp2019
a

Artyom Degtyarev [JB]

12/07/2020, 1:33 PM
Found a ticket for this, please have a look: https://youtrack.jetbrains.com/issue/KT-42098 If it seems related, consider upvoting it and subscribing for updates.
👍 1
View count: 3