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

    saket

    09/08/2019, 2:55 AM
    Do folks here prefer using IntelliJ IDEA for writing Kotlin Native over Android Studio?
    g
    s
    +3
    • 6
    • 16
  • n

    napperley

    09/08/2019, 9:04 AM
    Is there a way to add C definitions for a built-in C library (varies by Kotlin Native target) without having to do monkey patching (https://en.wikipedia.org/wiki/Monkey_patch)?
    s
    o
    m
    • 4
    • 12
  • s

    Sam Schilling

    09/09/2019, 5:42 PM
    Anyone else experienced any issues with NSObjects never being deallocated on macOS? This seems like a very serious issue as it means any application that uses NSObjects is exposed to memory leaks. I created an issue to track but it would be great to know if anyone else experiences this behavior. If so it would be great to upvote to gain exposure 🙂 https://youtrack.jetbrains.com/issue/KT-33780
    o
    • 2
    • 2
  • s

    Slackbot

    09/09/2019, 10:26 PM
    This message was deleted.
    k
    o
    +3
    • 6
    • 8
  • s

    Sam Schilling

    09/10/2019, 9:52 PM
    General question here: since Kotlin/Native supports exporting iOS frameworks that get compiled to Objective-C, is it preferable to develop host applications that use the framework in Objective-C as well instead of Swift? Are there any known issues with using K/N-compiled Objective-C frameworks in Swift?
    k
    s
    o
    • 4
    • 3
  • r

    robjperez

    09/11/2019, 10:10 AM
    Hi there!, Have a question about K/N. Is it possible to use it as a replacement for JNI?. I have a cross-platform written in C/C++ library that I use for ios/android, Can I call this library from an Android application using Kotlin/Native?
    🇳🇴 2
    d
    n
    • 3
    • 9
  • r

    ribesg

    09/12/2019, 8:30 AM
    What should I write in Kotlin that would result in a static class function seen from Swift?
    s
    l
    • 3
    • 6
  • r

    ribesg

    09/12/2019, 9:59 AM
    I’ve got a
    kotlin.native.concurrent.InvalidMutabilityException
    that I can’t explain.
    companion object {
    
            internal var xs: Set<X> by atomic(HashSet())
                private set
    
            fun registerX(x: X) {
                xs = xs + x
            }
    
        }
    atomic
    being:
    inline fun <reified T> atomic(initial: T) = AtomicDelegate(initial)
    AtomicDelegate
    being:
    class AtomicDelegate<T>(initial: T) : ReadWriteProperty<Any?, T> {
    
        private val atomic = AtomicReference(initial)
    
        override fun getValue(thisRef: Any?, property: KProperty<*>): T =
            atomic.get()
    
        override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
            atomic.set(value)
        }
    
    }
    And
    AtomicReference
    here is:
    internal actual class AtomicReference<T> actual constructor(initial: T) {
    
        private val atomic =
            kotlin.native.concurrent.FreezableAtomicReference(initial)
    
        actual fun get(): T =
            atomic.value
    
        actual fun set(newValue: T) {
            atomic.compareAndSet(get(), newValue)
        }
    
    }
    The app crashes when
    registerX
    is called:
    Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashSet@221c288
    Where in my code am I attempting to modify a frozen
    HashSet
    ? I’m pretty sure I’m just creating a new local one, modifying it, then assigning it which makes it frozen (that’s what the
    +
    does)
    m
    d
    l
    • 4
    • 22
  • n

    Nabil

    09/12/2019, 1:15 PM
    There might be an issue with the Stub generator which causes ObjC properties prefixed with
    new
    to produce non compiling code, I created an issue https://github.com/JetBrains/kotlin-native/issues/3336 in case others are also experimenting with using Cocoapods dependencies and hitting an `this annotation is not applicable to target 'getter'`…
    o
    • 2
    • 3
  • e

    Erik Christensen

    09/12/2019, 2:03 PM
    I have code in an iosMain source set that's shared between the iosArm64 and iosX86 targets. With this setup, I'm not able to get code completion for iOS platform calls in Intellij. Is there a way to instruct it to use one of the two iOS targets just for the purposes of code completion in the editor?
    k
    k
    +3
    • 6
    • 33
  • o

    Oren Idan

    09/13/2019, 6:19 AM
    Does anyone know when
    1.3.60
    will be out? I need to support more than 22 properties in SQLDelight... https://github.com/JetBrains/kotlin-native/issues/3072
    g
    l
    • 3
    • 5
  • s

    Sebastian Keller

    09/13/2019, 2:12 PM
    Hi, is there a way to try/catch an
    IncorrectDereferenceException
    ? I want to use the iOS CMAltimeter class, but it's callback gets called from a non-main-thread when
    altimeter?.stopRelativeAltitudeUpdates()
    is called. I tried a surrounding
    try
    and
    catch
    , but no luck. I can not freeze the callback, because that would freeze
    update()
    too. I really don't know what else to do right now.
    altimeter = CMAltimeter()
                altimeter?.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue) { data: CMAltitudeData?, error: NSError? ->
                    update(data.pressure.doubleValue)
                }
    Can the relaxed mode help? If so, how to enable it?
    k
    k
    o
    • 4
    • 15
  • s

    Sam Schilling

    09/13/2019, 4:50 PM
    I have a feeling there may be some potential memory leak with the way Kotlin objects are converted to Obj-C objects. I have a simple class in Kotlin that is the following:
    class Agent(
        val var1: String,
        val var2: String,
        val var3: String,
        val var4: String,
        val var5: String,
        val var6: String,
        val var7: String,
        val var8: Boolean = false,
        val var9: String? = null,
        val var10: String? = null
    )
    And simply allocating it in Swift, i.e.,
    var agent = Agent(...)
    sometimes results in a memory leak. This even happens when all I do is allocate the object and nothing else references it. The same behavior applies when I put the object declaration in an autoreleasepool. Below is an image of what Xcode’s debug memory graph shows occasionally when there’s a leak.
    s
    • 2
    • 1
  • r

    RayeW47

    09/14/2019, 11:46 AM
    I'm not sure what I'm missing but I can't seem to use outside libraries in kotlin native. I also can't find any gradle documentation that would let me use that, nor any examples that use kotlin gradle scripts to interop with an outside library.
    m
    m
    d
    • 4
    • 7
  • o

    Ola Gawell

    09/16/2019, 3:15 PM
    I need some help with coroutines. I get that kotlin native only support coroutines on the main thread. But it should be possible to execute a background task (for example a http request) without blocking the ui right? I tried to create a simple task that uses the Dispatchers.Main but then the ui is blocked. Here is my code:
    a
    s
    +2
    • 5
    • 18
  • s

    spierce7

    09/16/2019, 3:29 PM
    How close are the different compiler platforms (jvm, js, and native) to sharing the same backend? I feel like this may have been done a while ago, but I haven’t heard anything.
    a
    o
    • 3
    • 4
  • s

    Sam Schilling

    09/16/2019, 3:52 PM
    Printing a Kotlin/Native object that is exported to an Objective C framework in Swift yields the object name and address, but printing the address of it the Swift way is always that address offset by 0x28. Any idea why this is?
    let a: MyType = ...
    print(a) // MyType@c56528
    print(Unmanaged.passUnretained(a).toOpaque()) // 0x0000000100c56500
    The second print should print the address of
    a
    , whereas the first would just be the default toString for Kotlin objects, I don’t know why the addresses are slightly offset though.
    o
    • 2
    • 5
  • v

    Vincent Chen

    09/17/2019, 3:43 AM
    Hi, I want to add dev sdk
    plugins {
        id 'org.jetbrains.kotlin.multiplatform' version '1.3.60-dev-1981'
    }
    repositories {
        maven {
            url '<https://dl.bintray.com/kotlin/kotlin-dev/>'
        }
    }
    But it is error
    Plugin [id: 'org.jetbrains.kotlin.multiplatform', version: '1.3.60-dev-1981'] was not found in any of the following sources:
    Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
    - Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:1.3.60-dev-1981')
      Searched in the following repositories:
        Gradle Central Plugin Repository
    How to do to fix it? Thanks
    r
    a
    • 3
    • 8
  • n

    napperley

    09/17/2019, 4:35 AM
    Trying to call a C function (
    cfg_init
    from libconfuse) that is expecting a
    CValuesRef<cfg_opt_t>?
    as the first argument. Using the
    cValuesOf
    function returns
    CValues<CPointerVar<cfg_opt_t>>
    which doesn't match. Below is the sample code:
    val targetStr = configString(name = "target".cstr, def = "NONE".cstr, flags = CFGF_NONE)
    val end = configEnd()
    val config = cfg_init(cValuesOf(targetStr, end), CFGF_NONE)
    a
    • 2
    • 7
  • n

    napperley

    09/18/2019, 5:12 AM
    Trying to figure out what character encoding is being used for terminal input. Writing the terminal input to a file as
    CPointer<ByteVar>
    works fine, however if the terminal input is written as a Kotlin String (eg
    data.cstr
    ) then the text in the output file looks garbled.
    o
    • 2
    • 2
  • r

    Rostislav Utrobin

    09/18/2019, 7:58 AM
    Hi, I have a question about ByteArray and toMutableList() method, on new Kotlin 1.3.50 when i do (in Common):
    val bytes = byteArrayOf(1)
    val mutableBytes = bytes.toMutableList()
    It works fine, but if a byteArray contains negative value i got a crash on iOS (on Android works fine). It's easy to reproduce, example:
    val bytes = byteArrayOf(-1)
    val mutableBytes = bytes.toMutableList() /* got a crash here on iOS */
    Does anybody have this issue?
    l
    a
    • 3
    • 5
  • j

    Jan Stoltman

    09/18/2019, 8:14 AM
    Hey guys, I'm working on iOS app with K/N framework and everything worked just fine untill I've added a cinterop Keychain wrapper written in ObjectiveC. Right now I'm getting
    bitcode bundle could not be generated because (...) was built without full bitcode.
    when trying to build an archive of my app. Has anybody faced something like this before?
    s
    s
    +2
    • 5
    • 10
  • b

    Big Chungus

    09/18/2019, 9:43 AM
    Hello, what can I use on K/N to build simple GUI for linux/windows?
    :yes: 2
    d
    a
    • 3
    • 3
  • n

    Nikita Klimenko

    09/18/2019, 4:00 PM
    Hi, Am I understand correctly the memory management in K/N that everything I write in a common package will automatically be released if the code in objective c does not have references to objects created by kotlin?
    k
    o
    +2
    • 5
    • 12
  • s

    Sam Schilling

    09/18/2019, 5:14 PM
    Sometimes calling
    GC.collect()
    results in
    Memory.cpp:987: runtime assert: Must be positive
    d
    o
    • 3
    • 10
  • v

    Vincent Chen

    09/19/2019, 8:42 AM
    Hi, if there is a “fun A(){…. return “” }” in my androidNativeArm64 now, there is also a “fun A(){…. return “”}” in my androidNativeArm32 This two fun A is all the same How can i write once for two platform ( Because import java.XXX, can’t write in commomMain )???? Thanks
    a
    • 2
    • 14
  • n

    napperley

    09/20/2019, 12:51 AM
    What memory considerations would need to be taken into account with a Kotlin String? Have a situation where a C library that is being used (termios - https://en.wikibooks.org/wiki/Serial_Programming/termios ) takes a buffer (
    CPointer<ByteVar>?
    ) for reading data, that is converted to a Kotlin
    String
    to do text manipulation, and is converted back to
    CPointer<ByteVar>?
    (via the
    cstr
    property) where it is written to a file.
    • 1
    • 1
  • v

    Vincent Chen

    09/20/2019, 3:56 AM
    Hi, Is it possible to write once with my “compilations.main.cinterops” block for android/ios
    targets {
            // Android Arm64 Platform (Parent Platform)
            androidNativeArm64("androidNativeArm64")
    
            // Android Arm32 Platform
            androidNativeArm32("androidNativeArm32")
    
            // Configure Android
            configure([androidNativeArm64, androidNativeArm32]) {
                compilations.main.cinterops {
                    XXXXXX
                }
    
                binaries {
                    sharedLib {
                        baseName = "AndroidNative"
                    }
                }
            }
    
            // *********************************************************
    
            // iOS Arm64 Platform (Parent Platform)
            iosArm64("iOSArm64")
    
            // iOS X64 Platform
            iosX64("iOSX64")
    
            // Configure iOS
            configure([iOSArm64, iOSX64]) {
                compilations.main.cinterops {
                    XXXXXX
                }
    
                binaries {
                    framework {
                        baseName = "iOS"
                    }
                }
            }
    
            // *********************************************************
    
            // JVM Platform
            jvm()
        }
    Thanks
    a
    • 2
    • 2
  • v

    Vincent Chen

    09/20/2019, 6:52 AM
    Hi, How to get targets alias ? Thanks like “${project.name}” Because I want basename is different
    binaries {
                    sharedLib {
                        baseName = iOSArm64 or iOSX64
                    }
                }
    a
    m
    • 3
    • 5
  • j

    JoakimForslund

    09/20/2019, 8:24 AM
    I have a configuration requirement when setting up iOS in gradle, where I want both the iosArm64 + iosX64 target to get built at the same time, but only want to configure everything for the target once. I have managed to configure both targets at one place, but now all my code inside iosMain will become red. I will paste it inside this thread in order not to spam the channel with code. How can i configure both my targets at one place, code in one place, but still set up iosMain properly without extra configuration?
    r
    r
    +2
    • 5
    • 15
Powered by Linen
Title
j

JoakimForslund

09/20/2019, 8:24 AM
I have a configuration requirement when setting up iOS in gradle, where I want both the iosArm64 + iosX64 target to get built at the same time, but only want to configure everything for the target once. I have managed to configure both targets at one place, but now all my code inside iosMain will become red. I will paste it inside this thread in order not to spam the channel with code. How can i configure both my targets at one place, code in one place, but still set up iosMain properly without extra configuration?
Untitled
All my code inside my iosMain folder will become red. And I figure it is because rather than using
val iosMain by creating
i am now using
val iosMain by creating
How can i configure both my targets at one place, but still set up iosMain without extra configuration?
r

ribesg

09/20/2019, 8:43 AM
That’s not how it works. You just created a non-platform specific sourceSet called iosMain, that doesn’t make it an iOS sourceSet
You need to define a “main” iOS target with one of the platform, then add additional targets and make the additional targets depend on your main one
You can make your sourceSets depend on each other inside your Gradle build file. It’s the recommended way. I just use a simple symlink as I don’t need the portability and prefer not to bloat my Gradle files more
j

JoakimForslund

09/20/2019, 8:51 AM
Yeah I dont know, but from what you are saying i'll need to add/modify another target called
ios
which means clogging down the gradle-file even more, I dont believe for a second that is the only way out of this
r

russhwolf

09/20/2019, 11:49 AM
This use-case is still a work-in-progress. See https://youtrack.jetbrains.com/issue/KT-27801 and related issues.
My usual workaround is
iosX64.dependsOn(iosArm64)
but it's not perfect.
k

Kris Wong

09/20/2019, 1:02 PM
there was a whole thread about this last week i think in #multiplatform
all you need to do is name one of your iOS targets to match your source set
then IDEA figures everything out
in my case i have iosX64('ios'), iosArm32('iosArm32'), iosArm64('iosArm64')
e

Erik Christensen

09/20/2019, 2:55 PM
https://kotlinlang.slack.com/archives/C3SGXARS6/p1568297037167500
j

JoakimForslund

09/24/2019, 2:34 PM
Thanks guys, I'll look into this more closely
View count: 3