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

    Igal Avraham

    06/24/2022, 1:21 AM
    👋 Hello, team!
    🤗 3
  • i

    Igal Avraham

    06/24/2022, 6:04 AM
    Hi, I am trying to add a pod the my kotlin native project with the cocoapods plugin. I keep getting errors no matter how I try to resolve it. the pod I am adding is GroundSdk. Can someone help ?
  • o

    okarm

    06/26/2022, 4:02 PM
    Hi, I'm dipping my toes in the K/N pond and I'd like to have any basic mistakes be pointed out early. Would you please look at the following piece of code and tell me if there's anything fundamentally wrong with my mental model? `iosMain`:
    internal actual fun encode(text: String, charset: Charset): ByteArray {
      var cfCharsetName: CPointer<__CFString>? = null
      try {
        // (1) Cast a NSString as CFStringRef for the CF lookup function.
        //     The BridgingRetain function will transfer the ownership to us,
        //     making us responsible for freeing the memory.
        cfCharsetName = CFBridgingRetain(charset.ianaName as NSString) as CFStringRef?
    
        // (2) Using the prepared CFStringRef, find the CFStringEncoding.
        val cfEncoding = CFStringConvertIANACharSetNameToEncoding(cfCharsetName)
        if (cfEncoding == kCFStringEncodingInvalidId) {
          throw RuntimeException("invalid encoding: ${charset.ianaName}")
        }
    
        // (3) Using the CF encoding, find the corresponding NSStringEncoding
        val nsEncoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding)
    
        // (4) Encode the Kotlin String using the NS Encoding. The resulting NSData
        //     lives in the ARC-enabled iOS runtime and since it does not escape the current
        //     scope, will be collected when scope ends.
        val encodedData: NSData =
            (text as NSString).dataUsingEncoding(nsEncoding, allowLossyConversion = true)
                ?: throw RuntimeException("encoder failed")
        val encodedBytes = encodedData.bytes ?: throw RuntimeException("encoder failed")
    
        // (5) Create a Kotlin-land ByteArray and copy over the encoded bytes
        // from the ObjC-land NSData.
        //
        // <https://github.com/JetBrains/kotlin-native/issues/3172>
        return ByteArray(encodedData.length.toInt()).apply {
          usePinned { pinnedByteArray ->
            memcpy(pinnedByteArray.addressOf(0), encodedBytes, encodedData.length)
          }
        }
      } finally {
        // Don't forget to free the unmanaged CF pointer! 
        CFRelease(cfCharsetName)
      }
    }
  • v

    Vsevolod Ganin

    06/27/2022, 1:09 PM
    Is there a way to automatically catch any of swift/objc exceptions/errors in
    try ... catch ...
    in Kotlin while calling
    interface
    method implemented in swift/objc? I saw relatively new
    ForeignException
    but afaik it only works for cinteroped libraries with special flag
    s
    • 2
    • 4
  • m

    Matt Nelson

    06/27/2022, 2:43 PM
    Hey does anyone know how a
    sealed interface
    will compile to objective-c? Is it the same as how it compiles as just an
    interface
    for Java? Wondering if it would have been better for
    kotlin.Result
    to have been a
    sealed interface
    with an underlying
    private value class
    such that it could compile to other platforms...
  • m

    Muhammet Emin Gündoğar

    06/28/2022, 4:33 PM
    hi guys i want to find kotlin source code to learn how they implemented.For example i want to learn how to string method implemented but i could not find it how can i find kotlin source code?
    j
    • 2
    • 1
  • j

    James Good

    06/30/2022, 6:29 AM
    Hello, I did quite a bit of Google searching to try to find out what the limitations of Kotlin native might be. I know that using Java libraries is a no go, but what about for stdlib functions in kotlin which delegate to Java, such as the Random module or this module https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.concurrent/java.util.-timer/schedule.html I see from the colored tabs on the website that it is appears to only have JVM support, but is there another option to use similar functionality as timer.schedule while using kotlin native?
    r
    • 2
    • 25
  • s

    spierce7

    06/30/2022, 3:16 PM
    How difficult is a kotlin native executable to backwards engineer?
    l
    • 2
    • 12
  • l

    Landry Norris

    06/30/2022, 4:38 PM
    How does the kotlin.native.internal.GC class work when I’m on the new memory model? The comments indicate that it controls the old ARC-like GC. I’m getting memory leaks in my app right now while interoping with a C library, so I’m mixing Kotlin’s GC with manual malloc/free. I’d like to be able to force a GC periodically so I can see the memory impact of my malloc/free objects. Edit: Adding GC.start() before seemed to force a GC. I now see a sharp drop in memory usage immediately.
    ➕ 2
    a
    • 2
    • 3
  • a

    Aditya Kurkure

    07/01/2022, 8:11 AM
    How can I access the swift
    JsonEncoder
    and
    JsonDecoder
    in Kotlin native? I noticed a JsonDecoder in Mapkit but can't see the Encoder in the same package.
    r
    • 2
    • 4
  • s

    spierce7

    07/04/2022, 5:42 PM
    Is it possible to obfuscate the method calls within a production application? I’m noticing I can still look at all the method calls via
    Strings <exe> | grep -i <name of module>
    e
    l
    • 3
    • 12
  • h

    hfhbd

    07/05/2022, 12:11 PM
    How can you use macros in Kotlin?
    j
    l
    n
    • 4
    • 19
  • h

    hfhbd

    07/05/2022, 4:51 PM
    How do you create CPointer<UByteVarOf<UByte>>? I simple want to pass the value 0
    r
    l
    • 3
    • 3
  • j

    Jeff Lockhart

    07/06/2022, 12:56 AM
    Is there a way to add additional
    external expect fun
    definitions to a pre-defined ObjC interop? I'm using an ObjC cocoapods library and need to call a function that's not part of its public API for testing. I know the function signature from its source code. Basically, I just need a way to ObjC "message" the function in Kotlin. Or something akin to Java reflection to access it.
    r
    s
    • 3
    • 21
  • k

    kevin.cianfarini

    07/06/2022, 2:01 PM
    What’s the correct way to transform a
    NSNumber
    to
    kotlin.Number
    ? Is it just
    myNsNumber as Number
    ?
    r
    j
    • 3
    • 10
  • d

    Dmitry Motyl

    07/06/2022, 3:38 PM
    I have several frameworks in my iOS project to split a code base. Shared code is added by cocoapods to each of them As result I get a crash with a lot of this messages:
    Class SharedXXX is implemented in both YYY and ZZZ. One of the two will be used. Which one is undefined.
    Has anybody solved this problem ?
    l
    • 2
    • 10
  • a

    ankushg

    07/07/2022, 7:02 PM
    We’re on the new memory model, and it’s kinda annoying to suppress IDE warnings relating to the old memory model on a one-by-one basis Is there a way to globally suppress old-memory-model-related warnings like
    VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL
    ?
    ➕ 5
    e
    • 2
    • 2
  • j

    Jeff Lockhart

    07/09/2022, 9:44 PM
    Is it possible to somehow access XCTestExpectation in *iosTest*s? Or is there another mechanism for testing async code that calls back on the main thread? iOS tests execute on the main thread, which causes callbacks to deadlock with the test code waiting on it.
    • 1
    • 1
  • r

    ribesg

    07/10/2022, 12:40 PM
    I'm trying to make this project compile https://github.com/Ribesg/kmp-reproducer It's very simple (like 9 files total), juste a Kotlin/Native iOS project with a pod dependency. It's trying to compile the dependency for an unsupported architecture, armv7. How can I fix it? It worked with Kotlin 1.6.21 but it required cocoapods-generate, which I have a hard time installing on my new Mac so I'd rather move on from it. I made an issue on Youtrack https://youtrack.jetbrains.com/issue/KT-53127/Cocoapods-dependency-is-built-for-unsupported-architecture
  • n

    natario1

    07/10/2022, 7:02 PM
    Hi guys, what’s the correct way to have KN use a different clang version than that in
    .konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials
    ? I’m thinking I might override the relevant property in
    konan.properties
    , but I’m not sure if it’s the right approach. Is anyone doing this?
    x
    • 2
    • 2
  • p

    Pavel Gorgulov

    07/11/2022, 10:43 AM
    Hi folks! Maybe someone can help me. I try to building lib through cinterop and there are complex numbers. On macosX64, macosArm64, mingwX64 everything is well, but on linuxX64 I get follow exception:
    16:22:47   Exception in thread "main" org.jetbrains.kotlin.konan.KonanExternalToolFailure: The /mnt/agent/system/.persistent_cache/konan/dependencies/llvm-11.1.0-linux-x64-essentials/bin/clang++ command returned non-zero exit code: 1.
    16:22:47   output:
    16:22:47   /mnt/agent/work/40296c97b9f61601/multik-native/multik_jni/src/main/cpp/mk_linalg.cpp:22:27: error: use of undeclared identifier 'creal'
    16:22:47     return mk_complex_float{openblas_complex_float_real(ret), openblas_complex_float_imag(ret)};
    16:22:47                             ^
    16:22:47   /mnt/agent/work/40296c97b9f61601/multik-native/build/cmake-build/openblas-install/include/openblas_config.h:128:55: note: expanded from macro 'openblas_complex_float_real'
    16:22:47     #define openblas_complex_float_real(z)             (creal(z))
    • 1
    • 1
  • h

    hfhbd

    07/11/2022, 2:46 PM
    Hey, I want to write the C parts of JNI with Kotlin Native. The JNINativeInterface has the following function to get the string in C: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetStringUTFChars This function is mapped as property in Kotlin:
    var GetStringUTFChars: kotlinx.cinterop.CPointer<kotlinx.cinterop.CFunction<
    in
    JNINativeInterface
    . But getting this "function" fails and I don't know why. I don't invoke the function yet.
    l
    n
    • 3
    • 35
  • j

    Jeff Lockhart

    07/12/2022, 4:20 PM
    Are Kotlin functional interfaces not supported as Swift closures or ObjC blocks? Is there a technical reason the compiler couldn't generate a compatible API that accepts the equivalent of a Kotlin lambda?
  • j

    Jeff Lockhart

    07/12/2022, 4:53 PM
    Would it be a better practice to define these interfaces as
    typealias InterfaceName = (param: ParamType) -> ReturnType
    ?
  • p

    Pardip

    07/13/2022, 1:46 PM
    Is there way to avoid initialisation crash?
    abstract class A {
    	
    	init {
    		foo()
    	}
    
    	abstract fun foo()
    }
    
    class B : A {
    	val b = /* init b */
    
    	override fun foo() {
    		b.something() // crash
    	}
    }
    The super class call
    foo()
    on init so, the property
    b
    is not yet initialised
    r
    e
    • 3
    • 4
  • b

    Big Chungus

    07/14/2022, 11:54 AM
    Is there any GTK K/N project that's actively being worked at? I'm looking to contribute rather than spin up my own, but the ones I've found all seem quite abandoned.
    t
    • 2
    • 1
  • b

    Brian Guertin

    07/14/2022, 8:31 PM
    Where is Kotlin 1.7.20 coming from? It's not specified anywhere in my build, I'm trying to use 1.7.0:
    * Source files: 
     * Compiler version info: Konan: 1.7.0 / Kotlin: 1.7.20
     * Output kind: FRAMEWORK
    h
    j
    • 3
    • 3
  • a

    AmrJyniat

    07/15/2022, 8:29 AM
    Can I have one abstract fun with multiple parameters/constructor without asking me to override two funs in the inherited class?, like so:
    abstract class A {
       abstract foo(param1: Any): Any
       abstract foo(param1: Any, param2, Any): Any
    }
    
    class B: A {
       //ask me to override one fun at lease and make the other fun optional
       override foo(param1: Any): Any {
         ......
       }
    }
    I'll always inject the
    foo()
    fun with all parameters, but I don't need them in the inherited class in most cases
    u
    • 2
    • 11
  • a

    Anton Afanasev

    07/15/2022, 3:34 PM
    Hi all. With K\N this:
    var onStateChanged: ((from: State, to: State) -> Unit)?
    translated to:
    @property void (^ _Nullable onStateChanged)(State *, State *) __attribute__((swift_name("onStateChanged")));
    which makes this function signature problematic to read on iOS. Are there any way to pass/enforce argument name on k\n? PS. I mean that argument names
    from
    and
    to
    are ignored during kotlin to swift translation.
  • t

    Trey

    07/20/2022, 9:36 PM
    I'm trying to debug why AudioQueueNewOutput is returning an OSStatus with a value of -50. From what I can tell, the -50 indicates a kAudio_ParamError. I've verified that the AudioStreamBasicDescription values are the same as some existing code written in Swift that works fine. Is it possible that the iOS doesn't like the other param pointers? They are typed, so I was thinking that it wouldn't compile if there was a problem with them. Any suggestions on how to continue debugging?
Powered by Linen
Title
t

Trey

07/20/2022, 9:36 PM
I'm trying to debug why AudioQueueNewOutput is returning an OSStatus with a value of -50. From what I can tell, the -50 indicates a kAudio_ParamError. I've verified that the AudioStreamBasicDescription values are the same as some existing code written in Swift that works fine. Is it possible that the iOS doesn't like the other param pointers? They are typed, so I was thinking that it wouldn't compile if there was a problem with them. Any suggestions on how to continue debugging?
View count: 4