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

    Christian Sousa

    07/13/2020, 11:16 AM
    Hello! Is there any way of using a javascript library on the multiplatform common code?
    g
    • 2
    • 9
  • s

    Sergey Melyukov

    07/13/2020, 1:52 PM
    Hello! I have a non-published multiplatform kotlin library
    com.foo.bar
    I want to create another multiplatform project with some examples of using
    com.foo.bar
    How can I add
    com.foo.bar
    as a local dependency for my demo-project?
    k
    • 2
    • 1
  • s

    Sergey Melyukov

    07/13/2020, 1:56 PM
    Or maybe I can add some examples of
    com.foo.bar
    within
    com.foo.bar
    project to not to create a separate repo with examples?
    s
    • 2
    • 6
  • j

    Jim

    07/14/2020, 4:14 AM
    I'm starting a project with the experimental release of kotlin 1.4 and am trying to get kapt to work but get this error
    ype mismatch: inferred type is String but Action<KaptExtension> was expected
    I've tried moving kapt (and the associated moshi deps) between jvm and common with no success has anyone seen kapt working in multiplatform? I attached my build.gradle.kts file and would appreciate any help!
    kapt-in-multiplatform_build_gradle_kts
    l
    • 2
    • 2
  • a

    audax

    07/14/2020, 7:31 AM
    I made an example project of a Kotlin MP library with a Vue.js TypeScript application with proper TypesScript headers of the Kotlin library and gradle integration of Vue.js: https://github.com/audax/kotlin-vue-typescript-example
    👀 1
    c
    • 2
    • 6
  • l

    Loboda Deni

    07/14/2020, 11:33 AM
    Really multi-platform modules can not be connected to each other as usual? it's not very convenient to work with them in this case
    z
    k
    r
    • 4
    • 34
  • l

    Luka

    07/14/2020, 1:47 PM
    I get "Unresolved reference: NativeSqliteDriver" when trying to use it in my ios KMP target (from SQLDelight library). "AndroidSqliteDriver" from my android target resolves normally. Gradle syncs without errors. Any idea how to debug this?
    j
    • 2
    • 2
  • w

    wuseal

    07/14/2020, 2:33 PM
    Hi, Everyone, Will Kotlin 1.4 change the world? 🤔
    🤨 2
    d
    l
    k
    • 4
    • 3
  • c

    Chintan Soni

    07/14/2020, 5:23 PM
    Hello everyone,, Has anyone tried StateFlow in KMP? If yes, can someone guide me on how can I write Unit Test for StateFlow? I am following MVVM architecture and am trying to create a common ViewModel that can be used by any platform. In below example, I am trying to test
    LoginViewModel
    from its method
    login
    . LoginViewModel.kt:
    @ExperimentalCoroutinesApi
    class LoginViewModel(private val loginViewState: LoginViewState, private val loginService: LoginService) {
    
        private val _apiStateFlow = MutableStateFlow(loginViewState)
        val stateFlow: StateFlow<LoginViewState> = _apiStateFlow
    
        private val _EMAIL_REGEX = "^[A-Za-z](.*)([@]{1})(.{1,})(\\.)(.{1,})"
    
        suspend fun login(email: String, password: String) {
            if (isFormValid(email, password)) {
                _apiStateFlow.value = loginViewState.copy(isLoginApiLoading = true)
                runCatching {
                    loginService.login(email, password)
                }.onSuccess {
                    loginViewState.copy(isLoginApiLoading = false, loginResponse = it)
                }.onFailure {
                    loginViewState.copy(isLoginApiLoading = false, errorResponse = ErrorResponse(it.message.orEmpty()))
                }
            }
        }
    
        fun isFormValid(email: String, password: String): Boolean {
            val isEmailValid = email.isEmailValid()
            val isPasswordValid = password.isPasswordValid()
            _apiStateFlow.value = loginViewState.copy(isValidEmail = isEmailValid, isValidPassword = isPasswordValid)
            return isEmailValid && isPasswordValid
        }
    
        private fun String.isEmailValid() = _EMAIL_REGEX.toRegex().matches(this)
        private fun String.isPasswordValid() = length in 6..14
    }
    
    data class LoginViewState(
        val email: String = "",
        val password: String = "",
        val isValidEmail: Boolean = false,
        val isValidPassword: Boolean = false,
        val isLoginApiLoading: Boolean = false,
        val loginResponse: LoginResponse? = null,
        val errorResponse: ErrorResponse? = null
    )
    Service.kt:
    expect val platformEngine: HttpClientEngineFactory<HttpClientEngineConfig>
    
    val myHttpClient: HttpClient
        get() = HttpClient(platformEngine) {
            install(JsonFeature) {
                serializer = KotlinxSerializer()
            }
            install(Logging) {
                level = LogLevel.ALL
            }
            expectSuccess = false
            HttpResponseValidator {
                validateResponse { response: HttpResponse ->
                    println("Response: $response")
                    val statusCode = response.status.value
                    when (statusCode) {
                        in 300..399 -> throw RedirectResponseException(response)
                        in 400..499 -> throw ClientRequestException(response)
                        in 500..599 -> throw ServerResponseException(response)
                    }
    
                    if (statusCode >= 600) {
                        throw ResponseException(response)
                    }
                }
    
                handleResponseException { cause: Throwable ->
                    println("Exception: $cause")
                }
            }
            defaultRequest {
                url {
                    host = "127.0.0.1:8080/"
                    protocol = URLProtocol.HTTP
                }
                timeout {
                    connectTimeoutMillis = 10000
                    requestTimeoutMillis = 10000
                    socketTimeoutMillis = 10000
                }
            }
        }
    LoginService.kt:
    class LoginService(private val httpClient: HttpClient) {
        suspend fun login(email : String, password : String): LoginResponse = <http://httpClient.post|httpClient.post> {
            body = LoginRequest(email, password)
        }
    }
    LoginReqRes.kt:
    data class LoginRequest(val email: String = "", val password: String = "")
    data class LoginResponse(val name: String = "", val age: Int = 0, val email: String = "")
    data class ErrorResponse(val message: String)
    Any suggestions?
    ➕ 1
    k
    • 2
    • 3
  • j

    jean

    07/14/2020, 7:35 PM
    I’m getting started with multiplateform, mainly to target android and ios. I notice this https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction gives different explanations/configuration than the code generated by IntelliJ idea when creating a android/ios project. Should I follow one more than the other? Is one of them deprecated?
    k
    • 2
    • 3
  • c

    Chintan Soni

    07/15/2020, 4:16 AM
    Hey everyone, Is there any way I can generate TS (TypeScript) files for Kotlin/JS instead of plain old Javascript? Or any options that I can generate both of them? Right now, I am having this in build.gradle.kts:
    js(IR) {
            moduleName = "JsDomain"
            nodejs {
                testTask {
                    useMocha {
                        timeout = "10000"
                    }
                }
            }
            browser {
                testTask {
                    useMocha {
                        timeout = "10000"
                    }
                }
            }
        }
    g
    a
    • 3
    • 3
  • a

    aleksey.tomin

    07/15/2020, 5:42 AM
    How can I build only one target in multiplatform project? I have
    macosX64
    and
    linuxX64
    and on macos building both. But I want to build only macos target
    s
    • 2
    • 1
  • w

    willyrs

    07/15/2020, 10:28 AM
    Can one create a framework for mac catalyst? I’ve built the target:
    macosX64("mac") {
        binaries {
            framework("mac")
        }
    }
    but when I try to import the framework it says:
    /Users/*/Projects/RTE/apod-kampkit/ios/ApodKMP.xcodeproj Building for Mac Catalyst, but the linked and embedded framework 'mac.framework' was built for macOS. You may need to restrict the platforms for which this framework should be linked and embedded in the target editor, or replace it with an XCFramework that supports both platforms.
    I’m a bit confused since it clearly says that the framework is (correctly?) built for macOS. I’ve also tried to put this framework in a normal macOS app project and it works
    👍 1
    t
    d
    • 3
    • 4
  • z

    zsperske

    07/15/2020, 3:17 PM
    Hello, I have a pretty basic question about iOS in a KMP project. Say I have an interface defined in my common code that looks like this.
    interface Database {
         suspend fun updateEntry(foo: Foo) : Boolean
    }
    In order to implement this on iOS one option appears to be implementing a kotlin class in my iosMain that could use obj-c interop to achieve what I want. Is it also possible to feed a swift class that I've written (with obj-c headers) into my common code? Are there drawbacks to that?
    b
    k
    • 3
    • 10
  • l

    Loboda Deni

    07/16/2020, 5:51 AM
    Has anyone encountered the problem that after refactoring the package name, the studio does not see classes from other modules?
    ➕ 1
    g
    • 2
    • 7
  • l

    Loboda Deni

    07/16/2020, 6:11 AM
    something like this, everything works strangely, is multi-platform development a stable feature? because it seems like it's alpha
    w
    k
    • 3
    • 8
  • j

    jean

    07/16/2020, 7:47 AM
    the hands-on tutorial use
    jvm("android")
    for targeting android but I’m reading in the doc that one could also use
    android { ... }
    . Is the
    android
    shortcut useful only to be able to configure build variants, dependencies, etc… ? The doc says also
    id("com.android.library")
    is necessary but gradle can’t resolve it
    Plugin [id: 'com.android.library'] was not found in any of the following sources:
    (and then nothing, it does not say any sources). What if I want to target android and desktop through the jvm? should I just use
    jvm()
    ?
    g
    l
    k
    • 4
    • 15
  • l

    Luka

    07/16/2020, 11:52 AM
    Do you have any suggestion how to create and publish private cocoapod after podspec file has been generated by cocoapods gradle plugin. Our ios team would just like to call pod install and use this shared framework. Not sure how to pass some params to podpsec gradle task or using some script to modify generated .podspec file. Any idea how to automate publishing?
    👍 1
    s
    k
    • 3
    • 9
  • m

    Michal Janos

    07/18/2020, 4:25 PM
    Hi I'm new with kotlin, so my question may be stupid, but are there someone, who have correctly implement
    klock
    to multiplatform? I have implemented 1.11.13, everything works fine, with using
    npm link
    , but it is not possible to publish it to my private nexus NPM repo what I try, is to change package.json, and change it to my scope before publish, this help me with
    kotlin-source-map-loader
    , but
    klock
    create
    require('klock-root-klock')
    on end of generated js file kotlin multiplatform 1.3.72
    z
    • 2
    • 1
  • k

    Kurt Renzo Acosta

    07/18/2020, 5:32 PM
    Is there a way to run android tests using
    allTests
    ? It's just running
    iosTest
    whenever I run it.
    a
    z
    • 3
    • 3
  • b

    bod

    07/18/2020, 9:06 PM
    Hello, World! So... I think about 8 months ago I made a Kotlin MP "framework" for iOS, and oddly, the hardest part was to find how to actually import it in my XCode project (I'm not an iOS developer). I remember it took me several hours until I finally made it work somehow. Fast forward to now, I'm trying to make a MacOS app, I have the framework, I created a new empty XCode project ... and I'm finding myself stuck at the step again! Googling and stackoverflowing since this afternoon and it's 23h05 now. The instructions [here](https://kotlinlang.org/docs/tutorials/native/apple-framework.html#xcode-for-macos-target) are all too vague. Is there anyone here who has a step by step guide on how to do import a framework into a project with a recent XCode (with screenshots maybe?). I would be forever grateful...
    j
    k
    • 3
    • 6
  • a

    Attila Blenesi

    07/20/2020, 3:50 PM
    Is there a list of production apps using Kotlin Multiplatform.
    d
    • 2
    • 2
  • k

    Kroppeb

    07/20/2020, 9:13 PM
    I don't see what the issue is here
    s
    • 2
    • 5
  • k

    Kroppeb

    07/20/2020, 10:22 PM
    I have a jave class with function
    getResult():T
    . Normally in kotlin I can then use
    value.result
    to get this value. However this doesn't seem to be possible with `expect`/`actual`. Am I missing something?
    b
    s
    • 3
    • 6
  • o

    oshai

    07/21/2020, 6:17 AM
    Hi, is it possible with multiplatform to create two separate jvm modules? I would like to have one for regular JVM and one for Android. Or is it because it's the same platform that is impossible?
    d
    a
    s
    • 4
    • 9
  • c

    Christian Sousa

    07/21/2020, 9:59 AM
    What is the best way to clone by value a class instance on a multiplatform project (under the common code)? I’ve not found anything related to it, only the Cloneable on Java, but that doesn’t really help because I was trying to do it under the common part
    g
    • 2
    • 8
  • s

    savrov

    07/21/2020, 9:58 PM
    Hello, Let’s say, I have a project with 2 modules: A & B. A module contains TestUtil class defined under
    commonTest
    . Is it possible to access to this class from *B*’s
    commonTest
    ? I thought to do something like this, but it does not seems to work:
    commonMain {
     dependencies {
      implementation(project(':moduleA'))
     }
    }
    commonTest {
     dependencies {
      implementation(project(':moduleA'))
     }
    }
    r
    • 2
    • 2
  • a

    aleksey.tomin

    07/22/2020, 11:24 AM
    Why
    getnameinfo
    function for macosX64 and linuxX64 target in
    platform.posix
    but for mingwX64 in
    platform.windows
    ? It it a bug or feature?
    a
    • 2
    • 7
  • a

    Andrea Prearo

    07/22/2020, 4:26 PM
    Is there a Kotlin multi-platform library for encoding/decoding JWT? I’m trying to add JWT functionality in my KMP code and, if possible, I’d like to avoid having to embed platform specific JWT libraries for Android and iOS.
    s
    k
    s
    • 4
    • 7
  • d

    Darren Bell

    07/22/2020, 8:49 PM
    Hi I'm having issues trying to change the port of the DevServer I have a configuration as follows
    kotlin {
        js {
            useCommonJs()
            browser {
                binaries.executable()
                webpackTask {
                    cssSupport.enabled = true
                    devServer = KotlinWebpackConfig.DevServer(true, false, true, true, false, 3000, null, listOf("$projectDir/src/jsMain/resources"))
                }
                runTask {
                    cssSupport.enabled = true
                }
                testTask {
                    useKarma {
                        useChromeHeadless()
                        webpackConfig.cssSupport.enabled = true
                    }
                }
            }
        }
    when I run
    jsBrowserDevelopmentWebpack
    I can see the changes have taking in the generated webpack.config.js. However, when I run
    jsBrowserDevelopmentRun
    the configuration seems to get overwritten again. Is anyone having success is this area? Im using the latest 1.4-M3
    r
    i
    • 3
    • 5
Powered by Linen
Title
d

Darren Bell

07/22/2020, 8:49 PM
Hi I'm having issues trying to change the port of the DevServer I have a configuration as follows
kotlin {
    js {
        useCommonJs()
        browser {
            binaries.executable()
            webpackTask {
                cssSupport.enabled = true
                devServer = KotlinWebpackConfig.DevServer(true, false, true, true, false, 3000, null, listOf("$projectDir/src/jsMain/resources"))
            }
            runTask {
                cssSupport.enabled = true
            }
            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
when I run
jsBrowserDevelopmentWebpack
I can see the changes have taking in the generated webpack.config.js. However, when I run
jsBrowserDevelopmentRun
the configuration seems to get overwritten again. Is anyone having success is this area? Im using the latest 1.4-M3
r

russhwolf

07/22/2020, 9:29 PM
Try overriding the dev server in
runTask
as well
d

Darren Bell

07/22/2020, 9:46 PM
Hi. I tried that originally, i tried it again. But still no success
i

Ilya Goncharov [JB]

07/27/2020, 1:08 PM
Hi, please try
1.4.0-rc
which was released today. I believe this issue was fixed in it
d

Darren Bell

07/28/2020, 9:42 AM
@Ilya Goncharov [JB]. Will do thanks
I can confirm this is working now. Many thanks
View count: 8