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

    napperley

    07/04/2019, 11:23 PM
    Trying to free a msg via the MQTTClient_freeMessage function however it doesn't accept a CPointer<MQTTClient_message>?. The function only accepts a CValuesRef<CPointerVar<MQTTClient_message>>?. Below is the mapping for MQTTClient_message:
    @kotlinx.cinterop.internal.CStruct public final class MQTTClient_message public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
        public companion object : kotlinx.cinterop.CStructVar.Type {
        }
    
        public final var dup: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
        public final var msgid: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
        public final var payload: kotlinx.cinterop.COpaquePointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
    
        public final var payloadlen: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
        public final val properties: paho_mqtt.MQTTProperties /* compiled code */
    
        public final var qos: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
        public final var retained: <http://kotlin.Int|kotlin.Int> /* compiled code */
    
        public final val struct_id: kotlinx.cinterop.CArrayPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */> /* = kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVarOf<kotlin.Byte>> */ /* compiled code */
    
        public final var struct_version: <http://kotlin.Int|kotlin.Int> /* compiled code */
    }
    d
    • 2
    • 4
  • q

    qlitzler

    07/05/2019, 3:03 PM
    Hello, I am working on an open source project, which is a client relying on
    ktor
    . I am trying to add an ios target, and run into this exception when trying to build. You can reproduce for yourself by checking out the
    feature/ios
    branch of https://github.com/algolia/algoliasearch-client-kotlin
    -.txt
    o
    a
    • 3
    • 7
  • f

    fcosta

    07/05/2019, 6:33 PM
    I’m trying to run my test with Xcode generating a test framework. I’m using cocoapods. Is the configuration below correct? I can’t find any framework with name test in my build folder 😞
    kotlin {
        targets {
            final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64
    
            fromPreset(iOSTarget, 'ios') {
                binaries {
                    framework('client')
                    framework('test') {
                        compilation = compilations.test
                        linkerOpts += ['-framework', 'UIKit']
                    }
                }
            }
        }
        cocoapods {
            // Configure fields required by CocoaPods.
            summary = "chat-client"
            homepage = "<https://github.com/felipehjcosta>"
    
            pod('SocketRocket', '0.5.1')
            pod('OHHTTPStubs')
        }
    }
    l
    • 2
    • 4
  • p

    Paul Idstein

    07/06/2019, 10:54 AM
    Is it possible to disable GC in Kotlin/Native for iOS? We see for instance when referencing ARFrames huge lags, as K/N retains instances and a GC cycles is roughly 30secs away. We can mitigate it only with a forceGC after every delegate callback.
    b
    k
    +2
    • 5
    • 20
  • g

    galex

    07/08/2019, 10:17 AM
    Hello, I am working on a mac but do I need to be on a mac to compile Kotlin/Native for iOS or does it work on a linux machine as well?
    a
    • 2
    • 1
  • j

    Jonas Bark

    07/08/2019, 2:45 PM
    On my project I'm depending on the artifacts produced by another Kotlin Multiplatform library - it also produces native artifacts etc (in this case the ones for iOS):
    val commonMain by getting {
        dependencies {
           //....
           api("dependency-group:dependency:version")
        }
    }
    When I'm trying to run the
    linkDebugTestIosX64
    gradle task I'm getting this error:
    e: Compilation failed: Cyclic dependency in library graph for: /Users/boni/Documents/Programmieren/Kotlin/StihlBusiness/StihlBusiness/build/classes/kotlin/iosX64/main/Library
    
     * Source files: StoreTest2.kt
     * Compiler version info: Konan: 1.3.1 / Kotlin: 1.3.40
     * Output kind: PROGRAM
    Is there a way to debug this to get better information?
    🤝 1
    s
    a
    +2
    • 5
    • 17
  • j

    josephivie

    07/08/2019, 8:33 PM
    I am unable to get a really basic selector working in iOS - here's what I'm doing.
    class ClosureSleeve(val closure: () -> Unit) : NSObject() {
    
        @ObjCAction
        fun runContainedClosure() {
            closure()
        }
    
        val selector: COpaquePointer? get() = Companion.selector
    
        @ThreadLocal
        companion object {
            var selector: COpaquePointer? = sel_registerName("runContainedClosure")
    
            fun printMethods(){
                val instance = ClosureSleeve{}
                val type = object_getClass(instance)
    
                println("Now there are implementations:")
                memScoped {
                    val sizeOutput = this.alloc<UIntVar>()
                    println("My class: ${type}")
                    val mlist = class_copyMethodList(type, sizeOutput.ptr)
                    if(mlist == null){
                        println("Failed to pull selectors, null response.")
                        return@memScoped
                    }
                    val size = sizeOutput.value.toInt()
                    println("Selector size: $size")
                    for (i in 0 until size) {
                        println("Method $i: ${sel_getName(method_getName(mlist[i]))?.toKString()}")
                    }
                }
                println("Attempted registry: $selector")
                println("End selectors.")
            }
        }
    }
    I'm then using it from Swift to keep that section isolated:
    let sleeve = ClosureSleeveKt.makeSleeve {
                print("Test")
            }
            print("Sleeve: \(sleeve)")
            self.sleeve = sleeve //Not to worry; strong ref here
            button.addTarget(sleeve, action: NSSelectorFromString("runContainedClosure"), for: .touchUpInside)
    When it prints out what methods are available,
    runContainedClosure
    is not there, just
    init
    and
    dealloc
    . Can anybody help? I've been working on this for several days and been unable to get it to work. I see that @spierce7 successfully got something like it working at one point.
    a
    j
    • 3
    • 5
  • s

    spierce7

    07/08/2019, 11:32 PM
    I created a multiplatform HTML streaming library. For fun I thought I'd benchmark it for macosX64 and JVM. Here is a link to the benchmark: https://github.com/ScottPierce/kotlin-html/blob/master/benchmark/src/commonMain/kotlin/dev/scottpierce/html/benchmark/SimpleBenchmark.kt Results:
    JVM: Benchmark Completed. Benchmark Total Millis: 17324, Average iteration was 346.42 millis
    Native: Benchmark Completed. Benchmark Total Millis: 185398, Average iteration was 3707.94 millis
    g
    e
    +2
    • 5
    • 26
  • j

    JoakimForslund

    07/10/2019, 11:43 AM
    Is it possible to use WKWebView on macOSX target for kotlin native? I do not seem to find any imports for it? (https://developer.apple.com/documentation/webkit/wkwebview)
    j
    l
    a
    • 4
    • 18
  • r

    Rostislav Utrobin

    07/10/2019, 12:01 PM
    Is there any ideas or maybe guide how to use self-compiled kotlin-native? We want try to use some features from master (but it's not available in 1.3.40) I've compiled kotlin native from this build (by guide from KN's Readme) https://github.com/JetBrains/kotlin-native/releases/tag/build-1.3.50-dev-2041 and now I have klib.jar Does anybody have an idea how to use it instead of the release version?
    e
    • 2
    • 1
  • s

    spierce7

    07/10/2019, 7:20 PM
    With relaxed mode, does that also mean that we'll get some Lock / synchronization utils?
    k
    b
    • 3
    • 3
  • i

    Ivan Ilic

    07/12/2019, 1:14 PM
    Hello, is it possible to use in kotlin addObserver on NSObject? I want to observe the property value of native object without success. I also tried to implement my own NSObject using this swift example as reference https://developer.apple.com/documentation/swift/cocoa_design_patterns/using_key-value_observing_in_swift. Is anyone have more success and want to share with me?
    l
    s
    • 3
    • 16
  • s

    sksk

    07/13/2019, 4:27 PM
    Are there plans for a Kotlin Package Manager ? similar to SPM and Crates, something focused on simplicity, accessibility and extensible, written in native language to avoid slowness and flaws of gradle
    ☝️ 3
    r
    d
    +7
    • 10
    • 52
  • n

    napperley

    07/15/2019, 3:42 AM
    Noticed that documentation (KDoc) and source code (Kotlin source files) aren't available when using a Kotlin Native library (a KLib written in Kotlin) via Gradle. Will that be fixed in a newer version of the Kotlin plugin? This is the Kotlin Native library I'm referring to for reference purposes: https://gitlab.com/napperley/kmqtt-client
    a
    m
    o
    • 4
    • 4
  • p

    Paul Idstein

    07/15/2019, 8:15 AM
    I would like to use a finalize hook in iOS NSObject. How can I implement
    dealloc
    in Kotlin? I will as a final step call super.dealloc to dispose KRefSharedHolder, but before that I would like to clean-up scoped pointers
    o
    s
    l
    • 4
    • 5
  • s

    spierce7

    07/15/2019, 8:15 PM
    I'm trying to share a test library with my iOS team. They are telling me that I need to have the framework compile to
    arm64 arm64e armv7 armv7s
    . Can kotlin/native do arm64e or armv7s?
    s
    s
    • 3
    • 3
  • s

    spierce7

    07/15/2019, 8:31 PM
    I was having trouble accessing the companion object instance from Swift code. We could access it, but had to create an instance of the companion object to do so, i.e.
    <Kotlin Class>.Companion().<companion function>()
    . Did we overlook something, or is this a known limitation?
    k
    s
    • 3
    • 6
  • s

    spierce7

    07/15/2019, 8:38 PM
    So my iOS team needs me to provide them a framework, but that framework needs to support several different kotlin/native platforms, while being compiled to a single framework. Are there any examples of doing this, or would anyone know how?
    d
    j
    +2
    • 5
    • 15
  • t

    thevery

    07/16/2019, 8:36 AM
    I know that developers usually don't like to read standalone docs, but this one is surprisingly good, especially in native part: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html
    👨‍🎓 1
    👍 2
    r
    n
    • 3
    • 2
  • k

    Kruger Brent

    07/16/2019, 5:55 PM
    I_am_facing__Uncaught_Kotlin_exception__kotlin_native_IncorrectDereferenceException__illegal_attempt_to_access_non-shared__issue_when_I_access_this_piece_of_code_in_Xcode_.txt
    o
    • 2
    • 8
  • n

    napperley

    07/17/2019, 2:18 AM
    Is there a Kotlin Native sample that shows how to wrap a C Macro to create new instances (like a Struct for example) and manually free them later on?
    e
    • 2
    • 2
  • k

    kpgalligan

    07/17/2019, 3:12 PM
    Having some issues with the cocoapods integration. Anybody know where that plugin is kept, and best place to file bugs? I’m pretty sure it’s in the “main” kotlin repo and not native, but having some trouble tracking it down and want to make sure it’s not in a special place.
    b
    t
    i
    • 4
    • 24
  • m

    m

    07/17/2019, 6:33 PM
    Hy guys. I noticed that compiler just ignore
    suspend
    methods and doesn’t warn about that due compilation for iOS. So, is it possible to enable such warnings?
    s
    • 2
    • 2
  • n

    napperley

    07/17/2019, 10:48 PM
    What are the top priorities for Kotlin Native (apart from iOS support)? WASM support has been mentioned as not being a top priority ( https://kotlinlang.slack.com/archives/CDFP59223/p1563365970024200?thread_ts=1563324949.014100&amp;cid=CDFP59223 ).
    g
    k
    • 3
    • 4
  • m

    mben

    07/18/2019, 8:36 AM
    Hello i have 2 questions one about compilation and another about tests : 1) when your shared code is compiled with kotlin native for android does it use jvm or other thing? 2) I tried mockk to unit test my shared code but i saw recently that when you launch it through android studio it use jvm so i'm wondering what is the good way to test shared code for ios and android?
    a
    t
    • 3
    • 5
  • k

    Kruger Brent

    07/18/2019, 4:15 PM
    Is coroutines supported in Kotlin/Native or CommonMain modules?
    s
    j
    d
    • 4
    • 28
  • t

    tylerwilson

    07/19/2019, 1:47 AM
    Anybody else tired of all the Int <-> Int32 casting in swift with MP library? Anybody find a clean way around this?
    s
    s
    • 3
    • 6
  • m

    Michał Kalinowski

    07/19/2019, 6:35 AM
    Hey there, I have a question about performance, how big is overhead when it's comes to only calling method from C?
    o
    • 2
    • 2
  • i

    ignus

    07/19/2019, 6:41 AM
    What features from Kotlin/JVM aren't available in Kotlin/Native?
    j
    g
    n
    • 4
    • 17
  • i

    irus

    07/20/2019, 11:07 AM
    #include <jvmti.h>
    #include <stdio.h>
    
    JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
        return 0;
    }
    // SIGSEGV
    @CName("Agent_OnLoad")
    fun Agent_OnLoad(
        vm: CValuesRef<JavaVMVar>?,
        options: CValuesRef<ByteVar>?,
        reserved: CValuesRef<*>?
    :disappointed: jint {
        println("Agent: Hello, World!")
        return 0
    }
    
    // ok
    @CName("Agent_OnLoad")
    fun Agent_OnLoad(
        vm: NativePtr,
        options: NativePtr,
        reserved: NativePtr
    :disappointed: jint {
        println("Agent: Hello, World!")
        return 0
    }
    n
    o
    • 3
    • 7
Powered by Linen
Title
i

irus

07/20/2019, 11:07 AM
#include <jvmti.h>
#include <stdio.h>

JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
    return 0;
}
// SIGSEGV
@CName("Agent_OnLoad")
fun Agent_OnLoad(
    vm: CValuesRef<JavaVMVar>?,
    options: CValuesRef<ByteVar>?,
    reserved: CValuesRef<*>?
:disappointed: jint {
    println("Agent: Hello, World!")
    return 0
}

// ok
@CName("Agent_OnLoad")
fun Agent_OnLoad(
    vm: NativePtr,
    options: NativePtr,
    reserved: NativePtr
:disappointed: jint {
    println("Agent: Hello, World!")
    return 0
}
n

napperley

07/21/2019, 12:00 AM
Do note that Kotlin Native doesn't support JNI.
i

irus

07/21/2019, 12:11 PM
I've trying to implement JVM TI with Kotlin/Native, and I have some success, but types generated by cinterop feels wron
🆗 1
o

olonho

07/22/2019, 1:05 PM
K/N does support JNI as any other C library.
CPointer<JavaVMVar>
and such is right type here.
🆗 1
i

irus

07/22/2019, 8:40 PM
But
cinterop
generated
CValuesRef<JavaVMVar>?
here. Headers from jdk11
I feel like generated types is wrong in other places, so they doesn't help, and I have to write bindings myself. https://github.com/IRus/jvm-ti-kotlin/blob/master/src/linuxMain/kotlin/JvmTi.kt#L25
Can you confirm that?
o

olonho

07/23/2019, 11:02 AM
nope,
CPointer
is subclass of
CValuesRef
, and in this case it shall be used.
cinterop
is not related to the problem here, as it provides bindings to the C library from Kotlin, and in your case you produce C library from Kotlin source code.
View count: 7