https://kotlinlang.org logo
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
  • j

    jared

    11/18/2020, 5:53 PM
    I am using
    kotlinx.coroutines
    1.3.9-native-mt-2
    and Ktor
    1.4.2
    in a multiplatform library for sharing networking between iOS and Android. I am confused over Ktor and background threads. I am using the
    Main
    dispatcher and I can’t tell if the network request is running on the main thread or a background thread. Does Ktor handle running a single background thread for me?
    j
    d
    a
    • 4
    • 21
  • c

    Cicero

    11/18/2020, 9:31 PM
    A small weird question, have you ever stumbled into adding a library and then suddenly your project is not recognized anymore as a Kotlin project? It took me a while to realize it was because of a library, ktor-client-gson specifically, and, when working with android, I didn't really stumbled on this before
    c
    • 2
    • 2
  • n

    Nikita Khlebushkin

    11/18/2020, 10:15 PM
    Hello! I have a KMM library created and developed from KMM template less than a month ago. It has the following structure:
    mobile-shared [SharedLogic]
    |____ ModuleShared
    |____ TestAndroidApp
    |____ TestIosApp
    I can build and compile KMM library, assemble .jar, Cocoapods - no problem here. Lately I've been trying to add this project as a module dependency to an Android project, which used to have the following structure:
    MyApp
    |____ app
    and now has the following structure:
    MyApp
    |____ app
    |____ mobile-shared [SharedLogic]
    |____|____ ModuleShared
    |____|____ TestAndroidApp
    |____|____ TestIosApp
    How I was trying to do it: Option 1: MyApp/settings.gradle.kts:
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            jcenter()
            mavenCentral()
        }
        resolutionStrategy {
            eachPlugin {
                if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
                    useModule("com.android.tools.build:gradle:4.0.1")
                }
            }
        }
    }
    
    include(":app")
    include(":SharedLogic")
    project(":SharedLogic").projectDir = File("mobile-shared")
    include(":SharedLogic:ModuleShared")
    MyApp/app/build.gradle.kts:
    ...
    android {
        dependencies {
            implementation(project(":SharedLogic:ModuleShared"))
    Option 2: MyApp/settings.gradle.kts:
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            jcenter()
            mavenCentral()
        }
        resolutionStrategy {
            eachPlugin {
                if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
                    useModule("com.android.tools.build:gradle:4.0.1")
                }
            }
        }
    }
    
    include(":app")
    include(":ModuleShared")
    project(":ModuleShared").projectDir = File("mobile-shared/ModuleShared")
    MyApp/app/build.gradle.kts:
    ...
    android {
        dependencies {
            implementation(project(":ModuleShared"))
    Error I encounter:
    A problem occurred configuring project ':SharedLogic:ModuleShared'.
    * Where:
    Build file '/home/xlebnick/projects/MyApp/mobile-shared/ModuleShared/build.gradle.kts' line: 40
    
    * What went wrong:
    This version of the kotlin-serialization Gradle plugin is built for a newer Kotlin version. Please use an older version of kotlin-serialization or upgrade the Kotlin Gradle plugin version to make them match.
    In ModuleShared/build.gradle.kts:
    plugins {
        kotlin("plugin.serialization") version "1.4.10"
    }
    In mobile-shared/build.gradle.kts:
    buildscript {
        repositories {
            gradlePluginPortal()
            jcenter()
            google()
            mavenCentral()
        }
        dependencies {
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
            classpath("com.android.tools.build:gradle:4.1.0")
        }
    }
    And in MyApp/build.gradle.kts:
    uildscript {
        apply(from = "versions.gradle.kts")
        val kotlinVersion: String by extra // 1.4.10
        val rootClasspath: List<String> by extra
    
        repositories {
            mavenCentral()
            google()
            jcenter()
            maven("<https://plugins.gradle.org/m2/>")
            maven("<https://maven.fabric.io/public>")
        }
    
        dependencies {
            classpath(kotlin("gradle-plugin", version = kotlinVersion))
            for (rc in rootClasspath) {
                classpath(rc)
            }
        }
    }
    What am I doing wrong? P.S. Found this issue, but it doesn't help at all
    • 1
    • 1
  • p

    Philip Dukhov

    11/18/2020, 10:24 PM
    Hi! I have a multiplatform module containing a server, with one kotlin multiplatform dependency module . Running it from main function with play button produces following error:
    Error: Could not find or load main class com.well.server.ApplicationKt
    I’ve found a solution to run it, using following task:
    task<JavaExec>("run") {
    main = "com.well.server.ApplicationKt"
    val jvm by kotlin.targets.getting
    val main: KotlinCompilation<KotlinCommonOptions> by jvm.compilations
    val runtimeDependencies = (main as KotlinCompilationToRunnableFiles<KotlinCommonOptions>).runtimeDependencyFiles
    classpath = files(main.output.allOutputs, runtimeDependencies)
    }
    One of the minuses - I can’t debug server and run an other module, because server starts running as part of task, and task progress remains 92 until I abort it. Is there a better solution? But the main goal right now is to deploy the server. Following the official guide, I tried this code:
    tasks.create("stage") {
    dependsOn(tasks.getByName("installDist"))
    }
    application {
    mainClassName = "ApplicationKt"
    }
    distributions {
    main {
    contents {
    from("$buildDir/libs") {
    rename("${rootProject.name}-jvm", rootProject.name)
    into("lib")
    }
    }
    }
    }
    tasks.getByName<JavaExec>("run") {
    `classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by
    jvmJar
    can be found and served`
    }
    But
    ./gradlew :server:run
    returns
    Could not find or load main class ApplicationKt
    error, and
    :server:jvmJar
    finishes without errors but doesn’t seems to produce the output
    b
    a
    • 3
    • 36
  • a

    Amritansh

    11/18/2020, 11:13 PM
    Hello, I am working on a KMM library which requires me to get these values from iOS and Android Devices.  • appVersion • connection type: Wifi or cellular • Carrier • Os version • Device model What will be the best way to approach this? Should I ask them at the time of initialization in the Apps or is there another way to get them internally from the KMM project? Happy to elaborate more if this does not make sense.
    w
    g
    s
    • 4
    • 6
  • w

    william

    11/19/2020, 1:05 AM
    has anyone tried using
    kotlin.Result
    in multiplatform? i'm not having any luck using it with
    kotlin {
        targets.all {
            compilations.all {
                kotlinOptions {
                    freeCompilerArgs = freeCompilerArgs + "-Xallow-result-return-type"
                }
            }
        }
    }
    I still get the message saying I can't use result as a return type
    • 1
    • 1
  • w

    william

    11/19/2020, 1:45 AM
    alternatively does anyone know of multiplatform Result libraries? i haven't been able to find one supporting jvm and ios
    z
    • 2
    • 8
  • r

    Rengu N

    11/19/2020, 5:26 AM
    Hello Team - Do anyone know how to make build variants for KMP especially for native iOS
    r
    • 2
    • 1
  • s

    Sergio Casero

    11/19/2020, 11:05 AM
    Hello guys, I have a kmp module with JVM target, the problem is that the IDE doesn't recognize it in one of my modules, it doesn't have any sense because, in fact, If I compile the project by manual putting the imports, it works perfectly, but the IDE doesn't recognize it, any solutions? I've included the dependency with
    implementation(project(":accesscontrol"))
    This is my 6th kmp project and I never get this issue. I have 3 JVM modules and works on 2 of them perfectly. I've tried cleaning the project, invalidating the cache, restarting the PC... When I execute
    ./gradlew run
    I can see that common related tasks are executed, and I can see the jar inside the build folder
    m
    • 2
    • 5
  • j

    Jeremias Nunez

    11/19/2020, 2:16 PM
    Hi All! I've successfully integrated a KMP module into an existing iOS app, but I'm having an issue with the difference between the generated Obj-C class name (Prefix+ClassName) and the Swift name (ClassName) of one of my classes. When I try to iterate over an array of such classes I'm getting this error:
    Precondition failed: NSArray element failed to match the Swift Array Element type
    Expected Movie but found SharedMovie: file Swift/ArrayBuffer.swift, line 354
    My Movie class is defined like this:
    @Serializable
    data class Movie(
        val name: String,
        val tone: String,
        val light: String,
        val url: String,
        val order: Int,
        val version: Int
    )
    I found this issue but it doesn't provide any possible solution: https://github.com/JetBrains/kotlin-native/issues/2830
    • 1
    • 1
  • c

    Cicero

    11/20/2020, 8:56 AM
    Yesterday I imported both my old android project and iOS to my new KMM projetect ❤️. But honestly the current public documentation is not good. If I didn't had some medium posts to help me out I would have failed, or taken way longer. If you would do this migration into KMM, which sources do you use? Do you know the process back and forth? Am I too green? I would like to hear other people experiences. I feel like there is still space for a good guide for it, with a video and all, I'm probably gonna put my hands on 🙃
    a
    g
    j
    • 4
    • 11
  • m

    mmaillot

    11/20/2020, 10:04 AM
    Hi ! I created a project with ktor server. I have a frontend with typescript. I’m looking for a solution to share API data between projects. My idea is to create a module in my ktor project which contains data class (using kotlinx.serialization) and API call (using ktor client). I want to generate the API calls for my frontend in typescript. Can I do that with MPP ? Do you have some links, tips ?
    • 1
    • 2
  • t

    Tristan Hamilton

    11/20/2020, 12:37 PM
    Hello! Looking to add iOS target for kotlin-result lib: https://github.com/michaelbull/kotlin-result/pull/23 Main issue up to now is not having a macOS machine to compile and publish with. Someone just pointed out that we could use a free github actions macos env, however if we need to install full xcode that will break the free storage limit. If we could just install the xcode cli tools, seems we would be ok. So when I originally went to add this I definitely read some doc that I believe mentioned needing full xcode installed (it used to mention something about it here: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#using-kotlinnative-targets but that page is now gone). Can anyone here confirm if xcode cli tools installed is enough to build iOS targets for multiplatform library?
    l
    • 2
    • 8
  • a

    Azur Haljeta

    11/20/2020, 5:55 PM
    Is there any recommended approach to make WebSockets work on both Android and iOS, since Ktor WebSockets are still not supported on Kotlin Native?
    t
    • 2
    • 10
  • o

    Ola Adolfsson

    11/21/2020, 7:44 PM
    Hi, is there anyone else having isses with the absolute paths in the npm packages creaeted by kotlin 1.4.* when it comes to consuming them in a “real” nodejs project? https://discuss.kotlinlang.org/t/local-dependencies-in-package-json-of-js-mpp-projects/19260
    👀 1
    a
    i
    i
    • 4
    • 7
  • c

    Cicero

    11/21/2020, 9:13 PM
    So, hello people, I’m trying to do something that I expected to be rather simple and it’s not working. I have this object:
    data class LoginModel(
        @SerialName("username")
        val username: String?,
        @SerialName("password")
        val password: String?,
        @SerialName("userType")
        val userType: String = "PROFESSIONAL"
    )
    With the serialisers and all, when I try to access it in swift I find this: - (instancetype)initWithUsername:(NSString * _Nullable)username password:(NSString * _Nullable)password userType:(NSString *)userType And when I try to use it on my code it kinda foces me to put something on my variable with a pre defined value, like this: let login = common.LoginModel(username: emailTextfield.text, password: passwordTextField.text, userType: “PROFESSIONAL”) I can live with this but I would like to know if there is an immediate solution. PS: It works fine on android, as intended. How default values work on swift: https://docs.swift.org/swift-book/LanguageGuide/Functions.html
    r
    b
    • 3
    • 4
  • s

    Skolson5903

    11/22/2020, 1:39 AM
    Saw 1.4.20 is out, tried upgrading a project from 1.4.20-RC that also uses the kotlinx atomic plugin
    buildscript {
            ...
            classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4")
        }
    Module build.gradle.kts:
    plugins {
            ...
            id("kotlinx-atomicfu")
         }
    After the upgrade the IDE (Android Studio 4.1) shows this import in error, but gradle build still works:
    import kotlinx.atomicfu.atomic
    In the IDE, the ending "atomic" is red as if it isn't in the dependencies, but gradle builds OK and tests run. Previously I had seen IDE-bad vs Gradle-good build issues in this project on the "java" package, but adding this to gradle.properties fixed that:
    kotlin.mpp.enableGranularSourceSetsMetadata=true
    That option is still set and doesn't help this new atomic issue. Anyone else seen this with 1.4.20? I'm still researching. Thanks in advance for any info...
    k
    • 2
    • 2
  • n

    napperley

    11/22/2020, 2:59 AM
    Looks as though I have stumbled on a bug where the dependencies for the first JVM module are applied, but not for the second one. IntelliJ is providing the option to include a library from classpath in the second JVM module, which the IDE shouldn't be doing with a platform module.
    • 1
    • 1
  • h

    Hai Tran

    11/23/2020, 9:02 AM
    What’s best way to implement multi-language in KMM? • split according to specific platforms • combine a common definition file(.kt, .xml,…)
    c
    • 2
    • 3
  • c

    Cicero

    11/23/2020, 11:51 AM
    Today I stumbled upon this article and there is a topic about compilation. Do we still suffer from this in KMM? https://medium.com/xorum-io/crafting-and-publishing-kotlin-multiplatform-library-to-bintray-cbc00a4f770 https://github.com/xorum-io/ReKamp
    a
    • 2
    • 4
  • j

    Jérôme Gully

    11/23/2020, 5:52 PM
    Hi, just got that, i find no communication in release note about that. BTW it's still compile and run on my Linux machine.
    g
    k
    • 3
    • 10
  • a

    aw

    11/23/2020, 7:09 PM
    Hello, is there any good tutorial about how to integrate
    shared.framework
    (which is exported from :*packForXcode*) via a
    cococapods
    into an existing App, without linking the App-project with the MPP-project (like in the Android Studio example)? We need to have the MPP-project separate from the iOS App and only use
    cocoapods
    to link the (prebuild) dependency. Every example I find either directly invokes :packForXcode from Xcode build-phases or uses
    cocoapods
    just to reference to the relative-path of the framework.
    k
    • 2
    • 19
  • a

    Amritansh

    11/23/2020, 9:48 PM
    Hello, How can we create a Singleton in Kotlin which takes some parameters? The reason I am asking this in this channel is because in kotlin native we can not have var in an object class unless you annotate it with ThreadLocal. I am not sure how to save value in a member variables of a singleton object class.
    t
    b
    • 3
    • 11
  • r

    russhwolf

    11/23/2020, 10:25 PM
    What’s the state of support for the
    kotlin.mpp.enableCompatibilityMetadataVariant
    flag for library authors to avoid compatibility issues with projects that don’t enable heirarchical project support? I see it in the JB libs, but can I use it or should I avoid it?
    b
    e
    • 3
    • 4
  • v

    Vincent Chen

    11/24/2020, 6:11 AM
    message has been deleted
    s
    m
    • 3
    • 2
  • j

    Jérôme Gully

    11/24/2020, 9:55 AM
    Hi, How do you encode/decode base64 in common code ? You go down to the android/ios specific sourceset ? I found that but it's seems forgotten https://github.com/Kotlin/kotlin-examples/pull/90
    g
    j
    b
    • 4
    • 4
  • p

    Paul Woitaschek

    11/24/2020, 10:30 AM
    We have created a library that is built on our CI linux machine. That library has no specific ios dependencies and all the logic resides in commonMain. Am I correct that I can't use that library at all unless I buy a mac and add an empty nativeMain source set and publish that?
    c
    a
    +2
    • 5
    • 8
  • p

    Philip Dukhov

    11/24/2020, 4:47 PM
    I wanna share env file among ios/android/server modules. I’ve created
    xcconfig
    file in Xcode, and shared it with android using
    android.buildTypes.resValue
    . How can I do the same with a KMP shared module?
    a
    • 2
    • 1
  • f

    Frankablu

    11/24/2020, 5:15 PM
    I'm doing a port of a Kotlin/JVM to multi platform (JVM/Js/Native), is there any libraries I can call on for basic file i/o aka read a text file to a string and write a text file to a string (i assume it exist but I can't find it). Also I've got concurrency in the JVM version using worker threads (read jobs from a task queue and write results to a result queue), any multi-platform equivalent library?
    b
    k
    • 3
    • 5
  • w

    why

    11/24/2020, 6:37 PM
    Hi.. I’m in a need of a weakly referenced object like the one in java (WeakReference) how can I achieve that in KMP? In other words I need some objects to be cleared by the garbage collector when it’s weakly reachable
    t
    • 2
    • 1
Powered by Linen
Title
w

why

11/24/2020, 6:37 PM
Hi.. I’m in a need of a weakly referenced object like the one in java (WeakReference) how can I achieve that in KMP? In other words I need some objects to be cleared by the garbage collector when it’s weakly reachable
t

Tijl

11/24/2020, 8:59 PM
that depends on which platforms you are targeting, Kotlin/Native has kotlin.native.ref / WeakReference , and JS has it’s own WeakRef, but that’s not supported in all browser
👍 1
View count: 7