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

    Franco

    09/12/2020, 1:44 AM
    Hi everyone, I updated from Kotlin 1.3.72 to Kotlin 1.4.10 today and I'm getting the following compilation error when I try to build my multiplatform library. Any idea what this is about? There are no references to my code on this error so I guess it's an issue inside Kotlin? Or is there anything I have to configure for this after the migration to to Kotlin 1.4 that can fix this?
    Untitled
    l
    • 2
    • 9
  • t

    Tim Malseed

    09/12/2020, 5:41 AM
    I'm trying to set up a multi platform project, with two modules,
    shared
    and
    desktop
    . 'Shared' is the typical
    multiplatform
    gradle project, declaring
    commonMain
    and
    jvmMain
    sourcesets. 'Desktop' depends on 'shared', via:
    implementation(project(":shared"))
    However, the 'shared' source files don't seem to be available to the 'desktop' module. Do I need to do something special to 'publish' shared, or otherwise make it accessible to other modules?
    w
    g
    • 3
    • 4
  • f

    Franco

    09/12/2020, 8:08 AM
    Hi, I updated from Kotlin 1.3.72 to 1.4.10 and when trying to use my multiplatform library (imported as a module) on a JVM module I get the following error:
    Ignoring dependency of module <MPP Lib> on module <JVM Module>. Java modules cannot depend on Android modules
    Any idea why this would happen? It seems like the JVM module is trying to import the Android target of the multiplatform library instead of the JVM one.
    l
    • 2
    • 3
  • l

    louiscad

    09/12/2020, 11:31 AM
    Hello, does anyone know how to get rid of these log messages? I have them repeated hundreds of times in my builds because I have over 40 multiplatform modules targeting Android, and that makes eye scanning the logs way tougher.
    The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
    See <https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets>
    z
    • 2
    • 4
  • d

    dan.the.man

    09/12/2020, 6:05 PM
    I'm trying to set up some tests with suspend functions, It works fine on JVM but I'm curious what people are doing for JS and native?
    l
    c
    • 3
    • 9
  • a

    ankushg

    09/13/2020, 1:42 AM
    Anyone know of a good way to get test coverage info for test runs on iOS and/or JS targets? Jacoco works for JVM, but it would be nice to get insight into coverage for platform-specific stuff
    b
    k
    • 3
    • 5
  • b

    bod

    09/13/2020, 1:57 PM
    Hello, World! Trying to create a MPP library with 1.4.10, I get
    Unresolved reference assertEquals
    in my unit tests. I have these dependencies:
    commonTest {
                dependencies {
                    implementation(kotlin("test-common"))
                    implementation(kotlin("test-annotations-common"))
                }
            }
    Googling a bit it looks like I'm not the only one [1] - but I'm a bit surprised, this seems like a major problem. So I guess my question is: does anyone have a basic example project, with tests, that works? [1] = https://youtrack.jetbrains.com/issue/KT-40571
    • 1
    • 1
  • w

    william

    09/13/2020, 3:50 PM
    i have a multiplatform module (jvm and ios target), as well as a jvm based module. intellij is unable to find any of the sources from the multiplatform module (and says unresolved reference), but the gradle builds work fine. I've tried invalidating caches, removing .idea, and uninstalling intellij. any other ideas?
    👍 1
    k
    s
    • 3
    • 7
  • i

    Ibrahim Ali

    09/14/2020, 11:35 AM
    Hello everybody, I'm trying to build a library and I always find my imports unresolved, IDK if I should do something. but everything runs fine.
    val commonMain by getting {
        dependencies {
            implementation("org.jsoup:jsoup:1.13.1")
        }
    }
    ☝️ 1
    g
    • 2
    • 4
  • m

    Maximilian Fehrentz

    09/15/2020, 7:28 AM
    Hi, does anyone know how suspend functions are compiled for iOS?
    m
    j
    • 3
    • 6
  • a

    aleksey.tomin

    09/15/2020, 9:08 AM
    I try to create library for macOS and iOS application. 1. I’ve read https://kotlinlang.org/docs/reference/native/cocoapods.html and add
    cocoapods
    into
    build.gradle.kts
    2. I’ve called
    build
    3. I’ve called
    podspec
    and
    library.podspec
    was created 4. I’ve called
    podBuildDependenciesMacos
    podSetupBuildMacos
    - was created cocoapods dir with framework 5. I’ve called
    podInstall
    - but was not pod into list:
    $ pod list
    returns
    0 pods were found
    . What do I wrong? How can I create library for use in Xcode?
    k
    l
    r
    • 4
    • 14
  • d

    Daniele B

    09/15/2020, 3:51 PM
    Today it was a great milestone! I was able to run exactly the same shared ViewModel on both Android and iOS, using
    StateFlow
    !!! I can easily say 85% of the code is on Kotlin Multiplatform, and 15% only on the platform-specific declarative UI (Compose and SwiftUI)! on Android, it uses Compose's `collectAsState`:
    @Composable
    fun MainLayout(coreModel: CoreViewModel) {
        val appState by coreModel.stateFlow.collectAsState()
        ...
    }
    on iOS, it uses a very simple class extending
    ObservableObject
    , where a StateFlow “listener” is initialized:
    class AppViewModel: ObservableObject {
      let coreModel : CoreViewModel = CoreViewModel()
      @Published var appState : AppState = AppState()
         
      init() {
          coreModel.onChange { newState in
              self.appState = newState
          }
       }
    }
    this is the shared `ViewModel`:
    class CoreViewModel {
    
      internal val mutableStateFlow: MutableStateFlow(AppState())
      val stateFlow: StateFlow<AppState>
          get() = mutableStateFlow
    
      fun onChange(provideNewState: ((AppState) -> Unit)) {
          stateFlow.onEach {
              provideNewState.invoke(it)
          }.launchIn(CoroutineScope(Dispatchers.Main))
      }
    }
    👍 8
    :kotlin: 3
    👏 4
    🎉 23
    👀 1
    k
    f
    +4
    • 7
    • 55
  • d

    diesieben07

    09/15/2020, 4:59 PM
    I am playing around with Multiplatform and Kotlin/Native. I want to be able to use
    posix
    in code shared between Linux/OSX. However I cannot get this to work at all. I have set
    kotlin.mpp.enableGranularSourceSetsMetadata=true
    and
    kotlin.native.enableDependencyPropagation=false
    like described in the docs. Then I have created a
    nativeMain
    source set:
    val nativeMain by creating {
      dependsOn(commonMain)
     }
    Then I have configured the
    linuxX64Main
    and
    osxX64Main
    source sets to depend on
    nativeMain
    . However I still cannot use
    posix
    in
    nativeMain
    . This issue happens both when trying to compile with Gradle as well as in IntelliJ (types / functions cannot be resolved). What am I missing?
    a
    b
    +2
    • 5
    • 11
  • m

    Matteo Wohlrapp

    09/16/2020, 6:34 AM
    Does anyone know if Kotlin suspend functions actually suspend on iOS and if so, how is it implemented on iOS?
    l
    • 2
    • 7
  • m

    Maximilian Fehrentz

    09/16/2020, 8:45 AM
    Does anyone have a working example for a project with SqlDelight using migrations?
    k
    l
    • 3
    • 3
  • c

    Christian Jensen

    09/16/2020, 9:51 AM
    I have added a KMM module to my existing Android project via the wizard. The iOS project is in another repository. What's the easiest way for us to make a KMM proof-of-concept in the iOS repository? I would expect a generated ObjectiveC framework from the android project but can't seem to find it...
    k
    • 2
    • 1
  • a

    Alberto

    09/16/2020, 2:24 PM
    are there any recommendations on a Observer / RX multiplatform library targeting Android / iOS? I saw https://github.com/noheltcj/RxCommon but not sure how up to date is. Also not necessarily looking for RX specifically, but a framework perhaps already available to deal with observables on Android / iOS.
    k
    e
    k
    • 4
    • 13
  • c

    Christopher Elías

    09/16/2020, 4:55 PM
    Hello 👋! Can I start a Kotlin MMP for Android & iOS with Android Studio on Windows? Does anybody have some samples on how to prepare the environment and "hello world sample" maybe?
    s
    j
    a
    • 4
    • 13
  • z

    zalewski.se

    09/17/2020, 3:47 AM
    My xcode updated to version 12 and since then I’m getting build error:
    output:
    Undefined symbols for architecture x86_64:
      "_objc_setHook_setAssociatedObject", referenced from:
          _platform_objc_objc_setHook_setAssociatedObject_wrapper100 in libobjc-cache.a(result.o)
         (maybe you meant: _platform_objc_objc_setHook_setAssociatedObject_wrapper100, knifunptr_platform_objc100_objc_setHook_setAssociatedObject )
    ld: symbol(s) not found for architecture x86_64
    Any idea how to fix this? 😓
    s
    • 2
    • 6
  • e

    Elka

    09/17/2020, 4:58 AM
    Hello what are the best practices to implement multi-module Kotlin on iOS? We have multiple apps, each app can dependent on multiple feature frameworks. Here's an example diagram. From what I read is that the iOS App2 might see 2 versions of the classes in Module1... Because the frameworks are being compiled separately... Any suggestion/workarounds on how to solve this problem?
    k
    • 2
    • 5
  • i

    Ivann Ruiz

    09/17/2020, 5:24 PM
    Currently working in a multi-platform project and wanna share the
    CoroutineDispatcher
    I'm using for iOS. There's a few variants out there, but this specific implementation allows for using
    delay()
    calls in suspend function. I keep this object inside my
    SharedViewModel
    and use it to define the
    viewModelScope
    for iOS coroutines.
    Untitled
    t
    • 2
    • 2
  • d

    Daniele B

    09/17/2020, 5:54 PM
    Another great milestone today, after
    Android
    and
    iOS
    , I was able to run the shared ViewModel on
    Web
    too! I admit I never used
    React
    before, but with Kotlin it was incredibly easy to setup it up! I was actually thinking to use
    Vue.js
    for the web, because I was interested in a lightweight web framework, whose main capability is to provide a declarative UI, similar to what Compose and SwiftUI provide in mobile. But I was not aware of how simple Kotlin makes it to work with React! I am still astonished now. Kotlin hides most React complexity, and Android Studio even spins a node.js server on localhost to test the app, with no setup! My project uses a shared ViewModel, which means that changes to the app state only happen in the shared code. Such changes are then propagated via
    StateFlow
    to the platform-specific app code. In Kotlin/React it’s as simple as this to observe the app state changes via StateFlow:
    fun myAppState() : AppState {
        val appDependencies = useContext(AppDependenciesContext)
        val (state, setState) = useState(appDependencies.coreModel.stateFlow.value)
    
        useEffectWithCleanup {
            val job = appDependencies.coreModel.stateFlow.onEach { setState(it) }.launchIn(GlobalScope)
            return@useEffectWithCleanup { job.cancel() }
        }
        
        return state
    }
    💯 5
    :kotlin-flag: 2
    👍 2
    b
    a
    +2
    • 5
    • 31
  • j

    jean

    09/18/2020, 12:21 PM
    I’m trying to upload a multiplatform library to bintray, I’m following their doc from the github page :https://github.com/bintray/gradle-bintray-plugin I’m also using kotlin dsl for my build file and I’m not sure what I’m supposed to do for the step 7 :
    publishing {
        publications {
            MyPublication(MavenPublication) {
                from components.java
                groupId 'org.jfrog.gradle.sample'
                artifactId 'gradle-project'
                version '1.1'
            }
        }
    }
    Where does
    MyPublication
    comes from?
    m
    j
    • 3
    • 5
  • s

    Samuel Michael

    09/18/2020, 1:53 PM
    Trying to find the easiest way to use a KMM library as a dependency for separate iOS, Android, and possibly Web, any suggestions?
    d
    • 2
    • 35
  • a

    António Bastião

    09/18/2020, 2:08 PM
    Hello everyone! Can anyone please help me to understand why I cannot see the screen shown on 4th step? How can I solve it?
    s
    • 2
    • 6
  • v

    Vivek Subramanian

    09/18/2020, 5:20 PM
    I am constantly getting this
    ld: warning: ignoring file /Users/vivek/AndroidStudioProjects/kmm-sample/shared/build/xcode-frameworks/shared.framework/shared, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
    Undefined symbols for architecture arm64:
      "_OBJC_CLASS_$_SharedGreeting", referenced from:
          objc-class-ref in ContentView.o
      "_OBJC_CLASS_$_SharedCalculatorCompanion", referenced from:
          objc-class-ref in ContentView.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    I am able to open the xcodeproject in XCode and run it on the iphone Simulator there.
    j
    • 2
    • 4
  • j

    jeggy

    09/19/2020, 10:42 PM
    I have successfully setup a multiplatform project. But I want to have my project as a multiplatform multi project. so I'm wrapping it all inside the
    allprojects
    and this works fine, but as soon as I add a
    include
    to my
    settings.gradle.kts
    file I immedietally get this error:
    Extension with name 'kotlin' does not exist. Currently registered extension names: [ext]
    . Does anyone know how to setup a multiplatform multi project using kotlin gradle script? or is this something that's not possible yet?
    m
    r
    • 3
    • 6
  • s

    Samuel Michael

    09/20/2020, 4:58 PM
    Question: How do I setup a iosApp as a workspace instead of project, mine is designed to only run when launched through xcworkspace not xcodeproj? I am trying to change the flag in xcodebuild from -project to -workspace Anyone have any luck with setting up their KMM plugin to do so?
    • 1
    • 1
  • s

    Samuel Michael

    09/20/2020, 6:40 PM
    Anyone have any experience adding Multiplatform framework to a iOS workspace which uses Carthage for managing frameworks?
    s
    d
    • 3
    • 33
  • s

    Siggi Gunnarss

    09/21/2020, 1:50 PM
    Has anyone has success running iOS apps from Android Studio using the new plugin? I get authentication errors when installing via AS, the same project installs fine using the same config via xcode.
    Reason: AMDeviceSecureInstallApplicationBundle failed with err = -402653177(The argument is invalid.)
    The error is similar to https://youtrack.jetbrains.com/issue/OC-17572 which is no longer valid.
    s
    j
    • 3
    • 4
Powered by Linen
Title
s

Siggi Gunnarss

09/21/2020, 1:50 PM
Has anyone has success running iOS apps from Android Studio using the new plugin? I get authentication errors when installing via AS, the same project installs fine using the same config via xcode.
Reason: AMDeviceSecureInstallApplicationBundle failed with err = -402653177(The argument is invalid.)
The error is similar to https://youtrack.jetbrains.com/issue/OC-17572 which is no longer valid.
s

Samuel Michael

09/21/2020, 2:58 PM
Under the hood it is just running xcodebuild so it is nothing too fancy going on, only real difference from running command in terminal is opening up a console /tool window for terminal output. If you want you could even make a custom run configuration to do the same thing. I would run the same
xcodebuild -project ...
command it is running in the terminal and see if there is any additional debugging info
s

Siggi Gunnarss

09/22/2020, 6:51 AM
Yeah, that's the strange thing, the compilation finishes successfully, both in AS and command line. There's some final step that attempts to transfer the file over which causes the problem. I assume that step is in the closed source ios plugin?
j

Jake

09/22/2020, 12:38 PM
I needed to update to Android Studio RC 2 a while ago to get this to work. I’m not sure if that’s still the latest version
s

Siggi Gunnarss

09/23/2020, 6:58 AM
Right, so AS 4.1 instead of 4.0. Worth a shot!
View count: 12