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

    irus

    07/20/2019, 11:10 AM
    I'm trying to implement such function in K/N, cinterop generated first signature, but looks like it clear memory of pointers passed into it, I see that I can make them just NativePtr, but than it's hard to travers passed structs. How to instruct K/N to not clear passed ptrs?
    d
    • 2
    • 4
  • m

    Michał Kalinowski

    07/22/2019, 1:13 PM
    Hey, someone know how cast variable f.e
    UInt
    to
    CPointer
    ?
    d
    n
    • 3
    • 4
  • k

    Kruger Brent

    07/22/2019, 3:35 PM
    I am trying to use this https://khttp.readthedocs.io/en/latest/ library instead of Java HTTP. But it seems to work only for the Android target in a multiplatform scenario. It’s not even detecting on iOS or Common targets, although I have mentioned the dependency tag and repository URL in the respective gradle files! Any ideas?
    k
    l
    • 3
    • 76
  • k

    Kruger Brent

    07/22/2019, 11:16 PM
    Hi guys, I am trying to use Ktor for my iOS target in a multiplatform scenario. Has anyone come across an error like this?
    s
    • 2
    • 3
  • o

    olonho

    07/23/2019, 6:04 AM
    https://github.com/olonho/ktor-sample/ is an example how to use ktor and kotlinx.serialization in Kotlin/Native projects.
    👍 1
    k
    • 2
    • 1
  • m

    Michał Kalinowski

    07/24/2019, 5:25 AM
    Hey, currently I manage to draw triangle in opengl when importing glew and glfw. The only issue for now is that every macro like function from C is generated by cinterop as a nullable so for each call I need make not-null asserted cast. Is there any way to tell cinterop that I trust that all macros like functions can't be nullable?
    m
    • 2
    • 5
  • a

    andreasmattsson

    07/25/2019, 1:37 PM
    Wondering if anyone could help me with memory issues on iOS? I'm trying to figure out how to keep a weak reference to a UIViewController within a Kotlin class instance, without preventing the ViewController from deiniting. This is what I'm currently trying on the Kotlin side:
    class KotlinWeakViewController(private val weak: WeakReference<UIViewController>) {
        constructor(viewController: UIViewController) : this(WeakReference(viewController))
    
        val viewController get() = weak.get()
    }
    And I have this in my Swift VC:``` private var weakVc: KotlinWeakViewController? required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) //weakVc = KotlinWeakViewController(viewController: self) weakVc = KotlinWeakViewController(weak: KotlinWeakReference(referred: self)) weakVc = nil } deinit { print("ViewController deinit") } ``` Unfortunately the ViewController never seems to deinit if I instantiate the
    KotlinWeakViewController
    , regardless of whether I create the
    WeakReference
    on the Kotlin side or on the Swift side, and regardless of whether I keep the reference to the
    KotlinWeakViewController
    around in an instance variable or nil it immediately.
    k
    • 2
    • 6
  • t

    Thomas

    07/25/2019, 3:38 PM
    My iOS app crashes with the following error:
    malloc: *** error for object 0x280872d78: pointer being freed was not allocated
    malloc: *** set a breakpoint in malloc_error_break to debug
    I am guessing I am doing something wrong with my cinterop code. How can I find the cause of the issue in my code?
    a
    s
    • 3
    • 4
  • p

    ptmt

    07/29/2019, 8:25 AM
    I have a similar exception
    Invalid module
    https://kotlinlang.slack.com/archives/C3PQML5NU/p1548688304549700 for
    1.3.50-eap-5
    Is it possible to implement more meaningful message from `LLVMVerifyModule`as TODO here states? (if it makes sense at all) https://github.com/JetBrains/kotlin-native/blob/b0c74ec00b91038cc2e587e0017d919fd5dbbadc/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt#L65
    s
    v
    • 3
    • 5
  • t

    Thomas

    07/29/2019, 12:53 PM
    Hello, is this code supposed to throw an
    InvalidMutabilityException
    ? If you move the
    init
    to the end (after the lazy val) it does not throw the exception.
    fun main() {
        Example()
    }
    
    class Example {
    
        init {
            freeze()
        }
    
        val value by lazy { 1 }
    }
    d
    o
    • 3
    • 5
  • j

    Jurriaan Mous

    07/29/2019, 7:32 PM
    I am trying to do a cinterop on the rocksdb headers. It fails on
    #include <map>
    with exception:
    /include/rocksdb/db.h:13:10: fatal error: 'map' file not found
    . This is the .h file: https://github.com/facebook/rocksdb/blob/master/include/rocksdb/db.h . What am I doing wrong? (This cinterop thing is new to me so maybe I am missing something obvious)
    d
    • 2
    • 5
  • a

    Arkadii Ivanov

    07/29/2019, 10:45 PM
    Performance question: the following code takes ~47 secs on K/N with Kotlin 1.3.31 and ~29 secs with Kotlin 1.3.41 (Linux X64 target). And just 1.3 sec on JVM. Both on the same machine. I'm wondering, what is the reason?
    var map: Map<Int, Int> = emptyMap()
        repeat(10000) {
            map += it to it * 2
        }
    d
    k
    +5
    • 8
    • 81
  • k

    Kris Wong

    07/30/2019, 2:57 PM
    it's not clear how to use
    @ObjCMethod
    -
    @ObjCMethod external override fun viewDidLoad() {
    . the generated bindings don't seem to pass any args to that annotation.
    s
    • 2
    • 4
  • k

    Kris Wong

    07/30/2019, 7:17 PM
    what in the world is this
    __attribute__((unavailable("Kotlin subclass of Objective-C class can't be imported")))
    s
    • 2
    • 5
  • k

    Kris Wong

    07/30/2019, 9:19 PM
    how would you pass a selector to an
    addTarget
    call on a UIControl?
    l
    • 2
    • 8
  • a

    Andrei Marshalov

    08/01/2019, 3:00 PM
    Hi! How can i use
    allocArrayOf()
    inside
    memScoped{ }
    to alloc array of
    double
    ? I’m surprised that it works only for
    float
    . Kotlin version
    1.3.30
    d
    • 2
    • 4
  • r

    russhwolf

    08/02/2019, 2:37 AM
    Lost a couple hours on this one. The following code fails to compile on native in 1.3.41:
    fun main() {
        val label = "hello"
        val lambda: suspend () -> String = { label }
    }
    Apparently the compiler chokes on a variable named
    label
    being passed into a suspend lambda. The problem goes away if a different name than
    label
    is used. I’d toss it in youtrack but it seems to already be fixed in the 1.3.50 eap.
    🤔 3
    s
    s
    • 3
    • 3
  • y

    Yan Pujante

    08/04/2019, 7:00 PM
    I want to create a kotlin native project to generate a static library. I would like the project to have a structure like this:
    src/nativeMain // contains "generic" code that can be used in other dir
    src/macosMain // contains "specific" code for macOS
    src/mingwMain // contains "specific" code for Windows
    From my understanding, the
    build.gradle
    needs to look like this:
    kotlin {
          macosX64("macos") {
            binaries {
                staticLib {
                }
            }
        }
    
          mingwX64("mingw") {
            binaries {
                staticLib {
                }
            }
        }
    }
    But I am unclear how I include
    nativeMain
    which should be part of the static library as well as how I declare a dependency (
    macosMain
    depends on
    nativeMain
    ) Any help appreciated.
    d
    l
    m
    • 4
    • 13
  • c

    Cyrille QUÉMIN

    08/05/2019, 1:49 PM
    Hey guys, I’d like to use new API only available on with Xcode 11 Beta. When will the bindings be generated for those new API so that I can use them in Kotlin Native for iOS (and subsequently in a mpp project)? If I compile Kotlin native myself locally will it generate those bindings for me ?
    l
    • 2
    • 5
  • a

    asad.awadia

    08/05/2019, 6:27 PM
    Kotlin native can only use other libraries that support native right? I.e i cant kotlin native a vertx application?
    :yes: 2
    j
    k
    +3
    • 6
    • 21
  • g

    galex

    08/06/2019, 1:32 PM
    Hello, can I build Kotlin-native for iOS directly in Swift?
    a
    k
    +3
    • 6
    • 23
  • u

    4ntoine

    08/06/2019, 1:59 PM
    Hey, guys. I have kotlin mpp project and i’ve just managed to compile it for JVM and native (macosx). In my benchmarks native release app is ~10x slower than JVM one. This is how native target is added in `build.gradle`:
    macosX64("native") {
                binaries {
                    executable()
                }
            }
    . The measurements are done with trivial
    measureTimeMillis()
    What can be the reason? Any optimizations turned off?
    a
    a
    +2
    • 5
    • 22
  • p

    Paul Idstein

    08/06/2019, 3:26 PM
    How can I ship resources with klib? We have some config files we would like to define in a multi-platform library and use them in a different app
    a
    • 2
    • 1
  • l

    louiscad

    08/06/2019, 4:52 PM
    If I want to embed a C or Obj-C file (
    .h
    +
    .c
    or
    .m
    ) into a Kotlin/Native library, is setting up C-interop enough, or do I also need to do something special to export the file?
    d
    m
    • 3
    • 22
  • l

    louiscad

    08/06/2019, 9:08 PM
    Is there a way to make cinterop generate Obj-C -> Kotlin bindings that have generics? Currently,
    id <SomeProtocol>
    ends up being
    Any?
    . I tried to add
    extraOpts("-Xobjc-generics")
    in the cinterop from my
    build.gradle.kts
    , but then, the cinterop gradle task fails, telling the option is unknown.
    k
    • 2
    • 2
  • a

    andreasmattsson

    08/07/2019, 7:28 AM
    Can I get the
    KotlinKClass
    of Kotlin class from Swift/obj-C (in order to then pass it to a kotlin method)? I.e. the equivalent of
    ClassName::class
    on the Kotlin side?
    s
    • 2
    • 2
  • a

    alex009

    08/07/2019, 8:44 AM
    Does kotlin/native require JDK 8 only? same project successful compiles to iosArm64 with JDK 8, but doesn't compile on JDK 10.
    a
    • 2
    • 6
  • a

    Animesh Sahu

    08/07/2019, 3:00 PM
    How do i start project for raspberry kotlin/native in intellij on my pc? And can i use java libs in them though maven/gradle?
    d
    • 2
    • 3
  • y

    Yan Pujante

    08/07/2019, 6:52 PM
    I have a very small kotlin native project that generates a static lib:
    package sample
    
    import platform.AppKit.NSView
    
    fun attached(parent: NSView) : Boolean {
        println("kotlin::attached(${parent.window()})")
        return true
    }
    Then I have another (C++) project consuming the library and calling:
    lib->kotlin.root.sample.attached({ parent }))
    where
    parent
    is a
    NSView
    that was created by some code I am not responsible for (it is passed to me). This simple code crashes... From the screenshot attached I can confirm that what is passed to me is a
    NSView
    pointer... but somehow on the kotlin side it crashes. I have tried with a few methods on
    NSView
    and they all trigger a crash. Any idea? Am I doing something wrong?
    k
    s
    • 3
    • 14
  • h

    Harsh Deshpande

    08/08/2019, 5:26 PM
    https://kotlinlang.slack.com/archives/C0922A726/p1565284995237500
    k
    • 2
    • 4
Powered by Linen
Title
h

Harsh Deshpande

08/08/2019, 5:26 PM
https://kotlinlang.slack.com/archives/C0922A726/p1565284995237500
k

Kirill Shmakov [JB]

08/09/2019, 9:11 AM
Harsh, could you please provide the following: - OS you are using; - Idea Ultimate version; - type of project you are using (is it multiplatform plugin which defines your project in main build.gradle[.kts]?); - configuration you start to debug?
Just in case, is it not something similar to https://kotlinlang.slack.com/archives/C3PQML5NU/p1565160335304800?thread_ts=1564747546.241900&amp;cid=C3PQML5NU ?
h

Harsh Deshpande

08/09/2019, 3:48 PM
Hi Sorry for the late response - I'm using 10.14.5 Idea Ultimate 2019.2, #IU-192.5728.98 It's a kotlin native library (not at much liberty to talk about this product too much) it should just be a regular debug configuration? (well since this is native, we are not using the JVM configs at all)
k

Kirill Shmakov [JB]

08/12/2019, 1:55 PM
Ok, so do you have executables which are defined by
binaries { ... executable ... }
in you
build.gradle
file? If not then IDE will not determine its run configuration from Gradle model. The resulting run configurations are supposed to be of type `Kotlin/Native Application`:
View count: 6