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

    Slackbot

    01/30/2020, 8:04 PM
    This message was deleted.
    d
    k
    • 3
    • 3
  • k

    kpgalligan

    01/31/2020, 2:11 PM
    This is the client setup
    private val client = HttpClient {
            install(JsonFeature) {
                serializer = KotlinxSerializer()
            }
            install(Logging) {
                logger = Logger.DEFAULT
                level = LogLevel.ALL
            }
        }
    k
    a
    • 3
    • 8
  • p

    Patrick

    01/31/2020, 3:17 PM
    I have a Kotlin Class that looks like this:
    class Device {
        var didConnectFunc: CFunction<() -> Unit>? = null
    
        fun didConnect() {
            didConnectFunc?.ptr?.invoke()
        }
    }
    If I export this as a dynamic C library, I get can set the function to be executed like this:
    void *didConnect() {
        printf("DID CONNECT\n");
    }
    
    lib->kotlin.root.Device.set_didConnectFunc(device, didConnect);
    This works fine. What do I have to do however if I want to pass an Argument to my C function like this:
    class Device {
        var didConnectFunc: CFunction<(barcode: Barcode) -> Unit>? = null
    
        fun didConnect(barcode: Barcode) {
            didConnectFunc?.ptr?.invoke(barcode)
        }
    }
    This code does not compile with the following error message:
    type [@kotlin.ParameterName] Barcode is not supported here: doesn't correspond to any C type
    How would I best solve this problem? Is it possible to create a pointer to the Barcode class and pass that to the function?
    k
    o
    +2
    • 5
    • 12
  • s

    Sylvain Patenaude

    01/31/2020, 4:28 PM
    In my Kotlin (multiplatform) code, I have several `object`s. Let's say for instance I have one named "SomeHelper" that contains "static" methods. Why, in my "MyProject.framework/Headers/MyProject.h" file, does it add a Kt suffix to my
    swift_name
    ? And why do I see
    objc_subclassing_restricted
    ?
    __attribute__((objc_subclassing_restricted))
    __attribute__((swift_name("SomeHelperKt")))
    @interface ProjectNameSomeHelperKt : KotlinBase
    a
    • 2
    • 5
  • g

    GarouDan

    02/02/2020, 10:05 PM
    Hi, I’m receiving the following error when building my Kotlin multiplatform project (but only for the Kotlin native targets):
    java.lang.IllegalStateException: Could not find serialized descriptor for index: -7854123172190848783
    Does someone know how to solve this problem? I’m using Kotlin
    1.3.61
    and Gradle
    5.5.1
    . I tried to update to latest Kotlin dev
    1.3.70-eap-96
    but I still have the same problem =/
    m
    a
    • 3
    • 3
  • v

    Vincent Chen

    02/03/2020, 9:56 AM
    Hi, In my kn project I have android/ios/jvm sourceSets if I want my some class/function in commonMain don’t compile by ios how to setting?? Thank you very much
    a
    r
    • 3
    • 2
  • k

    Kavan

    02/03/2020, 8:20 PM
    val str = StringBuilder (); str.append("hello");
    var str = ""; str += "hello";
    Second is faster then first one. Shouldn't take same time ? If not then. When to use first and when to use second ?
    s
    d
    • 3
    • 5
  • k

    Kris Wong

    02/04/2020, 2:26 PM
    what's the most straightforward way to add a .klib artifact to the maven publication created for an iOS target with a framework binary?
    k
    r
    • 3
    • 48
  • r

    ribesg

    02/04/2020, 2:43 PM
    What does
    NativeBuildType
    do? When setting it to
    RELEASE
    , it strips the result from at least 2 enums in the code leading to crashes
    🤨 1
    😱 1
    a
    • 2
    • 18
  • t

    Trond Tunheim

    02/05/2020, 10:17 AM
    Hi, I have done some experimenting with Kotlin native for iOS. I have discovered at several occasions that I run into "Overload resolution ambiguity" when calling certain functions. For instance UIColor, which has 3 overloads with the same signature. How do I get the compiler to distinguish between those ?
    a
    • 2
    • 2
  • n

    Nikolay Kasyanov

    02/05/2020, 10:54 AM
    Hey folks, is this expected that importing
    import kotlin.test.Test
    is highlighted red in the IDE when the test is located in the
    commontTest
    source set? Gradle build doesn’t fail, seems like an IDE issue.
    • 1
    • 1
  • m

    max.cruz

    02/05/2020, 11:10 AM
    Hi, I’m working on a native project to wrap libgit2 (similar to the gitchurn example) and perform some tasks on the server-side (Linux). My problem is that I’m using macOS for development, and I need to do cross-compile to build the version for Linux. Most of the examples are using
    System.getProperty("os.name")
    to identify the target, so it supposes that it would be needed to use the same OS. Is there some example that you can recommend me about how to set up the project properly for cross-compile?
    a
    • 2
    • 2
  • d

    dwursteisen

    02/05/2020, 12:04 PM
    👋 Quick question. I using a C API using Kotlin/Native. Using C interrop, I can use the generated object
    Model
    which has a field
    val transform: Matrix
    I want to update this transform matrix but I haven’t found a way to do it.
    val model = cValue<Model> { }
    // ...
    model.useContents {
        // create a copy so update are lost 
        transform.useContents {
           m1 = ...
        }  
    }
    generated code by cinterop:
    public final class Model {
       // ...
       val transform: Matrix
    }
    header definition: • Model: https://github.com/raysan5/raylib/blob/master/src/raylib.h#L365 • Matrix: https://github.com/raysan5/raylib/blob/master/src/raylib.h#L195
    a
    • 2
    • 2
  • b

    Brian Stanek

    02/05/2020, 1:35 PM
    I’m trying to use an objective-c class that expects a
    Class<SomeProtocol>
    that it can internally instantiate when needed. In kotlin I can create a class that conforms to
    SomeProtocol
    - but I don’t know how to (or if it’s even possible to) get an “Objective-C class” from that class. I tried passing it as
    MyClass::class
    , but the compiler complains that it got a
    KClass<MyClass>
    but was expecting a
    SomeProtocol?
    - which isn’t quite right, because the API I’m calling expects a class, not an instance. Using
    MyClass::class as SomeProtocol
    appeases the compiler, but results in a TypeCastException at runtime. Is there anything analogous to
    KotlinClass::class.java
    in the native world?
    a
    • 2
    • 2
  • n

    napperley

    02/05/2020, 9:44 PM
    If the project is reverted to a previous commit ( https://gitlab.com/napperley/prometheus-manager/commit/54ca3a199fcc935fc46e82e25fe7f9f44d31b1d1 ), and the same Gradle task is executed then there is no Konan error. Here is the link to the project: https://gitlab.com/napperley/prometheus-manager
    👀 1
    a
    • 2
    • 3
  • n

    Nikolay Kasyanov

    02/06/2020, 10:18 AM
    Morning folks, I’m getting this while building an iOS framework after adding
    @Throws
    annotation to one of my Kotlin methods:
    !dbg attachment points at wrong subprogram for function
    !81136 = distinct !DISubprogram(name: "objc2kotlin.3034", linkageName: "objc2kotlin.3034", scope: !75265, file: !75265, type: !75266, spFlags: DISPFlagDefinition, unit: !1293, retainedNodes: !1295)
    i8* (i8*, i8*, i8*, i8**)* @objc2kotlin.3034
      %9 = alloca [5 x %struct.ObjHeader*], align 8, !dbg !81156
    !81156 = !DILocation(line: 296, column: 9, scope: !81157)
    !81157 = distinct !DISubprogram(name: "Kotlin_ObjCExport_getWrappedError", linkageName: "Kotlin_ObjCExport_getWrappedError", scope: !290, file: !290, line: 296, type: !1363, spFlags: DISPFlagDefinition, unit: !289, retainedNodes: !1295)
    !81157 = distinct !DISubprogram(name: "Kotlin_ObjCExport_getWrappedError", linkageName: "Kotlin_ObjCExport_getWrappedError", scope: !290, file: !290, line: 296, type: !1363, spFlags: DISPFlagDefinition, unit: !289, retainedNodes: !1295)
    warning: ignoring invalid debug info in /var/folders/ch/tb8ry3t16mdgwpjqz8yzw5yc0000gn/T/konan_temp6380746194156800718/MyFramework.kt.bc
    warning: no debug symbols in executable (-arch x86_64)
    And no debug info seems to be generated for the framework (dSYM file shrinks significantly). there’s a bunch of warnings preceeding:
    warning: linking module flags 'SDK Version': IDs have conflicting values ('[2 x i32] [i32 13, i32 0]' from /Users/username/.konan/kotlin-native-macos-1.3.61/klib/platform/ios_x64/Foundation/targets/ios_x64/native/cstubs.bc with '[2 x i32] [i32 13, i32 2]' from out)
    This warnings have been here for quite some time (caused by Xcode 11.3 being the active one on my machine I presume) but haven’t caused any issues so far so I’m not sure if they are related to the issue above or not.
    a
    s
    • 3
    • 8
  • k

    Kavan

    02/06/2020, 12:39 PM
    gethostbyname("<http://www.google.com|www.google.com>").pointed.h_addr_list
    is array of h_addr but in kotlin it's cpointer of bytearray How can I get first h_addr element ? I wanna use it in
    nativeHeap.alloc<sockaddr_in>.apply{ sin_addr.s_addr = /* here */ }
    • 1
    • 1
  • f

    fcosta

    02/07/2020, 5:02 PM
    Hi! Is there a web framework for kotlin native?
    b
    m
    +4
    • 7
    • 19
  • k

    Kavan

    02/08/2020, 11:33 AM
    I'm learning about compiler ? Can any one tell me what "Psi" stand for and what "Ir" stand for ?
    d
    f
    • 3
    • 4
  • k

    Kavan

    02/08/2020, 7:29 PM
    Look like Kotlin compiler built on Jetbrains IDE text parser.
    f
    m
    • 3
    • 2
  • b

    basher

    02/10/2020, 3:51 AM
    somewhere it's noted about how
    object
    s are initialized during runtime init on native. Does anyone know where that is?
    o
    • 2
    • 8
  • p

    Patrick

    02/10/2020, 9:47 AM
    I am trying to inspect the result of a Ktor HTTP call in Native using the lldb debugger. I’ve ran this line, which pretty prints the
    result
    of the call.
    (lldb) command script import konan_lldb.py
    (lldb) p result
    (ObjHeader *) $1776 = {'exception': {'stackTraceStrings$delegate': '...', 'message': 'Bad response: HttpResponse[<https://example.com/v1.0/authentication>, 401 Unauthorized]', 'cause': None, 'stackTrace': ['0x0000000100064397', '0x000000010005d7f5', '0x000000010005d3b5', '0x000000010005d995', '0x00000001002e916f', '0x00000001002e8c00', '0x00000001002ea3ea', '0x00000001002ea980', '0x00000001002f29cd', '0x00000001002f2d04'], 'response': '...'}}
    How would I now display the
    response
    property of the result? What is the best way to access it and display it in a readable format?
    v
    k
    r
    • 4
    • 13
  • n

    Nikolay Kasyanov

    02/11/2020, 8:23 AM
    hey, I’m curious if someone has solved the problem of publishing iOS frameworks as Maven artifacts (to Artifactory, for example). I know it’s not officially supported (yet?), are there good solutions out there? So far I’ve been able to find this: https://github.com/SalomonBrys/kotlin-ios-universal-framework.
    k
    • 2
    • 7
  • b

    basher

    02/11/2020, 9:24 PM
    What's the difference between
    lazy
    and
    atomicLazy
    ? Is
    lazy
    not thread-safe on native?
    k
    • 2
    • 4
  • j

    James

    02/11/2020, 10:53 PM
    Hi all, I’ve been taking a look at Kotlin/Native for the past couple of days looking at the possibility of using it for iOS and Android app development.  At the moment I’m taking a look at executing a network request using Ktor. Just a simple login request. If successful the API returns an auth token. This case works great. My problem is if the request is unsuccessful (the username / password combination is incorrect, one of the fields wasn’t provided, etc.) the API returns a 400 response and some JSON with a reason as to why the request failed. At the moment the only thing I get is the Throwable which tells me the error code. Ideally I’d like to still decode the json in the response to present a more helpful error message.  tl;dr: How can I deserialise the response of a failed network request?
    k
    j
    • 3
    • 4
  • l

    Luke Kellett

    02/12/2020, 7:58 PM
    Hey all, so I’m trying to use AppCode for the iOS/Swift side of my Kotlin/Native project and am finding that references to the “app” framework (from Kotlin/Native) show up as unresolved. It compiles and runs fine but the AppCode IDE simply doesn’t know where the library is?! So I have no code completion. The thing is if I switch over to XCode then the references are fine and I can get code completion for code in the “app” framework. Any ideas? Performing a clean doesn’t help either.
    v
    k
    • 3
    • 5
  • k

    kpgalligan

    02/13/2020, 1:29 AM
    I think I missed the memo. Does native run tests for darwin targets other than macos in 1.3.70?
    b
    m
    +3
    • 6
    • 8
  • n

    Nikolay Kasyanov

    02/13/2020, 10:02 AM
    hmm I’m getting “This cast can never succeed” warnings while building with Gradle and also in IDE. I’m casting between
    String
    and
    NSString
    (in both directions). Seems to be working fine in runtime too. The docs confirm that’s the way to go. Are these false positives?
    a
    • 2
    • 4
  • f

    felislynx

    02/13/2020, 10:13 AM
    Hi there, I'm trying to import cocoapods library in my k/n project, but following all available instructions, leaves me with unresolved import. I'm using cocoapods gradle plugin, add pods into cocoapods{}, generate podspec, add my podspec into podfile of ios project, make pod install, run workspace, build it, go back to android studio project and i have unresolved import :/
    a
    • 2
    • 53
  • m

    Myroslav Kolodii

    02/13/2020, 11:49 AM
    Maybe someone will be able to point me into right direction? I have several multiplatform modules in my project, which I would like to export to Xcode as frameworks. I already know it only possible to have only one multiplatform framework, so the task is to put all modules together and create a single framework from them. And this is where I stuck. Some are mentioning generating `.klib`s for each module and generate single framework from them, but is there some kind of a guide for this? Currently I’m using
    packForXcode
    gradle task from Kotlin tutorial (https://play.kotlinlang.org/hands-on/Introduction%20to%20Kotlin%20Multiplatform/01_Introduction). Ideal would be to modify it somehow to get several modules as input and produce one framework on output.
    r
    k
    • 3
    • 9
Powered by Linen
Title
m

Myroslav Kolodii

02/13/2020, 11:49 AM
Maybe someone will be able to point me into right direction? I have several multiplatform modules in my project, which I would like to export to Xcode as frameworks. I already know it only possible to have only one multiplatform framework, so the task is to put all modules together and create a single framework from them. And this is where I stuck. Some are mentioning generating `.klib`s for each module and generate single framework from them, but is there some kind of a guide for this? Currently I’m using
packForXcode
gradle task from Kotlin tutorial (https://play.kotlinlang.org/hands-on/Introduction%20to%20Kotlin%20Multiplatform/01_Introduction). Ideal would be to modify it somehow to get several modules as input and produce one framework on output.
r

russhwolf

02/13/2020, 1:38 PM
Use
packForXcode
as usual in your top-level module, and include the other modules in that one via
dependencies
block.
m

Myroslav Kolodii

02/13/2020, 1:40 PM
That’s what I’ve tried, but classes from sub-modules are not visible (tried with
api
)
Not visible from Xcode
r

russhwolf

02/13/2020, 1:45 PM
Ah. For visibility from swift you need an extra step in your
framework
block. See "Exporting Dependencies in Frameworks" section here https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries
m

Myroslav Kolodii

02/13/2020, 1:46 PM
Great, that’s probably what I was looking for. Thanks
r

russhwolf

02/13/2020, 1:46 PM
Needs either an explicit
export
for each or setting
transitiveExport = true
👍
k

Kris Wong

02/13/2020, 1:56 PM
if you have a maven repository, then you can publish the .klibs for each module and consume them in your umbrella project, producing a fat framework, or using the cocoapods plugin
otherwise, git submodules work as well
👍 1
View count: 9