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

    Meherdatta Chepuri

    03/10/2023, 1:58 AM
    Anyone know how to get over this issue https://kotlinlang.slack.com/archives/C3PQML5NU/p1678411533344589?thread_ts=1678405022.785259&cid=C3PQML5NU
  • a

    AmrJyniat

    03/10/2023, 8:03 AM
    Hi, a newbie KMM here I saw a different Coroutine dependency
    coroutines-core-native-mt
    for KMM project, is it correct that this one makes Coroutine works on IOS as Android? do still I need it in the newest version or the
    coroutines-core
    enough?
    j
    r
    +1
    4 replies · 4 participants
  • n

    natpryce

    03/10/2023, 8:15 AM
    Hi all… Does anyone have an example of a multiplatform JVM & Javascript project that uses the W3C DOM API? I’m not sure how to define the
    expect
    declarations because the DOM API is mapped to interfaces in the JVM platform and classes in the Javascript platform. The DOM objects are provided by factories in both platforms, so my code only needs to use the DOM objects, not instantiate the classes nor implement the interfaces. What should the expect declaration be?
  • a

    AmrJyniat

    03/10/2023, 9:28 AM
    I noticed that Napier logging library log/print the one line twice, is anyone faced the same problem or I'm missing something?
    d
    9 replies · 2 participants
  • r

    Rui Reis

    03/10/2023, 10:35 AM
    hey guys, I’m a newb in KMM, but keep finding this issue that when I try to run the iOs project (just a template project) from AS i get an error
    j
    7 replies · 2 participants
  • s

    Slackbot

    03/10/2023, 10:40 AM
    This message was deleted.
    k
    2 replies · 2 participants
  • h

    Hovo

    03/10/2023, 6:53 PM
    Hello, I have a question. Why KMM doesn't have IOS emulator in Windows? And will KMM have IOS emulator in Windows OS in the future?
    j
    s
    +3
    15 replies · 6 participants
  • m

    Meherdatta Chepuri

    03/10/2023, 7:47 PM
    I started using Cocoapods and app builds and works fine. However Im trying to use bamboo for running UI test cases on my existing iOS application. Only during CI runs , shared cannot be created. Any ideas on how we can fix this?
    l
    1 reply · 2 participants
  • p

    Pat Teruel

    03/10/2023, 9:28 PM
    Hello! I’m developing a Mobile SDK using KMM and I would like to confirm how “dangerous” is it to use
    GlobalScope.async
    ? Or is there an alternative way to do a
    DispatchQueue.global().async
    on KMM? My problem is, KMM doesn’t have a close-to-native way of Scheduling tasks without freezing the Suspend function. So I had to create a class that’s “invalidatable”, similar to that of the Timer in Swift.
    import kotlinx.coroutines.GlobalScope
    import kotlinx.coroutines.async
    import kotlinx.coroutines.delay
    
    class AsyncSchedulerCaller(
        delayTime: Long,
        suspendFunction: suspend () -> Unit
    ) {
        init {
            GlobalScope.async {
                delay(delayTime)
                if (invalidated) {
                    println("Invalidated.")
                } else {
                    isRunning = true
                    suspendFunction()
                    isRunning = false
                }
            }
        }
        var invalidated = false
        var isRunning = false
    
        fun invalidate() {
            invalidated = true
        }
    }
    The way I use this is I store it in an optional variable and invalidate if it exists and create a new one, e.g.
    class SomeClass { 
        var scheduler: AsyncSchedulerCaller? = null 
    
        suspend fun someSuspendFunction() { 
            runSomeApiCallHere() 
    
            scheduler?.invalidate() // this will make sure that the existing scheduled task will not be run
            scheduler = AsyncSchedulerCaller( 
                delayTime = 500, // will run after 500 milliseconds
                suspendFunction = {
                    runSomeOtherApiCallHere() 
                }
            )
        }
    }
    To be honest, it already runs properly in iOS, and the scheduled task seem to run in the background. But I want to understand why it does, else, I might encounter bugs and I wouldn’t know how to fix. That said, it works in iOS, but I haven’t tested in Android. Would this kind of code be dangerous on the app’s lifecycle in Android? Thanks for the answers.
    j
    b
    6 replies · 3 participants
  • h

    Harnick

    03/11/2023, 12:47 PM
    I may be barking up the wrong tree here, but I'm trying to create/destroy coroutine scopes when my viewmodels are instantiated/destroyed. I know
    Finalize
    wasn't the greatest solution when it came to Java's GC, but with KMM supporting more than just Android, is there a better way to destroy a coroutine scope along with its viewmodel?
    c
    7 replies · 2 participants
  • a

    Andrey

    03/11/2023, 3:11 PM
    Tell me, did anyone solve the problem of using llvm obfucator in a place with KMM? I'm only interested in the android platform. I usually use
    <https://github.com/darvincisec/o-llvm-binary>
    , but perhaps there is something else for KMM ? Any information would be helpful
  • k

    Koneko Toujou

    03/12/2023, 1:33 PM
    Does kotlin emit different bytecode for both android and desktop? Assuming both compile for the same source and same target, and both compile the exact same class
    m
    a
    8 replies · 3 participants
  • j

    Justin Xu

    03/13/2023, 2:09 AM
    I have a
    LoginManager
    that managers users logging into my app and downloading their data from database, and should be created/destroyed when the user logs in/out. Is there a common design pattern/implementation for this sort of dependency?
  • v

    Varun Sharma

    03/13/2023, 7:26 AM
    I am getting error below while trying to run a unit test in androiTest of KMM module. Any idea on how should I go about fixing it?
    Task 'testDebugUnitTest' not found in project
    a
    1 reply · 2 participants
  • a

    AndreiBogdan

    03/13/2023, 11:12 AM
    Hello. I am really, really unsure on how to access the badoo.reaktive
    Single
    from my native Android app . I have the following:
    fun getAssignedBooks(): SingleWrapper<List<String>> {
        return singleFromCoroutine {
            callAssignedBooks()
        }
            .subscribeOn(ioScheduler)
            .observeOn(mainScheduler)
            .wrap()
    }
    But when I try to do this:
    val assignedBooks = SharedBookRepository().getAssignedBooks()
    assignedBooks.subscribe()
    I get this:
    Cannot access 'com.badoo.reaktive.base.Source' which is a supertype of 'com.badoo.reaktive.single.SingleWrapper'. Check your module classpath for missing or conflicting dependencies
    Cannot access 'com.badoo.reaktive.single.Single' which is a supertype of 'com.badoo.reaktive.single.SingleWrapper'. Check your module classpath for missing or conflicting dependencies
    Any ideas why ? 😞 I'm using RxJava2 in my native Android app, I'd also like to chain the
    getAssignedBooks()
    with other observables and singles using
    .flatMap()
    and such, but not sure how I can do that. And it's been stressing me out for the past hour+
    a
    8 replies · 2 participants
  • h

    Harsh Joshi

    03/13/2023, 11:55 AM
    Hey I am not able to use String.format in Shared module that is powered by KMM. Does anyone has any clue?
    v
    t
    +1
    5 replies · 4 participants
  • h

    Harnick

    03/13/2023, 3:38 PM
    So this is more of a general practice question: A music application I'm working on requires the use of a user token for verification with a third-party service. Obviously it's best to encrypt this in local storage, but I'm struggling to think of implementations with shared key storage in the context of symmetric encryption. In Android, Keystore functions allow you to store the shared key (more) securely. Outside of that, the only way to access them in an application's data folder is via a process with root privileges, which can't commonly be created on a user's end. In Linux, I believe you can use the Secret Service API via D-Bus' libsecret if you're compiling to Kotlin/JS? That supports KDE and GNOME, I don't know if it supports other environments, like XFCE/LXQT/etc. I'm not experienced with Apple products at all, so I can't give any thoughts on that front. In Windows, I'm sure there's some old implementation that corrupts itself every 30 minutes, but I can't think of one. Regardless of all that, KeePass seems to be the only cross-platform example available for storing keys, and I'm finding it hard to visualise a universal approach to storing a key. I guess I could use a key derivation function, and ask the user for a password on each login, but that seems excessive for what the application is. Does anyone have any thoughts?
    d
    s
    10 replies · 3 participants
  • b

    Bradleycorn

    03/13/2023, 9:30 PM
    I’m using the new Experimental DSL to produce an XCFramework for iOS. My setup is pretty basic (a single module), and it seems to work (I can see the output xcframework in my build folder when I run the
    assembleMyLibXCFramework
    task. So far so good. Here’s how I have it configured:
    kotlinArtifacts {
        Native.XCFramework("MyLib") {
            targets(iosX64, iosArm64, iosSimulatorArm64)
            modes(NativeBuildType.DEBUG, NativeBuildType.RELEASE)
    
            linkerOptions = linkerOptions + listOf("-lsqlite3")
        }
    }
    Sooo … Now I want to publish the xcframework via cocoapods (eventually SPM as well, but one thing at a time…). I don’t see how the new DSL to produce the framework works with the existing
    cocoapods
    DSL provided by the
    native.cocoapods
    plugin? Or maybe they don’t work together at all? Can I publish an XCFramework generated with the Experimental DSL using cocoapods? How so?
    s
    a
    2 replies · 3 participants
  • s

    Stan

    03/13/2023, 11:22 PM
    I am new to kotlin, multiplatform, and I'm trying to debug a slightly modified version of the doodle contact tutorial: https://github.com/nacular/doodle-tutorials/tree/master/Contacts I generate source maps, and step through my own commonMain and jsMain source in the debugger, but I cannot "load content" from anything in
    <webpack://doodle-contacts/compileSync/*>
    Chrome/Debug Error:
    Could not load content for
    <webpack://doodle-contacts/compileSync/js/main/productionExecutable/kotlin/jsMainSources/libraries/stdlib/js/src/kotlin/collections/HashSet.kt?fb14>
    Fetch through target failed: Unsupported URL scheme; Fallback: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME)
    I would like to be able to step through kotlin library code, just like I do with JDK library code. I think I should be able to look at and step through any kotlin src in commonMain. But am I trying to do something that cannot be done? Here is my "most recent"
    js(IR) {
            browser {
                compilations.all {
                    kotlinOptions {
                        metaInfo = true
                        sourceMap = true
                        sourceMapEmbedSources = "always"
                        verbose = true
                    }
                }
                commonWebpackConfig {
                    devServer?.`open` = false
                    devServer?.`port` = 9090
                    mode = DEVELOPMENT
                    devtool = EVAL_SOURCE_MAP
                    sourceMaps = true
                    showProgress = true
                }
            }
            binaries.executable()
        }
    }
    I added a screen-shot of my debugger in the thread.
    1 reply · 1 participant
  • e

    elect

    03/14/2023, 9:50 AM
    I'm benchmarking my lib with
    kotlinx-benchmark-runtime:0.4.3
    and I'd like the
    jvmBench
    sources to extend the
    jvmMain
    , in order to avoid things as re-declaration of expected classes and so on In the readme, they simply write (in Groovy script)
    Propagate dependencies and output from
    main
    sourceSet.
    ```dependencies {
    benchmarksCompile sourceSets.main.output + sourceSets.main.runtimeClasspath
    }```
    how can I translate that to Kotlin DSL? Looking around at other examples, I tried the following, but without success:
    kotlin {
        targets {
            jvm {
                compilations {
                    val main by getting
                    val bench by creating {
                        defaultSourceSet {
                            dependencies {
                                implementation(main.compileDependencyFiles + main.output.classesDirs)
                            }
                        }
                    }
                }
            }
        }
    }
  • h

    Håkon Pettersen

    03/14/2023, 9:56 AM
    Hello. What could be causing duplicated files in the commonMain when implementing SqlDelight 1.5.4 in a KMM-library? It was working previously, but after updating multiplatform dependency to 1.8.10 and other dependencies like Ktor and serialization this started happening.
    h
    2 replies · 2 participants
  • b

    Brais Gabin

    03/14/2023, 10:12 AM
    Hello! Is out there any example to how to configure a KMM in a "convenient plugin"? I don't want to repeat the code inside the
    build.gradle.kts
    in all the modules for that reason I want to move all that to a gradle plugin. My problem is how to translate
    val androidMain by getting
    .
    c
    a
    6 replies · 3 participants
  • c

    ChChenna Rao

    03/14/2023, 10:49 AM
    Can any one have sample project which have below things. 1. Ktor with Mvvm Integration 2. Sqdelight for both Android and IOS. 3. Ktor(Api Success and Failure Cases) using Jetpack Compose
    v
    1 reply · 2 participants
  • i

    Idan

    03/14/2023, 11:19 AM
    Any alpha ktor client version out there with okhttp 5.0.0 engine? (for fastFallback support)
  • r

    rb90

    03/14/2023, 1:04 PM
    Hello 👋, I have a question regarding
    io.ktor.client.HttpClient
    . I am using it in a Kotlin Multiplatform project. For this, I followed the tutorial provided here: https://ktor.io/docs/getting-started-ktor-client-multiplatform-mobile.html. From what I see there, for the
    HttpClient
    I don't need to call
    .close()
    ? Because the Ktor docs here https://ktor.io/docs/create-client.html#close-client describe that close needs to be used to free up the resources. However if I am calling
    .close()
    on my instance of
    HttpClient
    and after that, I am trying a 2nd request with it, I got a crash. I tried that by calling my request function from my iOS client and I run in sth like this:
    kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=SupervisorJobImpl{Completed}@e50024f0
    . I am using one single instance in my Multiplatform module for the
    HttpClient
    like suggested in the Ktor docs:
    Note that creating
    HttpClient
    is not a cheap operation, and it's better to reuse its instance in the case of multiple requests.
    So there is no new instance created for each request. Is that usage correct? Can you please give me here an advice?
    c
    9 replies · 2 participants
  • m

    mohamed rejeb

    03/14/2023, 2:53 PM
    Hi 👋, checkout my latest KMP project using Compose multiplatform for Android, IOS and Desktop (Web Soon)! 99% of the code is shared! (UI, Navigation, Business logic, Networking, Caching, DI...) https://github.com/M0Coding/Pokedex
  • s

    spierce7

    03/14/2023, 3:48 PM
    If I have a multiplatform library with multiple Java source sets, how can I choose which source set I use when I import the library?
    r
    1 reply · 2 participants
  • v

    Vitaliy Zarubin

    03/15/2023, 5:57 AM
    Hello! Tell me, what top open source applications did you come across? Not demos on two pages, but full-fledged applications. Maybe there is "kotlin multiplatform applications awesome", I know this only from libs.
    p
    c
    2 replies · 3 participants
  • p

    Priyanshu Jain

    03/15/2023, 8:22 AM
    Hey everyone, after creating a new multiplatform module in an existing android application from the wizard using Cocoapods dependency, the project gives an error on Gradle Sync saying "Val cannot be reassigned" for version of cocoapods. I went to the CocoapodsExtension.kt file where version is defined as a var of String type and not as val. Does anyone know how to resolve this issue? Thanks.
  • h

    Hasan Nagizade

    03/15/2023, 8:52 AM
    Hello I have written an Android app with Kotlin Multiplatform project structure(there's common code,iOS module,android module). App is written in Jetpack Compose. How can I run this project in iOS? if you can recommend some articles it would be great. Also would this app be good enough for production?
    p
    11 replies · 2 participants
Powered by Linen
Title
h

Hasan Nagizade

03/15/2023, 8:52 AM
Hello I have written an Android app with Kotlin Multiplatform project structure(there's common code,iOS module,android module). App is written in Jetpack Compose. How can I run this project in iOS? if you can recommend some articles it would be great. Also would this app be good enough for production?
p

Pablichjenkov

03/15/2023, 9:39 AM
I run it from xcode. Before, I always do a clean / podbuildxcframework from the Android Studio gradle tasks panel, but only one time. After that initial steps, anytime I made changes either in kotlin or swift I just run the play button in xcode
h

Hasan Nagizade

03/15/2023, 9:40 AM
I am afraid I wrote the question a bit wrong. I want to run Android Compose code on iOS. currently iOS module is empty
p

Pablichjenkov

03/15/2023, 9:43 AM
If you plan to reuse the ui, it means you are going
compose multiplatform
, for that there are some official experimental templates
h

Hasan Nagizade

03/15/2023, 9:43 AM
is there any articles? I want to understand how it all works
p

Pablichjenkov

03/15/2023, 9:45 AM
https://github.com/JetBrains/compose-multiplatform/tree/master/experimental%2Fexamples clone the one you like the most and start playing with it
h

Hasan Nagizade

03/15/2023, 9:45 AM
is Google compose different from Jetbrains compose?
p

Pablichjenkov

03/15/2023, 9:46 AM
There are a couple other good templates, go to jetbrains account in GitHub and filter for templates, they just created a couple compose-multiplatform ones
The API is 99.9% similar.
The .1% is basically functionality specific to Android. Like interoperability between pointerInput events and Android touch events. Some classes/functions that you may see in Android compose but are missing in the jetbrains port. Really minimal cases, in my experience.
Things like that. But is the same compose just compiled/built for different platforms.
h

Hasan Nagizade

03/15/2023, 9:57 AM
Thank you very much
View count: 5