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

    napperley

    07/09/2021, 11:55 PM
    Are there any known cases where using
    AtomicReference
    can cause a Kotlin Native program to terminate suddenly?
    k
    • 2
    • 2
  • j

    Jason5lee

    07/11/2021, 1:41 AM
    Is there a file IO library for Kotlin Native that supports Linux and maybe macOS or Windows? I’m writing a CLI program and Kotlin Native may help with improving experience. Should I just stick to JVM for CLI?
    r
    n
    +2
    • 5
    • 9
  • n

    napperley

    07/11/2021, 11:31 PM
    Is it possible to swap the linker (GCC Gold) that Kotlin Native (with Kotlin 1.5.0 onwards) uses for a newer version (also GCC Gold), and if so where is the linker located on a Linux host? Is gold the linker that Kotlin Native uses ( https://stackoverflow.com/questions/3476093/replacing-ld-with-gold-any-experience )? I'm wondering if the new linker used by Kotlin 1.5.0 makes linking significantly faster than Kotlin 1.4.31; are there any benchmarks available? From experience linking takes up about two thirds of the build time (painfully SLOW!) for a Kotlin Native program.
    e
    m
    • 3
    • 6
  • m

    martmists

    07/12/2021, 9:04 AM
    Is it possible to have an AtomicReference to a list? I'm getting this error:
    Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.ArrayList@1aa3f68
        at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x4169a9)
        at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x410c87)
        at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x410d97)
        at kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} (0x433557)
        at ThrowInvalidMutabilityException (0x434a76)
        at Kotlin_AtomicReference_checkIfFrozen (0x523c71)
        at kfun:kotlin.native.concurrent.AtomicReference#<init>(1:0){} (0x4328ae)
        at ...
    k
    d
    r
    • 4
    • 17
  • m

    MJegorovas

    07/12/2021, 9:30 AM
    Anybody could help me converting this obj-c code to kotlin (in thread):
    r
    • 2
    • 7
  • y

    y9san9

    07/12/2021, 2:20 PM
    Hello mates, while using Kotlin Multiplatform I came across a following issue in Swift. In kotlin we have awesome feature like
    Nothing
    type, I was trynna use it with generics in entity like
    Either
    .
    sealed interface Either<out TLeft, out TRight> {
        class Failure<T>(...) : Either<T, Nothing>
        class Success<T>(...) : Result<Nothing, T>
        
    }
    This is cool approach in Kotlin and everything works fine:
    val result: Either<Entity, Error> = result as Success<Entity>
    BUT in swift I can't do stuff like this:
    guard let result: Either<Entity, Error> = result as? Success<Entity> else { return }
    This will break at runtime, since swift generics aren't erased, and it won't pass type check (
    Nothing
    !=
    Error
    ). Any ideas how to workaround it? cc @alex009
    👀 1
    👍 1
    • 1
    • 1
  • n

    napperley

    07/12/2021, 11:22 PM
    In a Kotlin Multiplatform project that is targeting linuxArm32Hfp if Kotlin 1.5.0 or later is used then a boatload of undefined reference errors appear (at the linking stage), eg:
    /home/napperley/.konan/dependencies/arm-unknown-linux-gnueabihf-gcc-8.3.0-glibc-2.19-kernel-4.9-2/arm-unknown-linux-gnueabihf/bin/ld.bfd: /mnt/pi_image/usr/lib/arm-linux-gnueabihf/libgdk-3.so: undefined reference to `wl_display_dispatch_pending'
    However if Kotlin 1.4.31 is used then none of the errors appear, and the build is successful. In the build output there are a boatload of warnings about missing libraries (at the linking stage) if Kotlin 1.5.0 or later is used, eg:
    /home/napperley/.konan/dependencies/arm-unknown-linux-gnueabihf-gcc-8.3.0-glibc-2.19-kernel-4.9-2/arm-unknown-linux-gnueabihf/bin/ld.bfd: warning: libpcre.so.3, needed by /mnt/pi_image/usr/lib/arm-linux-gnueabihf/libglib-2.0.so, not found (try using -rpath or -rpath-link)
    Are there some additional linking options that need to be passed to the linker to resolve the errors, and if so which ones?
    a
    • 2
    • 23
  • n

    napperley

    07/12/2021, 11:37 PM
    There is a lack of documentation on the linking process when developing a Kotlin Native program. No information is present on the linker used in Kotlin 1.5.0 onwards for example. What would happen if someone wants to use a newer linker to resolve GLIBC version issues?
    c
    m
    • 3
    • 3
  • m

    Matthias Geisler

    07/14/2021, 7:56 AM
    Does anybody has experience with SwiftCrypto usage with Kotlin? I am asking since I am in need of crypto and to do it with objective-c interop looks super error prone.
    m
    s
    • 3
    • 5
  • i

    Iaroslav Postovalov

    07/15/2021, 3:13 PM
    Hello! I'm experiencing a very bizarre error with Kotlin/Native with
    mingwX64
    . My test process fails with
    -1073741515
    exit code and no output. When I've opened the
    test.exe
    binary with Dependency Walker, it gave out that binary can't be linked with some Microsoft binaries.
    👀 2
    m
    b
    • 3
    • 10
  • i

    Iaroslav Postovalov

    07/15/2021, 5:10 PM
    OK, now my problem is that
    ld
    successfully links against
    .lib
    file, but as the result
    .dll
    is lost, and the executable can't find it
    m
    • 2
    • 6
  • i

    Iaroslav Postovalov

    07/16/2021, 7:59 AM
    How to disable compilation of Native target but still have it in metadata?
    d
    b
    • 3
    • 7
  • i

    itnoles

    07/17/2021, 2:45 PM
    suspend fun fetch() : HttpResponse = suspendCoroutine {
        val semaphore = dispatch_semaphore_create(0)
        val nativeRequest = NSMutableURLRequest(uRL = NSURL.URLWithString("<https://api.spacexdata.com/v4/launches>")!!)
        nativeRequest.setHTTPMethod("GET")
        val result = AtomicReference(HttpResponse().freeze())
        val completionHandler = { nsData: NSData?, nsURLResponse: NSURLResponse?, nsError: NSError? ->
            if (nsError != null) {
                val message =
                    "The response is: " + nsURLResponse?.description() + ", error is: " + nsError.description()
                println(message)
            }
            val response = nsURLResponse as NSHTTPURLResponse
            val httpResponse = HttpResponse().apply {
                statusCode = response.statusCode.toInt()
                body = nsData?.bytes?.reinterpret<ByteVar>()?.toKString()
            }.freeze()
            result.value = httpResponse
            dispatch_semaphore_signal(semaphore)
            Unit
        }.freeze()
        val task =
            NSURLSession.sharedSession.dataTaskWithRequest(nativeRequest, completionHandler)
        task.resume()
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
        it.resume(result.value)
    }
    I really want to simplified this code. Can anyone help me with it?
    m
    • 2
    • 5
  • b

    Big Chungus

    07/17/2021, 10:43 PM
    If i build target C lib for cinterops on windows with Visual Studio CMAKE, is it expected to work? Or must i build target C libs on MSYS2/CYGWIN to make them "consumable" by K/N? Currently I'm getting this error when compiling kotlin executable on windows, while it works fine on OSX and Ubuntu
    Type mismatch: inferred type is bool /* = Byte */ but Boolean was expected
    m
    • 2
    • 1
  • b

    Big Chungus

    07/18/2021, 5:07 PM
    Trying to run a simple test on mingwX64 and getting this weird error
    Cause: cannot assign instance of java.util.Collections$EmptyList to field java.lang.StackTraceElement.moduleVersion of type java.lang.String in instance of java.lang.StackTraceElement
    The test
    import kotlin.test.Test
    import kotlin.test.assertEquals
    
    class TestMe {
       @Test
       fun shouldTest(){
          assertEquals("test", "test");
       }
    }
    Any pointers?
    r
    • 2
    • 6
  • u

    吴少滨

    07/21/2021, 3:51 AM
    I need to pass the data model to C++ from Kotlin Native. My current solution is serialization and deserialization through protocol, but as the level of model data increases, it takes more time to transfer the proto method. So I want to find a better solution to replace it. There are some questions about it. 1.Any better suggestions? 2.Now my idea is to create a data model directly in C++. But Kotlin/Native doesn't support C++Interop; Is there any way for Kotlin/Native to get/set the C++ model?
    n
    • 2
    • 1
  • c

    coolcat

    07/21/2021, 8:47 PM
    Has anyone had any success with the 
    native.cocoapods
     plugin recently? I am trying to write a KMM library whose iOS code depends on a cocoapod, which I import using
    cocoapods {
      pod("AFNetworking")
    }
    However 
    cinterop
     gives me
    fatal error: module 'AFNetworking' not found
    as in this issue. But I don’t think it’s the same problem. Anyone had similar?
    b
    i
    o
    • 4
    • 8
  • n

    napperley

    07/22/2021, 12:54 AM
    What does the early version of Kotlin 1.5.30 support in terms of platform code sharing with the C libraries (eg C pointers)?
    s
    • 2
    • 2
  • a

    AJ Alt

    07/23/2021, 3:47 PM
    With support for Apple Silicon being added in 1.5.30, will you be able to cross compile for the M1 chips from an Intel Mac?
    s
    l
    t
    • 4
    • 4
  • j

    Julius Hannink

    07/26/2021, 8:14 AM
    Same here, no idea what causes this 😐
    @ankushg
    any progress on your side?
    a
    • 2
    • 3
  • u

    吴少滨

    07/26/2021, 12:07 PM
    Is there any documents or demo about Kotlin/Native CInterop for first learning?The official documents can't make me understand. I just touched it not long ago.But CValue、CPointer、CValueVar、CValues and so on that confuses me.I need a simple or detail demo about that.😭
    c
    c
    • 3
    • 3
  • k

    kpgalligan

    07/27/2021, 11:59 PM
    Curious about "encoding" in
    @ObjCMethod
    annotation. We've been doing some experiments with cinterop and can successfully link and call to objc methods. As a concrete example, on iOS the objc class for Crashlytics is
    FIRCrashlytics
    . We only care about getting the global instance and logging a string, so after seeing what cinterop does, we just made this Kotlin class. It'll successfully link to the objc, and calls the methods as we expect.
    @ExternalObjCClass
    open class FIRCrashlytics : NSObject() {
        @ExternalObjCClass
        companion object : NSObjectMeta(), ObjCClassOf<FIRCrashlytics> {
            @ObjCMethod("crashlytics", "@16@0:8")
            external fun crashlytics(): FIRCrashlytics
        }
        @ObjCMethod(selector = "log:", encoding = "v24@0:8@16")
        open external fun log(msg: String)
    }
    👀 2
    m
    • 2
    • 5
  • k

    Kartik Prakash

    07/28/2021, 1:27 AM
    Does anyone have a good example a KMP library being published for iOS (Kotlin-Native)? Ideally we want to build a KMP library publish it and consume it in a pure iOS project Obj-C or Swift.
    m
    • 2
    • 4
  • b

    benkuly

    07/28/2021, 10:23 AM
    Hi, what's the difference between
    someByteArray.refTo(0)
    and
    someByteArray.pinned{it.addressOf(0)}
    ? Which of them should I use, when I call a native function? And what shoud I do, when the function wants
    CValuesRef<uint8_tVar /* = UByteVarOf<uint8_t /* = UByte */> */>
    ? Is it enough to do
    someByteArray.asUByteArray().refTo(0)
    ?
    👋 1
    ❓ 1
    m
    • 2
    • 3
  • l

    Landry Norris

    07/28/2021, 2:45 PM
    I noticed that I can't find SwiftUI in the platform package. Is there a timeline on when SwiftUI will be available in iosMain? I'm trying to get an expect/actual for state to use for SwiftUI/Compose. I'd like to be able to use the expect/actual to create the state variables in shared code. This works for Compose, but I can't get the iOS side working without a platform.SwiftUI
    r
    • 2
    • 2
  • m

    Matthias Geisler

    07/29/2021, 6:12 PM
    Are there any special moves besides obvious things to make the linker faster for iOS?
    s
    • 2
    • 4
  • n

    napperley

    07/30/2021, 3:13 AM
    I am trying to use the
    cairo_region_create_rectangles
    function ( https://www.cairographics.org/manual/cairo-Regions.html#cairo-region-create-rectangles ) from the Cairo library, but the function is after
    CValuesRef<cairo_rectangle_int_t>?
    as the first parameter and I don't know how to provide a
    CValuesRef
    that contains multiple struct pointers. Below is the code that fails to compile (the values variable doesn't match what the
    cairo_region_create_rectangles function
    is expecting):
    // ...
    fun createWithMultipleRectangles(vararg rectangles: IntRectangle): Region {
                val tmpArr = rectangles.map { it.cairoRect.ptr }.toTypedArray()
                val values = cValuesOf(*tmpArr)
                return Region(cairo_region_create_rectangles(values, rectangles.size))
            }
    // ...
    • 1
    • 1
  • t

    Tristan

    07/30/2021, 8:31 PM
    Hello, I have a class in Kotlin with methods such as
    class MyClass {
        private val arrayQueue = ArrayQueue<String>()
    
        fun save(item: String) {
            arrayQueue.add(item);
        }
    
        val last: String
            get() = arrayQueue.last()
    }
    I use it in objective C
    + (instancetype)sharedInstance {
        static NativeClass *nativeClass = nil;
        static dispatch_once_t onceToken;
    
        dispatch_once(&onceToken, ^{
            nativeClass = [[NativeClass alloc] init];
            nativeClass.myClass = [[MyClass alloc] init];
        });
    
        return nativeClass;
    }
    First of all, accessing it was an issue just to get
    .last
    , so I created a wrapper to get a frozen version.
    fun getMyClass() = MyClass().freeze()
    But by doing this, I cannot mutate it anymore
    kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen
    How can I overcome this kind of issue?
    • 1
    • 2
  • i

    iamsteveholmes

    07/30/2021, 8:40 PM
    Does anyone know how to upgrade to the latest App structure instead of AppDelegate and SceneDelegate? Asked this on #multiplatform https://kotlinlang.slack.com/archives/C3PQML5NU/p1627586038107100
    h
    • 2
    • 2
  • l

    Landry Norris

    08/02/2021, 3:28 PM
    Is there anywhere to track the progress of the new GC system? Freezing tends to interfere with other thread-safe methodologies (as the original article on freezing suggests), so the fact that the K/N team suggested that the new GC will not require freezing is helpful. In May, they estimated a dev preview would be available by end of Summer, which is getting close.
    r
    • 2
    • 4
Powered by Linen
Title
l

Landry Norris

08/02/2021, 3:28 PM
Is there anywhere to track the progress of the new GC system? Freezing tends to interfere with other thread-safe methodologies (as the original article on freezing suggests), so the fact that the K/N team suggested that the new GC will not require freezing is helpful. In May, they estimated a dev preview would be available by end of Summer, which is getting close.
r

russhwolf

08/02/2021, 3:46 PM
It's not documented but you can try it out in 1.5.30-M1. Need to pass
-memory-model experimental
as compiler args
😲 4
👀 1
👍 3
😍 2
l

Landry Norris

08/02/2021, 3:47 PM
Thank you. I'll try this out. Do you happen to know where you found out about this arg? I'd like to be able to track the progress of this.
r

russhwolf

08/02/2021, 3:50 PM
If you want to watch a ticket, I don't know anything better than the roadmap at https://youtrack.jetbrains.com/issue/KT-42296 which doesn't go into detail. I found the flag from a mention in a coroutines issue somewhere. I expect we'll hear more about it closer to 1.5.30 release but we'll see
You might also need
kotlin.native.cacheKind=none
in gradle.properties
👀 1
View count: 1