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

    nrobi

    01/21/2020, 10:16 AM
    I’m using
    cocoapods
    to add the dependency for my
    common
    . However I’m getting
    Could not build Objective-C module 'common'
    without any more information. Is there any way to find more information why is the build failing?
    a
    s
    • 3
    • 15
  • t

    Tristan

    01/21/2020, 4:15 PM
    Anyone has already tried this project? https://github.com/joreilly/PeopleInSpace It uses SwiftUI and Jetpack Compose. I can get it running on Android, but not on iOS. I did a gradlew build (takes around 5mins) and then I tried to open the project in XCode. Everything seems fine, but I have a error saying
    import common // <- Not found
    . How should I proceed?
    d
    • 2
    • 3
  • s

    Sujit

    01/21/2020, 4:18 PM
    I kept on making a new kotlin multiplatform project for android and iOS library from scratch over the past few months for various projects I was working on. So, made a starter project to help me, and anyone who needs it here: https://github.com/sujitpoudel/kmp-android-ios-starter Sets up the android side of library with API 29, has gradle task to build iOS fat framework and a setup as well as release script I use. Hope someone finds this useful.
    👍 4
    m
    • 2
    • 1
  • s

    spierce7

    01/21/2020, 8:06 PM
    @elizarov @olonho A few questions (code on thread) 1. Should the property be frozen? The parent
    this
    isn’t frozen, and it seems like the property shouldn’t be frozen since it’s only ever touched by one thread. 2. I’m not seeing an exception when I attempt to mutate something that’s frozen. That seems odd. 3. I’m pretty sure I was seeing different behavior a month or so back (around Kotlinconf) where the property wasn’t frozen. Am I imagining this?
    k
    d
    +2
    • 5
    • 41
  • j

    Joey

    01/22/2020, 3:40 AM
    Hi guys, im fetching a api endpoint and the data looks like this.
    {
      "-LzAGaZtoPN702hIyUPh": {
        "isActive": true
      }
    }
    I wonder how can i get the dynamic key? Thanks!
    t
    • 2
    • 3
  • a

    abdellah

    01/22/2020, 10:32 AM
    Hello everyone, is there any open source project made based on Sqldelight and Ktor ?
    a
    k
    • 3
    • 9
  • j

    Julius

    01/22/2020, 1:55 PM
    Hi everyone, Im currently trying to hash a password with SHA-1. But for some reason iOS does emit some zeros Android:
    val HEX_CHARS = "0123456789abcdef"
            val bytes = MessageDigest.getInstance("SHA-1").digest(stringToHash.toByteArray())
            val result = StringBuilder(bytes.size * 2)
    
            bytes.forEach {
                val i = it.toInt()
                result.append(HEX_CHARS[i shr 4 and 0x0f])
                result.append(HEX_CHARS[i and 0x0f])
            }
    
            return result.toString()
    iOS:
    val input = stringToHash.encodeToByteArray()
            val digest = UByteArray(CC_SHA1_DIGEST_LENGTH)
            input.usePinned { inputPinned ->
                digest.usePinned { digestPinned ->
                    CC_SHA1(inputPinned.addressOf(0), input.size.convert(), digestPinned.addressOf(0))
                }
            }
            return digest.joinToString(separator = "") { it.toString(16) }
    :stackoverflow: 1
    c
    o
    • 3
    • 3
  • a

    Arkadii Ivanov

    01/22/2020, 2:29 PM
    How to use Android resources in an
    androidMain
    source set? I tried both
    res
    and
    resources
    folder names, the last one seems recognized but resources are not accessible (nor from the code or from e.g. layouts).
    k
    • 2
    • 4
  • n

    nrobi

    01/22/2020, 2:54 PM
    Hey, anyone had an issue with
    -Xobjc-generics
    ? I’m getting
    Any?
    on iOS when I’m trying to consume some generics
    k
    v
    • 3
    • 13
  • m

    Maurice Jouvet

    01/22/2020, 3:56 PM
    How can I add annotationProcessor on my build.gradle.kts (DSL)? (I’m on Android part here) I need that:
    kapt("androidx.lifecycle:lifecycle-compiler:$lifecycleVersion")
    But with my configuration it’s not working, can’t find the solution.. It says, required KaptOption.. Here is what I have:
    sourceSets {
        val androidMain by getting {
            kotlin.srcDir("src/main/kotlin")
            dependencies {
                kapt("androidx.lifecycle:lifecycle-compiler:$lifecycleVersion")
    k
    • 2
    • 18
  • m

    Maurice Jouvet

    01/23/2020, 8:40 AM
    Quick question, I am building my KMP app with sqldelight and I saw on the documentation that we need to add -lsqlite3 for compilation. I put it but I have this error now : e: Invalid argument: -lsqlite3 Conf:
    configure(listOf(iosArm32, iosArm64, iosX64)) {
            compilations {
                val main by getting {
    //                extraOpts("-Xobjc-generics -lsqlite3")
                    kotlinOptions {
                        freeCompilerArgs = listOf("-Xobjc-generics", "-lsqlite3")
                    }
                }
            }
    
            binaries.framework {
                export("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version")
                baseName = frameworkName
            }
        }
    b
    • 2
    • 1
  • c

    chrmelchior

    01/23/2020, 11:05 AM
    Anyone know how you set
    kotlinOptions
    (specifically
    freeCompilerArgs
    ) for
    android
    targets? I must be missing something obvious, but
    android.compilations
    is just an empty array (which is also a bit weird and doesn’t match https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#default-project-layout) and using
    targets.all {
            compilations.all {
                kotlinOptions {
                    freeCompilerArgs = ["..."]
                }
            }
        }
    does not work either (which kinda makes sense since the compilations array is empty).
    o
    k
    • 3
    • 3
  • s

    Sylvain Patenaude

    01/23/2020, 2:29 PM
    Has anyone seen the following warning? Trying to build a test app on iOS (that imports a <MyLibraryName>.framework).
    linking module flags 'SDK Version': IDs have conflictiing values...
    b
    • 2
    • 2
  • s

    Sylvain Patenaude

    01/23/2020, 7:41 PM
    I have a function returning
    Array<String>
    in Kotlin Multiplatform. Is this specific type consumable from Swift? If so, what is the equivalent type in Swift? EDIT: Looks like it's
    KotlinArray
    in Swift. EDIT2: Well, looks like
    KotlinArray
    is a generated type from my framework itself. I wonder if I shouldn't use
    List<String>
    instead of
    Array<String>
    ? Would it then translate into the desired type in Swift (which would be
    [String]
    I guess)?
    a
    • 2
    • 2
  • h

    Henrik

    01/24/2020, 7:32 AM
    Question about shared state in Android/iOS MPP. I have a working setup with compilation to Android and iOS, but now I have run into the whole frozen state world (new to me) and is stuck after some hours of trawling the web for info and examples. Simplified, I have a static global variable CurrentConfig which points to the current version of a parsed JSON config. This is used in many places of the app, so they should not load and parse it all the time on their own, but share it. Once in a while, the config is replaced with a freshly downloaded one on the fly. I guess this is an often seen pattern, but I have no idea how to solve it using Kotlin Native. Anyone have a best practice example to accomplish something like this?
    o
    p
    k
    • 4
    • 17
  • j

    Juhani Lehtimäki

    01/24/2020, 2:57 PM
    So maybe this is asked here already but we have an issue. All functions in our shared code marked as
    suspend
    do not show up in the compiled iOS code and cannot be called. Do we have to remove coroutine support from our shared code or is there some trick to make it work?
    k
    l
    +2
    • 5
    • 44
  • k

    Kris Wong

    01/24/2020, 3:41 PM
    man, IDEA is on the fritz in one of my MPPs. Code navigation is off. It's showing code errors in random places.
    s
    l
    • 3
    • 9
  • c

    CLOVIS

    01/25/2020, 10:37 PM
    What is the state of Multiplatform currently? Is it worth trying to publish a Multiplatform library now, before KLib comes?
    r
    d
    • 3
    • 4
  • n

    Nick Halase

    01/25/2020, 11:00 PM
    Can someone please enlighten me on unit testing with Kotlin multiplatform? As I understand it,
    commonMain
    and
    commonTest
    SourceSets
    exist regardless of the target. If my project only has ios and android targets, does that mean I can't run unit tests on the common code contained in
    commonTest/test
    ?
    b
    l
    s
    • 4
    • 19
  • g

    Grantas33

    01/25/2020, 11:06 PM
    build/js/packages_imported/ktor-ktor-client-core/1.3.0/ktor-ktor-client-core.js
    Module not found: Error: Can't resolve 'abort-controller' in 'build\js\packages_imported\ktor-ktor-client-core\1.3.0'
    build/js/packages_imported/ktor-ktor-io/1.3.0/ktor-ktor-io.js
    Module not found: Error: Can't resolve 'text-encoding' in 'build\js\packages_imported\ktor-ktor-io\1.3.0'
    I'm having these errors in the browser console of my KotlinJS project. I'm not using ktor as a direct dependency - I use a kotlin multiplatform library which uses ktor. I've had the same errors when developing the aforementioned library, and after adding jsMain npm dependencies in the library's build gradle file like this:
    api(npm("text-encoding"))
    api(npm("abort-controller"))
    the errors dissapeared from the library. However, they still do exist in my KotlinJS project which uses this library. What could be the issue here?
    b
    • 2
    • 1
  • l

    lavong

    01/26/2020, 9:51 AM
    Hi there. Anyone here measuring code coverage on a kotlin multiplatform project? Are there any good tools out there?
    JaCoCo
    obviously helps with JVM code only at best, right?
    b
    • 2
    • 2
  • b

    baxter

    01/26/2020, 10:43 PM
    Hi! I'm working on a MPP library, but wondering if there is some standard practice yet on having a pure Kotlin/MPP module with Jvm pure sources and Android specific sources. My current setup is Kotlin/MPP module with pure Jvm sources, and a second module for the Android sources. If this is the current standard practice... sweet! If not, I would appreciate any enlightenment! Thanks!
    k
    • 2
    • 2
  • p

    Piasy

    01/27/2020, 12:19 PM
    Hey guys, I'm making Kotlin Multiplatform work on Windows now, but I have an issue of calling Kotlin back from C++. Here is my use case: I want use socket.io-client-cpp to connect to a SocketIO server, and get a callback when it connects successfully. But the callback is not invoked on main thread, I do notice the note on the C Interop page, calling
    kotlin.native.initRuntimeIfNeeded()
    in my kotlin code before I connect to server, but it still crash my program. If I fire the callback on main thread, e.g. APP C++ code calls
    kotlinTestFunc
    , which calls
    cppSocketIOConnect
    , and fire the callback directly inside
    cppSocketIOConnect
    , it works fine. Do I miss something?
    👀 1
    a
    • 2
    • 14
  • b

    Big Chungus

    01/27/2020, 3:51 PM
    Is there a way in MPP project to only enable publication of one platform?
    d
    b
    • 3
    • 2
  • m

    Maurice Jouvet

    01/27/2020, 4:28 PM
    Hi everyone, is there some gradle “tweaks” to speed up the build time on KMP? Whenever I change a small portion of code in SharedCode, it takes almost 4-5 minutes to rebuild.
    k
    • 2
    • 2
  • v

    Venkat , Bangalore , India

    01/28/2020, 6:50 AM
    I am facing the issue similar to https://stackoverflow.com/questions/58620688/nsinv but ONLY in iOS 11 but not in iOS 13
    a
    • 2
    • 10
  • b

    Big Chungus

    01/28/2020, 1:20 PM
    Does dukat integration works on MPP gradle plugin? `
    kotlin.js.experimental.generateKotlinExternals=true
    seems to be doing nothing (or I might be looking for generated externals wrong)
    i
    • 2
    • 2
  • k

    Kris Wong

    01/28/2020, 4:59 PM
    is there a "right way" to run android unit tests when all the tests are in commonTest?
    b
    r
    • 3
    • 7
  • b

    baxter

    01/29/2020, 4:45 AM
    So I’ve been playing with multiplatform for a few weeks now, and I finally reached a small milestone for it. I have CircleCI compiling each platform on my project (Jvm, Node.js, Browserify, Linux, and Windows) and running the common tests.
    🎉 2
    d
    • 2
    • 2
  • n

    nrobi

    01/29/2020, 7:55 AM
    Is there a way to expose arrays with explicit type from the common? Currently I’m getting my
    List<SomeModel>
    converted to
    NSArray
    with losing the information about it’s type,
    SomeModel
    a
    o
    k
    • 4
    • 6
Powered by Linen
Title
n

nrobi

01/29/2020, 7:55 AM
Is there a way to expose arrays with explicit type from the common? Currently I’m getting my
List<SomeModel>
converted to
NSArray
with losing the information about it’s type,
SomeModel
a

Andrey Chernov

01/29/2020, 8:17 AM
This one should help you https://kotlinlang.slack.com/archives/C3PQML5NU/p1579685197083900
o

Olenyov Kirill

01/29/2020, 8:43 AM
“-Xobjc-generics” - it’s just a partly solution. See my question about generics. https://kotlinlang.slack.com/archives/C3PQML5NU/p1579344665010100
👍 1
n

nrobi

01/29/2020, 9:26 AM
Ah, I see @Olenyov Kirill. So this is a Swift <-> Objc interop problem. Actually I have an
Observable<List<SomeModel>>
and my use-case is the same as yours with
test2
k

kpgalligan

01/29/2020, 9:41 AM
I wrote the generics implementation. There are restrictions imposed by objective-c, such as you can’t have generics on interfaces (protocol in objc). Collection types have special handling in both objc->swift and in how the headers are generated from kotlin. In many general cases they work. You can certainly find cases where generic types are dropped as well.
Observable is an interface. It will not retain generics. That’s an objc problem.
n

nrobi

01/29/2020, 9:48 AM
Managed to work around the interface problem, with
E/A
for the
Observable
and abstract class instead of interface for the
Observer
View count: 3