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

    Gurupad Mamadapur [FH]

    12/23/2019, 2:54 PM
    Hi, for some reason I cannot resolve a dependency in the common sourceSet in mpp module. More specifically it is a ktor-core dependency. Here is the build.gradle file -
    plugins {
        id "com.android.library"
        id 'org.jetbrains.kotlin.multiplatform'
    }
    
    repositories {
        mavenCentral()
    }
    
    android {
        compileSdkVersion(28)
        buildToolsVersion = "28.0.3"
        defaultConfig {
            minSdkVersion(16)
            targetSdkVersion(28)
        }
    }
    
    kotlin {
        android()
        js {
            browser {
    
            }
        }
    
        sourceSets {
            commonMain {
                dependencies {
                    implementation kotlin('stdlib-common')
                    implementation "io.ktor:ktor-client-core:$ktorVersion"
                }
            }
            androidMain {
                dependencies {
                    implementation kotlin('stdlib')
                }
            }
            jsMain {
                dependencies {
                    implementation kotlin('stdlib-js')
                }
            }
        }
    }
    Here is the root build.gradle -
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        ext.kotlin_version = '1.3.61'
    
        repositories {
            google()
            mavenCentral()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    ext {
        ktorVersion = "1.3.0-rc"
    }
    Error is -
    > Task :shared:compileDebugKotlinAndroid FAILED
    e: /Users/fabhotels/Development/testmpp/shared/src/commonMain/kotlin/common.kt: (1, 23): Unresolved reference: HttpClient
    e: /Users/fabhotels/Development/testmpp/shared/src/commonMain/kotlin/common.kt: (3, 18): Unresolved reference: HttpClient
    The sample project is available here - https://github.com/Protino/testmpp/tree/sample/ktor
    k
    • 2
    • 5
  • n

    napperley

    12/23/2019, 9:39 PM
    Does Kotlin Multiplatform have a way to share code between multiple Platform modules (eg linuxX64, linuxARMV7) where the OS (eg Linux) is the same?
    i
    d
    +2
    • 5
    • 8
  • h

    Hannes

    12/23/2019, 9:48 PM
    Hi there, any hint how to call an
    object
    from iOS side? Let's say I have in commonMain a
    object Foo
    How can i call
    Foo
    from iOS side? If I try to use Foo directly I actually somehow access the Type, but not the singleton instance. Any idea?
    k
    s
    o
    • 4
    • 4
  • j

    jdemeulenaere

    12/24/2019, 3:39 PM
    How can a Kotlin/JS gradle subproject depend on a Kotlin/Multiplatform subproject ? In my case I have the following gradle project structure:
    client/               <= Kotlin/JS subproject
     |- build.gradle.kts  <= What should I put here to allow client to depend on :shared ?
    server/               <= Kotlin/JVM subproject
     |- build.gradle.kts  <= What should I put here to allow server to depend on :shared ?
    shared/               <= Kotlin/Multiplatform subproject
     |- build.gradle.kts
    I tried to put this but it didn't work:
    dependencies {
        implementation(project(":shared"))
    }
    e
    r
    i
    • 4
    • 10
  • a

    ansman

    12/24/2019, 6:15 PM
    I’m trying to run the tests for my
    js
    target but I keep getting
    :module:jsTest NO-SOURCE
    . My tests are in
    module/src/jsTest/kotlin
    i
    • 2
    • 3
  • j

    jdiaz

    12/25/2019, 9:44 PM
    Is it possible to share common code between native targets with CInterop working?
    d
    • 2
    • 13
  • j

    Joey

    12/26/2019, 2:45 AM
    * What went wrong:
    A problem occurred evaluating settings 'sample-kt-sharedlib'.
    > Could not find method enableFeaturePreview() for arguments [GRADLE_METADATA] on settings 'sample-kt-sharedlib' of type org.gradle.initialization.DefaultSettings.
    Any suggested solution to this? Im trying to upload a multiplatform lib to bintray. Thanks! B-)
    y
    r
    d
    • 4
    • 11
  • s

    saket

    12/26/2019, 5:26 PM
    Are there any technical limitations for not allowing named arguments to members of expected classes?
    e
    • 2
    • 2
  • o

    Orhan Tozan

    12/26/2019, 11:54 PM
    Hey guys, we are using Kotlin to build a native Android app, and we are planning to also build an native iOS app. We have a lot of business logic written in Kotlin right now, and its nicely layered, so seperated from the Android framework. I've read about Kotlin Multiplatform and its option to share common logic between different platforms, although after reading more, I'm not sure if our usecase is supported by Kotlin multiplatform. My question and usecase is: is it possible to have a 3 seperate repo setup: core (written in Kotlin), android-app (written in Kotlin) and ios-app (written in Swift). android-app and ios-app both use the core project. So that means that the Core module/repo doesn't know anything about the android/ios project.
    k
    d
    +2
    • 5
    • 29
  • m

    Marc Knaup

    12/27/2019, 10:17 AM
    Is there a way to run common tests on the JVM using IntelliJ IDEA, ideally with the run icon next to the test? Every time I run a test, it’s running on the JVM but using Gradle. It doesn’t matter than I’ve told the IDEA to not use Gradle for that 😕
    a
    • 2
    • 5
  • j

    jdemeulenaere

    12/27/2019, 1:55 PM
    Is there any multiplatform Kotlin drawing or game engine library out there ? 🙂
    m
    r
    d
    • 4
    • 3
  • b

    Big Chungus

    12/27/2019, 2:36 PM
    How do i share the same sourceSet between targets? i have common sourceSet with expect declarations and then another sourceSet with actual declarations which I want to compile to two different targets.
    p
    d
    • 3
    • 2
  • s

    steamstreet

    12/27/2019, 6:50 PM
    Are there any known issues in dealing with a multiplatform project and publishing with resolved versions? I use a version resolution strategy, and when I publish to Maven, am getting errors that versions aren’t included. I’m trying to follow the instructions here: https://docs.gradle.org/6.0.1/userguide/publishing_maven.html#publishing_maven:resolved_dependencies but they don’t seem to work correctly with the multiplatform publications (the versions aren’t included and the metadata build won’t publish at all)
    t
    • 2
    • 1
  • b

    Brendan Weinstein

    12/27/2019, 8:25 PM
    Just digging through https://github.com/JetBrains/kotlinconf-app for the first time. Looking at build.gradle.kts in the common module, it makes sense that the source set defined as iosMain maps to the iosMain package, mobileMain maps to the mobileMain package, and commonMain maps to the commonMain package. Which packages do the jvmMain and androidMain sourcesets map to? I see there is one remaining package called 'main' and it has an AndroidManifest.xml file, so I presume the 'main' package maps to the androidMain sourceset. I am searching to see if these sourceset mappings are by convention or defined in code. They appear to be by convention, but the convention seems inconsistent and the androidMain sourceset appears greyed out.
    d
    • 2
    • 2
  • a

    Alexander

    12/27/2019, 10:12 PM
    Cannot find multiplatform arithmetic operations similar to Java's https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#addExact(long,long) Think it would be great to have arithmetic overflow handling for kotlin multiplatform.
    e
    • 2
    • 1
  • n

    Nikita Khlebushkin

    12/28/2019, 10:15 PM
    Hello there, I am curious is it possible to make annotation processor for Kotlin Multiplatform at the moment? I found this https://stackoverflow.com/questions/52757881/how-to-write-annotation-processors-for-kotlin-native with the response on October, 2018, but maybe things have changed since then
    r
    • 2
    • 4
  • a

    altavir

    12/29/2019, 4:25 PM
    Are there any fixes for mutliplatform resource loading problem yet?
    d
    • 2
    • 3
  • b

    basher

    12/29/2019, 5:56 PM
    If I have a Java class that defines a getter like
    getFoo()
    , which gets translated to the
    val
    foo
    in Kotlin, is there a way to write an expect class that captures that? If I do:
    expect class F {
       val foo: Int
    }
    Kotlin (1.3.61) complains that the matching class in Java (via
    actual typealias F = MyJavaClass
    ) doesn't have that property. Is there some kind of annotation I need to use in my
    expect class
    to make this work (so that when
    val foo
    matches up with the Java getter)?
    d
    • 2
    • 6
  • s

    Slackbot

    12/30/2019, 9:23 AM
    This message was deleted.
    m
    m
    • 3
    • 2
  • k

    Kris Wong

    12/30/2019, 3:27 PM
    has anyone managed to get mockk working for their common tests?
    b
    m
    a
    • 4
    • 23
  • n

    Nick Halase

    12/30/2019, 6:04 PM
    What’s the best practice for directory structure within modules? In Java world, packages are king and reverse domain. What should the directory structures be within commonMain, iosMain and androidMain?
    k
    m
    • 3
    • 7
  • s

    StefMa

    12/31/2019, 7:16 AM
    I have one Gradle project which includes two sub projects:
    lib
    and
    sample
    . The library uses some dependencies (ktor for instance). They all are declared as
    implementation
    dependencies. My sample should simply use the
    lib
    as a dependency. For this i added
    commonMainImplementation(project(":lib"))
    But if I run my
    jvm
    sample (which has a
    main
    method) I get:
    java.lang.NoClassDefFoundError: io/ktor/client/HttpClientJvmKt
    Which is strange because I do not share the
    HttpClient
    as a API. It is declared as
    internal
    and therefore it should not be shared with other libraries... To my question: Is this setup possible? How should it work then? How do I have to declare my lib dependency in the sample?
    c
    • 2
    • 4
  • m

    mzgreen

    12/31/2019, 1:28 PM
    I’m trying to add a simple unit test to my project. I added:
    commonTest {
                dependencies {
                    implementation kotlin('test-common')
                    implementation kotlin('test-annotations-common')
                }
            }
    And then in
    commonTest/kotlin/
    directory I have this file:
    class Test {
    
        @Test
        fun foo() {
            assertEquals(1,2,"Test failed")
        }
    }
    I run it
    ./gradlew :common:test
    and I get errors like:
    > Task :common:compileDebugUnitTestKotlinAndroid FAILED
    e: .../common/src/commonTest/kotlin/Test.kt: (1, 20): Unresolved reference: Test
    e: .../common/src/commonTest/kotlin/Test.kt: (2, 20): Unresolved reference: assertEquals
    e: .../common/src/commonTest/kotlin/Test.kt: (6, 5): 'Test' is not an annotation class
    e: .../common/src/commonTest/kotlin/Test.kt: (8, 9): Unresolved reference: assertEquals
    Not sure what is going on.
    e
    k
    • 3
    • 11
  • k

    Kris Wong

    12/31/2019, 3:19 PM
    hope none of y'all are using supernatural-fs for iOS. it's completely broken. https://github.com/suparngp/kotlin-multiplatform-projects/issues/63
    • 1
    • 1
  • k

    Kris Wong

    12/31/2019, 4:09 PM
    is there any way to specify that one source set depends on another (i.e., iosArm64Main depends on iosMain), but add a dependency to iosMain that is not included in iosArm64Main?
    d
    • 2
    • 16
  • s

    serebit

    12/31/2019, 4:39 PM
    Hey all, we're trying to implement a common Map class that uses thread confinement for synchronization. We've settled on either using Mutex or a custom implementation of the Actor pattern. Are there any significant advantages or disadvantages to either of these approaches?
    a
    d
    +5
    • 8
    • 28
  • s

    saket

    01/01/2020, 12:24 AM
    Not sure if this was obvious, but while running common tests from the IDE is a hit-or-miss, I recently found out that IDEA offers a way to run custom gradle tasks that can be used as a stop-gap. Very useful for debugging with breakpoints:
    👍 3
    k
    • 2
    • 4
  • s

    spierce7

    01/01/2020, 8:05 PM
    I’m getting an error when uploading a multiplatform project to jcenter:
    Cannot upload checksum for module-maven-metadata.xml. Remote repository doesn't support sha-512
    Does anyone know how to fix this?
    m
    • 2
    • 4
  • k

    Kurt Renzo Acosta

    01/02/2020, 3:23 AM
    Started the year by writing an article about multiplatform. Do check them out if you can. Comments and suggestions are very much appreciated. https://dev.to/kuuurt/maximizing-code-sharing-between-android-and-ios-with-kotlin-multiplatform-54h8?fbclid=IwAR3MVHQv-7Ub_zI5TCkYJNoYA7YYig06xQ66P1rk_iuN9q_aOllO17-UlBw
    ❤️ 3
    k
    k
    i
    • 4
    • 4
  • m

    mzgreen

    01/02/2020, 11:20 AM
    I have a multiplatform project targetting android, ios, js and jvm. I need a way to spawn a simple thread and be able to call
    sleep
    method or its equivalent. Coroutines are multiplatform but do they support jvm target? https://github.com/Kotlin/kotlinx.coroutines#multiplatform I see android, js and native here but no jvm.
    b
    • 2
    • 2
Powered by Linen
Title
m

mzgreen

01/02/2020, 11:20 AM
I have a multiplatform project targetting android, ios, js and jvm. I need a way to spawn a simple thread and be able to call
sleep
method or its equivalent. Coroutines are multiplatform but do they support jvm target? https://github.com/Kotlin/kotlinx.coroutines#multiplatform I see android, js and native here but no jvm.
b

Big Chungus

01/02/2020, 11:21 AM
JVM is default target. simply use coroutines-core with no target suffix (i.e. js, native, common)
m

mzgreen

01/02/2020, 11:23 AM
Thanks!
View count: 7