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

    Tristan

    05/31/2021, 1:52 PM
    Hello, I'd like to present Kotlin Multi-Platform has alternative to our current stack for a specific product in my company (we are more than 3000 employees). The concerned product is an Ad SDK, witch is a critical part of our business. Its architecture is roughly the same since 2016, and was not prepared for the iteration of features we had on it. Today, there is more than 20 developers working it. Our current architecture is: Native iOS SDK (Obj-C), Native Android SDK (Java), Webview (TypeScript) The native parts are used to load the WebView and expose some APIs to it. Native part and WebView communicate via messages. This architecture allows us to update our features without having to re-compile a binary, which would force game developers to update their app and re-publish it. We can quickly implement new ad formats, or introduce new UIs. Synchronizing all the APIs between these 3 components can be tricky and requires extra efforts on communication. We also have some extra work on re-implementing things on both native side, when it could be exactly the same on both side (such as adding extra fields to some of our requests). So now my question 🙂 Do you have any slides pre-made that presents Kotlin and Kotlin Multi Platform? I'd like to avoid to create them if they already exist and focus on example that applies to our tech stack.
    n
    • 2
    • 2
  • t

    Tiago Nunes

    05/31/2021, 4:40 PM
    Hey everyone, is there a way to launch coroutines in Swift? I have this function in shared:
    suspend fun wait() = withContext(Dispatchers.Default) {
        delay(1000)
        true
    }
    How do I call this in Swift? I know I can launch a coroutine in shared and provide callbacks (and then call this in swift):
    fun waitIos(onFinished: OnFinishedCallback) = GlobalScope.launch {
        val result = wait()
        onFinished.finish(result)
    }
    But this way I need to write lots of wrappers and use callbacks, which kind of takes the fun out of using coroutines... (in the ios side) It makes sense if it isn't possible, I just want to make sure that it really isn't
    j
    r
    • 3
    • 6
  • a

    Aldan Rizki Santosa

    06/02/2021, 4:12 AM
    Is KMM ready for production?
    :yes: 7
    👍 2
    x
    • 2
    • 1
  • s

    spierce7

    06/02/2021, 4:57 AM
    Is there a multiplatform file API yet?
    k
    • 2
    • 4
  • a

    Alex Anisimov

    06/02/2021, 12:18 PM
    Hey folks! The KMM team is wondering what libraries you lack the most? Please share areas where you would like to have more libraries in the comments.
    m
    d
    +13
    • 16
    • 24
  • o

    Osman Saral

    06/02/2021, 12:44 PM
    Hello, It's probably Xcode related but maybe I can find an answer here. So here it is: When I try to build the iOS app from Xcode, it doesn't build Pod targets (and shared library). When I make a change on shared library, I need to manually build shared target every time. Did anyone have a problem like this? I'm using M1 macbook, it might be related. Even if it's not the same thing I've also find this. The difference is, my problem is not about the order of the builds.
    • 1
    • 1
  • c

    Charles Prado

    06/02/2021, 1:27 PM
    Hey guys. I'm trying to consume a sealed class on the iOS side. In iOS the method return a completion handler with
    SessionManagerCheckInResult<UserInfo>?
    being
    SessionManagerCheckInResult
    is the sealed class:
    sealed class CheckInResult<out T : Any> {
            data class Success(val data: UserInfo) : CheckInResult<UserInfo>()
            data class Error(val exception: Throwable) : CheckInResult<Nothing>()
        }
    I'm trying to get the error when I receive one, but I'm not able to get the result or error separated here. What I get if I print the object is:
    ▿ Optional<SharedSessionManagerCheckInResult>
      - some : Error(exception=ApiError(code=400112, message=Invalid or missing members in payload
    ...
    How can I get this error in iOS side? Some way I can convert the data to a
    SharedSessionManagerCheckInResultError
    here?
    s
    • 2
    • 10
  • v

    Vitor Prado

    06/02/2021, 1:31 PM
    Can someone tell me the idea behind
    compose compiler
    running on K/N?? We can expect composables in KMP world?
    m
    f
    +2
    • 5
    • 5
  • s

    solidogen

    06/02/2021, 6:22 PM
    did anyone try/know an existing sample of compose+swiftUI with shared viewmodel?
    k
    m
    • 3
    • 7
  • a

    Ahmed Mourad

    06/02/2021, 9:45 PM
    Hey everybody, I have two multiplatform modules
    A
    and
    B
    , both of which only contain
    commonMain
    and
    commonTest
    source sets and have
    jvm
    ,
    js
    and
    ios
    as targets. Also
    B
    depends on
    A
    . The problem is I can't reference the classes defined in the
    commonMain
    of
    A
    inside the
    commonMain
    of
    B
    , so something is probably wrong with my Gradle files...
    r
    • 2
    • 4
  • j

    jw

    06/03/2021, 2:29 AM
    is it possible to exclude files from commonTest from being compiled as part of, say, jsTest? I tried the naive thing of adding
    jsTest { kotlin { exclude '..' } }
    but it seems to have no effect. my current workaround is to eliminate the commonTest srcDir and add it as a srcDir to each platform-specific target's test source set and then do the exclude
    ➕ 4
    l
    t
    r
    • 4
    • 21
  • u

    ursus

    06/03/2021, 3:14 AM
    Is there some limitation if I were to buy apple M1 mac? (to build ios targets etc)
    c
    h
    • 3
    • 7
  • f

    Fabio Santo

    06/03/2021, 5:54 AM
    Hey everyone 👋 did ever occur to you that the gradle task
    iosX64Test
    hangs on loading ? No error is surfaced... 🤔
    x
    r
    • 3
    • 3
  • o

    Osman Saral

    06/03/2021, 7:20 AM
    Hello everyone, Since Multithreaded coroutines a thing now, do we need to use stately (or freeze state in general)? Documentation points against it, says The concurrency libraries mentioned here will freeze your data automatically. I'm using KaMPKit to get used to things, even if it uses multithreaded coroutines, stately is also used. So I'm really confused 😕 some concurrency concepts are hard for me to understand, should I really dive into those and try to learn as a KMM beginner?
    n
    s
    k
    • 4
    • 9
  • t

    tylerwilson

    06/03/2021, 1:14 PM
    Okay, so I moved up to Kotlin 1.5.10 (now that Compose beta8 supports it) and I am now getting exceptions on iOS in my common code in what was working network code. I do something like this:
    GlobalScope.apply {
                launch(ApplicationDispatcher) {
                    try {
                        val result: String = client.get {
    I know that GlobalScope is now a ‘delicate’ API. What is the preferred/canonical/best way to launch network calls in common code now? Thanks!
    s
    a
    • 3
    • 11
  • h

    Hossein Amini

    06/03/2021, 3:56 PM
    Hello, how to localize a kmm project by adding all texts and messages in the shared module?
    o
    x
    • 3
    • 3
  • a

    andylamax

    06/04/2021, 12:28 AM
    Hello, forgive me if this is the wrong channel, but. I would love to know how the kotlin libraries (i.e. kotlinx-serialization, kotlin-stdlib-jdk8) are compiled and they support all the versions of java. Starting from jdk8 to jdk15?
    r
    • 2
    • 9
  • g

    Gamadril

    06/04/2021, 8:37 AM
    How can I solve the "The 'java' plugin has been applied, but it is not compatible with the Android plugins." problem if my KMM module has to target both platforms: jvm and android
    a
    m
    c
    • 4
    • 11
  • a

    Anton Afanasev

    06/04/2021, 7:16 PM
    Hi here! How do you usually handle code that is sharable between platforms, but have unique or platform specific dependencies? For instance my expected constructor has 1 mandatory argument that I would like to share between platforms.
    expect class MailBox(firstName: String) {}
    Now, I want that my Android actual implementation will have some Android specific object passed as well. Lets say Context I can not do
    actual class MailBox actual constructor(firstName: String, context: Context) // not allowed as actual constructor does not match the expected.
    If I use a secondary constructor, I cannot be sure that it will be called and therefore Context is going to be of
    Nullable
    type and smell.
    actual class MailBox actual constructor(firstName: String) {
        private var context: Context? = null // Context is of Nullable - not nice
        
        constructor(context: Context, firstName: String = "Bobby", ) : this(firstName) {
            this.context = context
        }
    Obviously, I can declare my expected without primary constructor - but then I have no control over each platform passing a mandatory argument.
    expect class MailBox {} //commonMain
    
    actual class MailBox(context: Context, firstName: String) {} //androidMain
    
    actual class MailBox(firstName: String) {} //iOSMain
    
    //No ability to force passing `firstName` argument. Any platform can decide to modify/remove `firstName` on their will.
    QUESTION: Are there any other, cleaner approaches that allows me to force some expected constructor values mandatory, while others can be platform specific?
    d
    k
    r
    • 4
    • 4
  • o

    Ola Adolfsson

    06/04/2021, 8:18 PM
    Good evening, what’s the status regarding generating usable typescript definitions in JS targets? For now, we have to maintain them manually. If someone has better suggestions, please share 🙂 .
    b
    • 2
    • 3
  • s

    spierce7

    06/04/2021, 10:14 PM
    Does anyone know how to get a sibling java gradle module to be usable from Kotlin multiplatform? In the jvmMain source set I’m adding it as a direct implementation dependency, and the ide is telling me it can’t import those classes.
    r
    • 2
    • 3
  • x

    xxfast

    06/05/2021, 1:23 AM
    Are there any kotlin multiplatform resource libraries? I know of moko-resources, but that is yet to support jvm targets
    b
    • 2
    • 3
  • c

    Colton Idle

    06/05/2021, 4:21 AM
    Not sure if this is a better question for #multiplatform or for #compose-desktop but I'll ask here first. I basically have an android project with an app module. Really simple. Then I added a
    composables
    module. Android only. This left my composables module with a build.gradle with a top level
    dependencies{}
    block. I now converted it to multiplatform for compose desktop and so I have dependencies declared in a
    kotlin {}
    block. i.e.
    kotlin {
        android()
        jvm("desktop")
    
        sourceSets {
            named("commonMain") {
                dependencies {
                    api(compose.runtime)
                    api(compose.foundation)
                    api(compose.material)
                }
            }
        }
    }
    My question (sorry for being a complete kmm noob) is that is there any reason why I would keep a top level dependencies{} block around? I still have dependencies defined there, but if I remove it then everything seems fine. When using kmm is the gist that we never use top level dependencies block?
    r
    • 2
    • 5
  • c

    Charles Prado

    06/05/2021, 5:19 PM
    There's any way to make iOS headers understand default properties set on the Kotlin side? In Kotlin I have this class:
    @Serializable
    @Parcelize
    data class SomeClass(
        val id: String = "",
        val name: String = "",
        val mandatory1: String,
        val mandatory2: String,
    )
    On the iOS side, what I want is:
    // SomeiOSClass.swift 
    let instance = SomeClass(mandatory1: "foo", mandatory2: "bar")
    instead of :
    // SomeiOSClass.swift 
    let instance = SomeClass(id: "someId", name: "someName", mandatory1: "foo", mandatory2: "bar")
    Is it possible to not have to set those properties that already have a default value defined on Kotlin's side?
    e
    x
    • 3
    • 4
  • x

    xxfast

    06/06/2021, 3:25 AM
    Is there a way to get what system we are on and its version in `desktopMain`/`jvmMain`?
    d
    • 2
    • 5
  • c

    Colton Idle

    06/06/2021, 12:50 PM
    Multiplatform noob here. I'm converting an android only library module to something that will support desktop in the future. This is my current directory structure, but from what I'm seeing, I basically would not use
    /main
    or
    /test
    anymore for any reason, right? common code goes into commonMain and android specific code would go into androidMain, while desktop specific goes into desktopMain?
    t
    • 2
    • 4
  • a

    Alexey Glushkov

    06/06/2021, 4:00 PM
    Hi, is there any way to understand what is the latest supported version of android gradle plugin for KMM? Now I use 7.0.0-alpha12 and it works with Compose well in
    Android Studio Arctic Fox | 2020.3.1 Canary 12
    . But when I try to switch to
    2020.3.1 Beta 2
    it requires gradle plugin 7.0.0-beta02 which, I suppose, isn’t supported by KMM. I think so as I get this error
    Please initialize at least one Kotlin target in 'shared (:shared)'
    Should I keep using
    2020.3.1 Canary 12
    or there is a way to make beta work?
    ✅ 1
    i
    • 2
    • 10
  • m

    mayojava

    06/07/2021, 7:20 AM
    KMM noob here, I am having an issue with getting the right version of Android studio and KMM plugin that works together. I am currently using AS 2021.1.1 Canary 1 and KMM plugin 0.2.4(203-1.5.0-release-759-IJ)-57, but whenever I create a new KMM project I get an error saying the project name is not a Gradle-based project.
    l
    k
    • 3
    • 3
  • n

    Napa Ram

    06/07/2021, 11:11 AM
    Hi Everyone can anyone guide me how i can use ViewModel in KMM Is there any example with Use Case, Repository and ViewModel in CommonMain
    b
    r
    +2
    • 5
    • 13
  • r

    robjperez

    06/07/2021, 3:51 PM
    Hi there!. I’m having issues when doing iOS with KMM. My main problem is how to handle the callbacks in the form of completion blocks. Some iOS callbacks happen in a different thread on which the function is called. When this happen, the lambda that serves as completion block cannot be called because it was created in a different thread. I tried to freeze the lambda, and although it works, then the problem is that the lambda cannot access almost anything because it would freeze it as well. Which is the best way to deal with these issues? Thanks!!
    a
    • 2
    • 1
Powered by Linen
Title
r

robjperez

06/07/2021, 3:51 PM
Hi there!. I’m having issues when doing iOS with KMM. My main problem is how to handle the callbacks in the form of completion blocks. Some iOS callbacks happen in a different thread on which the function is called. When this happen, the lambda that serves as completion block cannot be called because it was created in a different thread. I tried to freeze the lambda, and although it works, then the problem is that the lambda cannot access almost anything because it would freeze it as well. Which is the best way to deal with these issues? Thanks!!
a

ahmedre

06/07/2021, 6:07 PM
i think you’ll find the 2 articles that are part of this set to be useful - https://dev.to/touchlab/kotlin-coroutines-and-swift-revisited-j5h
:thank-you: 1
View count: 3