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

    Luigi Scarminio

    11/22/2021, 12:17 PM
    If I instantiate an object from Kotlin Native inside a Swift function, who deals with the GC when Swift function finishes its scope?
    m
    • 2
    • 4
  • s

    spierce7

    11/22/2021, 3:20 PM
    I’m curious, why couldn’t Kotlin/native get the performance numbers it was expecting with ARC? Swift uses ARC and gets solid performance with LLVM.
    d
    • 2
    • 6
  • b

    Big Chungus

    11/22/2021, 3:29 PM
    e: java.lang.IllegalStateException: Unsupported Xcode version 12.4, minimal supported version is 12.5.
    Looks like kotlin 1.6.0 apply targets are not supported in GH actions due to old xcode. Is there any workaround for this?
    ✅ 2
    j
    k
    i
    • 4
    • 4
  • b

    benkuly

    11/23/2021, 3:58 PM
    Using Kotlin 1.6.0 this test runs on JVM, but native does not sort properly:
    @Test
    fun test() {
        val input = listOf("本", "日")
        val output = input.sorted()
        val expected = listOf("日", "本")
        assertEquals(expected, output)
    }
    • 1
    • 1
  • n

    Nikky

    11/24/2021, 11:50 AM
    i am trying to build a mingw64 binary on linux, as kotlin 1.6.0 shopuld support that now, but i also use ktor in there and am not sure which dependency i am missing to make it link libcurl
    > Task :linkReleaseExecutableMingwX64 FAILED
    e: /home/nikky/.konan/dependencies/llvm-11.1.0-linux-x64-essentials/bin/clang++ invocation reported errors
    
    The /home/nikky/.konan/dependencies/llvm-11.1.0-linux-x64-essentials/bin/clang++ command returned non-zero exit code: 1.
    output:
    lld: error: unable to find library -lcurl
    clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
    anyone got this to work yet ?
    m
    h
    m
    • 4
    • 13
  • z

    Zode

    11/30/2021, 8:09 AM
    Is there any way for K/N to generate framework for OC only? Many times we don’t need to use both OC and Swift, and generating framework for both languages will increase package size significantly i thought.
    s
    • 2
    • 3
  • i

    Iain Merrick

    12/02/2021, 5:22 PM
    Is there any option to generate purely single-threaded code? For my use cases, I feel like it might be easier to make stuff work in one thread than to debug multithreading issues.
    s
    j
    • 3
    • 6
  • d

    Draget

    12/02/2021, 8:28 PM
    Something I am confused about: I am creating a Kotlin Native application in IDEA and it creates a build.gradle.kts with 'repositories { mavenCentral() }. I somehow expected the Kotlin Native code not to work with JVM code - why would it include the repository for JVM dependencies?
    b
    e
    l
    • 4
    • 17
  • d

    Draget

    12/02/2021, 8:52 PM
    Does Konan require ncurses 5? The current version is 6, which I have installed. And yet I get the error:
    /home/draget/.konan/dependencies/clang-llvm-8.0.0-linux-x86-64/bin/clang++: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    (I have libtinfo.so.6)
    j
    s
    • 3
    • 5
  • d

    Draget

    12/02/2021, 9:12 PM
    I recently update to IDEA 2021.3 - my bundles Kotlin Plugin shows as
    213-1.5.10-release-949-IJ5744.223
    .
    Shouldn't it be
    212-1.6.0-release-799-IJ5457.46
    ? =/
    No updates offered from IDEA. Looking at the #intellij channel, it seems like it 2021.3 does not support the most recent Kotlin plugin. As much as I love Jetbrains, the update-experience of IDEA has been a total trainwreck every time, and this time is no different. Starting to loose my motivation for the Kotlin/Native experiment here… <.< I'll start fresh tomorrow.
    b
    i
    n
    • 4
    • 9
  • r

    rudolf.hladik

    12/03/2021, 2:19 PM
    Hello there, is there a way to have
    deinit
    function in Kotlin? it would be fine to have that feature at least at
    nativeMain
    module
    k
    • 2
    • 1
  • r

    Rob Elliot

    12/05/2021, 1:42 PM
    Hi, I’m trying to write a little CLI app in kotlin-native. I’d like to produce executables to work on all Linux distros and both macOS distros. Obviously I get that the Linux & macOS executables will need to be different, and that the macOS executables will need to be different too. I’ve been reading, and failing to understand, this thread: https://youtrack.jetbrains.com/issue/KT-38876 I think the takeaway is that you can’t build on a particular distro and then reliably shift the resulting executable between all Linux distros because it links to dependencies that may or may not be there - is that correct?
    m
    • 2
    • 5
  • n

    natario1

    12/05/2021, 8:50 PM
    cinterop question - trying to emulate:
    JavaVM* vm;
    GetJavaVM(&vm);
    With kotlin.cinterop types and my solution seems so verbose. Are there better APIs that I'm missing?
    val vm: CPointerVar<JavaVMVar> = allocPointerTo()
    val vm2: CPointerVar<CPointerVar<JavaVMVar>> = allocPointerTo()
    vm2.pointed = vm
    GetJavaVM(vm2.value!!)
    j
    p
    • 3
    • 7
  • z

    zt

    12/07/2021, 6:10 PM
    How can I get my build size smaller?
    j
    n
    +2
    • 5
    • 6
  • n

    napperley

    12/09/2021, 4:25 AM
    I have found what looks like a bug involving the new memory model, and C String arrays. Here is the project (doesn't contain the line that causes the bug): https://gitlab.com/napperley/lvgl-hello/-/tree/keypad-encoder The bug revolves around freeing memory after calling a function from a C library (LVGL - https://lvgl.io/ ). When starting the program a message box appears containing two buttons. The first button has no text, but the second button contains some text (Cancel). If the memory isn't freed then the first button contains some text (Ok). Appending the following line to src/linuxArm32HfpMain/kotlin/main.kt file after line 180 ( https://gitlab.com/napperley/lvgl-hello/-/blob/keypad-encoder/src/linuxArm32HfpMain/kotlin/main.kt#L180 ) causes the bug to occur:
    tmpArena.clear()
    a
    • 2
    • 4
  • m

    MJegorovas

    12/09/2021, 2:13 PM
    Need help with translating this code to kotlin:
    - (void) MonitorWifiInterface
    {
        m_pathMonitor = nw_path_monitor_create();
        
        nw_path_monitor_set_update_handler(m_pathMonitor, ^(nw_path_t  _Nonnull path) {
            NSLog(@"[NetInterfaceUtilies] Network path changed");
         });
     
         nw_path_monitor_start(m_pathMonitor); 
    }
    Have no idea what to do in
    ^(nw_path_t  _Nonnull path)
    part
    • 1
    • 3
  • b

    Brian Donovan

    12/09/2021, 3:21 PM
    Hello all, I’m not sure why my logcat is not updating when I fill in the email and password. Any help please. All the other commented out Logs work.
    m
    n
    • 3
    • 2
  • a

    Alexander Black

    12/10/2021, 1:26 AM
    Hey all, I'm wondering if there's a flag or something in my gradle build that I need to set in order to play with the new 1.6 native memory management system or is it enabled by default? I couldn't seem to find any documentation on the topic.
    e
    • 2
    • 2
  • z

    zt

    12/11/2021, 6:07 AM
    How can I alloc an array of Longs using allocArrayOf?
    d
    • 2
    • 2
  • m

    martmists

    12/11/2021, 4:22 PM
    How would I write the following in K/N?
    static PyObject *
    spam_system(PyObject *self, PyObject *args)
    {
        const char *command;
        int sts;
    
        if (!PyArg_ParseTuple(args, "s", &command))
            return NULL;
    
        // ...
    
        return Py_INCREF(Py_None);
    }
    What I've got so far:
    private val spamSystem = staticCFunction { self: PyObjectT, args: PyObjectT ->
        val command = ???
    
        if (PyArg_ParseTuple(args, "", ???) == 0) {
            return@staticCFunction null
        }
    
        // ...
    
        Py_None.incref()
    }
    d
    • 2
    • 1
  • m

    martmists

    12/11/2021, 7:45 PM
    it's as if it allocates it and copies it over instead of getting a pointer to the static one
    💯 1
    d
    • 2
    • 2
  • b

    Brian Donovan

    12/13/2021, 1:12 AM
    Hi All, I am a noob but how come this is giving me red?
    b
    a
    j
    • 4
    • 4
  • c

    Clocks

    12/13/2021, 6:57 AM
    Is there any designated moderators we can ping? Brian is clearly a scam account from their actions
    e
    • 2
    • 1
  • b

    Bailey Pollard

    12/13/2021, 7:40 PM
    Hey, is anyone able to give me an example on how to create a variable that would conform to this type?
    value: kotlinx.cinterop.CValuesRef<platform.posix.uint8_tVar>
    d
    n
    • 3
    • 9
  • z

    Zode

    12/14/2021, 3:29 AM
    What does this function
    RUNTIME_NOTHROW void Kotlin_initRuntimeIfNeeded()
    do? This function is in
    kotlin/kotlin-native/runtime/src/main/cpp/Runtime.cpp
    . 1. I found it got called all the time when trying to run my iOSApp, then I got a runtime exception when it ran into
    InitOrDeinitGlobalVariables(INIT_GLOBALS, result->memoryState);
    . It looks like the runtime environment had not fully created at that point, and it has already called OC bridge function, then caused an exception. 2. I also found another problem when using k/n. Top-level properties declared in kotlin will always return null when running iOSApp. I made it a top-level function and it worked. This problem also happened when KN was running into
    Kotlin_initRuntimeIfNeeded()
    . 3. btw, debug shared.framework and k/n lib with disasm showed in lldb is tough. Is there any way to debug k/n from source when running iOSApp? Does anyone has any idea here?
    j
    n
    • 3
    • 8
  • m

    My Nguyen

    12/14/2021, 9:26 AM
    Just for fun. Let's guess the output result.
    data class MyNumber(
        var x: Int
    ) {
        val isBig1: Boolean = x >= 10
    
        val isBig2: Boolean
            get() = x >= 10
    }
    
    fun main() {
        val number = MyNumber(9)
        println("isBig1 before: ${number.isBig1}")
        println("isBig2 before: ${number.isBig2}")
        number.x = 11
        println("isBig1 after: ${number.isBig1}")
        println("isBig2 after: ${number.isBig2}")
    }
    👀 1
    r
    • 2
    • 1
  • m

    martmists

    12/15/2021, 10:05 AM
    When calling variadic C functions spread operator is supported only for *arrayOf(...)
    How can I avoid this? Can I write a wrapper function in the .def or something? I already tried
    *arrayOf(*x.map { ... }.toTypedArray())
    but that was also invalid?
    r
    j
    • 3
    • 12
  • b

    Benoye

    12/15/2021, 1:56 PM
    Hi all ! Beginner question here, let’s say I define an extension in
    iosMain
    :
    fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply {
        usePinned {
            memcpy(it.addressOf(0), this@toByteArray.bytes, this@toByteArray.length)
        }
    }
    This one allows to convert a
    NSData
    in Objective-C to a
    ByteArray
    in Kotlin Is it possible to use this function directly in XCode on a
    NSData
    object ?
    m
    r
    • 3
    • 3
  • z

    Zode

    12/17/2021, 3:52 AM
    dependencies {
        add(PLUGIN_CLASSPATH_CONFIGURATION_NAME, Dependencies.xxxx)
    }
    Does adding this plugin to k/n take effect during k/n compilation(for iOS)? It looks like this plugin doesn’t work.
    j
    • 2
    • 3
  • c

    caffeine

    12/17/2021, 11:01 PM
    Hi. How I can handle shutdown of my k/n application? (without listening OS signals)
    n
    j
    • 3
    • 6
Powered by Linen
Title
c

caffeine

12/17/2021, 11:01 PM
Hi. How I can handle shutdown of my k/n application? (without listening OS signals)
n

napperley

12/17/2021, 11:19 PM
Are you talking about a program running on a Unix based OS (eg Linux)?
c

caffeine

12/17/2021, 11:29 PM
Yep. Linux, Windows (MinGW), Macos
console application
n

napperley

12/17/2021, 11:53 PM
As far as I'm aware listening to OS signals is the only way on Unix based platforms. Windows by the way isn't a Unix based OS (eg doesn't use the POSIX library).
c

caffeine

12/18/2021, 12:09 AM
Yes, i known. Now I handle terminate using signals. But this is not convenient if you are writing some kind of library
j

jimn

12/18/2021, 1:48 PM
check a kill-switch in the inner most event loop
View count: 3