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

    iamsteveholmes

    06/25/2021, 7:45 PM
    Hey folks! I have what I think is a pretty common issue. I am building an app that will be connected to backend ktor servers from where it will get system data as well as create new data. The App will be fully operational offline. I'm planning to use either SQLDelight or Kodein DB to persist data on the device and when network is available it will send updates over the network to ktor servers storing state in a MongoDB. The issue is that you never know how long your app will be disconnected from the internet. Maybe you are going camping for the weekend. So it will need to persist the "RecordAdded"/Deleted/Updated events and send them when they are reconnected. Are there any libraries to do this? Some sort of polling solution that will attempt updates and only delete the local events when the update is successfully? Thanks in advance!
    l
    a
    • 3
    • 3
  • i

    iamsteveholmes

    06/25/2021, 9:27 PM
    Anyone know of a multiplatform alternative to workmanager?
    👍 1
    f
    r
    • 3
    • 5
  • e

    Elka

    06/26/2021, 12:59 PM
    Kotlin Native: Why are 
    implementation
     dependencies specified in submodules are exported when 
    transitiveExport = true
    ? Shouldn’t it only export dependencies marked with 
    api
    ?
    g
    c
    • 3
    • 4
  • f

    Francis Mariano

    06/26/2021, 2:27 PM
    Hello folks. I have the following expect function
    expect fun String.formatPlatform(vararg args: Any?): String
    and on iosMain module I wrote the actual function
    actual fun String.formatPlatform(vararg args: Any?): String {
        return NSString.create(format = this, args = arrayOf(args)).toString()
    }
    But when I compile that code I get this error :
    kotlin.Array<out kotlin.Any?>  is not supported here: doesn't correspond to any C type
    I tried to change the parameter type from expect function to Float or Double, but the error continues:
    kotlin.Array<out kotlin.Float?>  is not supported here: doesn't correspond to any C type
    I read the issue https://github.com/JetBrains/kotlin-native/issues/1834 but I do not solve the problem. Can anyone help me with that? Thank you.
    l
    • 2
    • 7
  • s

    saket

    06/26/2021, 5:59 PM
    Is it expected that intellij lets me use APIs from android sdk from common code as well as my jvm-only module? They don’t compile but intellij tries to autocomplete them, and even show lint warnings that only apply to android projects.
    c
    • 2
    • 2
  • s

    Sourabh Rawat

    06/27/2021, 1:10 PM
    following 

    https://www.youtube.com/watch?v=s5qnlv8hzH8▾

    , how can I use 
    bootRun
     gradle task? Its not visible in available tasks.
    j
    • 2
    • 2
  • r

    Robert Munro

    06/28/2021, 6:40 AM
    i have a
    jvmMain
    and an
    androidMain
    source folder in my shared module. It seems like l have to duplicate the actual class declaration in both jvmMain and androidMain as if I just have the jvm version the expected class says something like "there isnt an actual declaration for jvm" (referring to androidMain). If i delete my android source set and gradle declaration the shared library complains about a missing
    AndroidManifest.xml
    . So just wondering if it is normal that i would have to duplicate
    androidMain
    and
    jvmMain
    s
    j
    • 3
    • 8
  • c

    Carson Holzheimer

    06/28/2021, 7:49 AM
    [SOLVED] I’m getting the error
    error: no such module 'KotlinCommon'
    while building for Bitrise tests. Tests run fine locally on simulator and device. I have a kotlin module in my iOS app, using the cocoapods plugin. Module seems to build fine with BUILD SUCCESSFUL Any ideas?
    • 1
    • 1
  • n

    Napa Ram

    06/28/2021, 9:52 AM
    Hello Everyone, i completed My POC in KMM using Ktor, Realm and shared ViewModel, so now only UI need to take care in android and iOS. now i need to write the Unit Testing for Ktor, realm and shared viewmodel also, can anyone please share the blog or sample how we can write unit testing and do the mocking in kotlin multiplatform, Thanks to @John O'Reilly , i have done all these by learning from his blog's and sample code
    👀 1
    j
    r
    m
    • 4
    • 5
  • h

    Hossein Amini

    06/28/2021, 11:29 AM
    Hi everyone! In KMM project using Ktor, when I want to pass an access token to the header of a request I get this exception:
    io.ktor.client.features.ClientRequestException
    .  This is my code:
    httpClient.request("https://...") {
        method = <http://HttpMethod.Post|HttpMethod.Post>
    
        header("Authorization", "access token")
    }
    What’s wrong with this code?
    b
    • 2
    • 2
  • n

    Nicolas Verinaud

    06/28/2021, 1:10 PM
    [SOLVED] Hi ! I used to run my unit tests using a gradle configuration running through Android Studio but it does not show the test pane anymore. 😞 Do you know how to get it back ?
    Android Studio 4.2.1 / KMM Plugin 0.2.6
    • 1
    • 2
  • t

    Toby

    06/28/2021, 2:24 PM
    Hello, is anyone able to use
    AtomicReference
    from the native library? I do not have access to a (getter and) setter. Would I have to implement my own AtomicReference into my project to make it work?
    d
    e
    +2
    • 5
    • 28
  • j

    Jérémy CROS

    06/28/2021, 3:36 PM
    Hi guys! 🙂 Sorry in advance for the dumb question, kinda feel bad for asking it but I really couldn’t find the answer anywhere... We’re looking to start a new multiplatform project with my team and I’m already struggling with the basic setup of what tool to use. We already have an ios app and an android app, this new project will mostly be a “mathematics” library with lots of computation. Should not have any platform specific code for a while but I cannot be sure it will stay like that forever. I was looking at a KMM project in Android Studio but that comes with code for android app and ios app which I really do not care about. Intellij on the other hand has Mobile Application type project (same as KMM I assume ?), Mobile library which could fit my need? and Library which has common, jvm, js and native stuff and I have no idea if I need all this 😄 Kinda overwhelmed there, thanks for any help 🙂
    c
    b
    +2
    • 5
    • 18
  • s

    spierce7

    06/28/2021, 9:34 PM
    Does anyone know a fix for not being able to use multiplatform modules inside jvm modules? Even though the module is inluded as a dependency wtih
    jvm()
    target, its source code can’t be used.
    c
    a
    • 3
    • 7
  • n

    Napa Ram

    06/29/2021, 4:32 AM
    hey guys, what is the best way to fix red gradle configs in kmm project? apart from cache clean/rebuild/cleaning build dirs (because it didn't help). It was working fine yesterday when i reopened today it's not building Adding screenshot also
    l
    s
    • 3
    • 15
  • a

    atsushieno

    06/29/2021, 9:20 AM
    What would be options (libraries) to read and write zip archives in MPP?
    j
    • 2
    • 2
  • s

    Stefan Oltmann

    06/29/2021, 11:45 AM
    Anyone knows how to fix this?
    Execution failed for task ':shared:allTests'.
    > Failed to execute all tests:
    :shared:iosX64Test: java.lang.IllegalStateException: command '/usr/bin/xcrun' exited with errors (exit code: 148)
    ✅ 1
    • 1
    • 4
  • a

    Alberto

    06/29/2021, 2:30 PM
    Hello, I’m working on a KMP library for both Android/iOS, using Maps, Sets and ArrayDequeues that can be concurrently manipulated from different threads. Are there any available libraries that provide a “thread-safe” version of such collections (via AtomicReferences for example)? I found this one https://gist.github.com/gmazzo/03acdb2e6b59d0394ac69d521e51fea1 but was wondering what were the recommendations here.
    t
    • 2
    • 3
  • s

    Stefan Oltmann

    06/29/2021, 2:56 PM
    I get an error "EXC_BAD_ACCESS" when I try to call "onReceive":
    struct ContentView: View {
      @EnvironmentObject var store: ObservablePhotoStore
      var body: some View {
        VStack {
          Button("Show details") {
            store.dispatch(PhotoAction.Refresh())
          }
        }
        onReceive(store.$state) { value in
          print("test")
        }
      }
    }
    This is the observerved object:
    class ObservablePhotoStore: ObservableObject {
       
      @Published public var state: PhotoState = PhotoState(progress: false, photos: [], selectedPhoto: nil, testString: "never updated")
      @Published public var sideEffect: PhotoSideEffect?
       
      let store: PhotoStore
       
      var stateWatcher : Closeable?
      var sideEffectWatcher : Closeable?
    
      init(store: PhotoStore) {
         
        self.store = store
         
        stateWatcher = self.store.watchState().watch { [weak self] state in
          self?.state = state
        }
         
        sideEffectWatcher = self.store.watchSideEffect().watch { [weak self] state in
          self?.sideEffect = state
        }
      }
       
      public func dispatch(_ action: PhotoAction) {
        store.dispatch(action: action)
      }
       
      deinit {
        stateWatcher?.close()
        sideEffectWatcher?.close()
      }
    }
    @main
    class MyPhotoApp: App {
       
      let photoRepository: PhotoRepositoryImpl
      let store: ObservablePhotoStore
       
      required init() {
        photoRepository = PhotoRepositoryImpl()
        store = ObservablePhotoStore(store: PhotoStore(photoRepository: photoRepository))
      }
       
      var body: some Scene {
        WindowGroup {
          ContentView().environmentObject(store)
        }
      }
    }
    I'm new to SwitUI and I try to learn from https://github.com/Kotlin/kmm-production-sample how to receive changes in StateFlow to update my Swift UI. I'm looking for a simple way to do that and that sample project is already very complex.
    s
    • 2
    • 4
  • j

    Justin Yue

    06/29/2021, 6:16 PM
    I recently tried to create a new multiplatform project, but I have this error (see thread). If it helps, my kotlin version is 1.5.20. Edit: Fixed. I had initially used openjdk-16 but switched to the Jetbrains-runtime
    • 1
    • 1
  • d

    Daniele B

    06/29/2021, 7:31 PM
    I was listening to the KMM Webinar today, but I missed one point, where Kathrin says that since the last Kotlin release, we can replace PackForXcode with something else. I was looking into Kotlin 1.5.20 release notes, but I couldn’t find this specific thing. Can anyone provide a link with some information about this new feature?
    👀 1
    h
    s
    +2
    • 5
    • 10
  • o

    Osman Saral

    06/29/2021, 8:09 PM
    Hi, I'm getting
    No tests found for given includes
    error when I try to run my tests. As far as I could find, solutions proposed for this error are: 1. Adding
    useJUnitPlatform()
    to build.gradle. I'm using junit4 and this doesn't work 2. import
    org.junit.jupiter.api.Test
    instead of
    import org.junit.Test
    . Same as above 3. change setting Gradle -> Run Tests Using' from 'Gradle (default)' to 'IntelliJ IDEA'. This setting is not there on Android Studio Arctic Fox or Bumblebee I've tried to copy all the test related codes from KaMPKit and using exactly the same dependency versions as this branch. Same tests run on KaMPKit project but not on my project. Did anyone get this error before? What am I doing wrong?
    • 1
    • 1
  • d

    Devendra Patel

    06/29/2021, 8:24 PM
    Hello there, I am trying to use
    mParticle
    library cocoapod in Kotlin Multiplatform project but am seeing following error
    Execution failed for task ':shared:cinteropMParticle-Apple-SDKIos'.
    > Process 'command '/Applications/Android <http://Studio.app/Contents/jre/jdk/Contents/Home/bin/java|Studio.app/Contents/jre/jdk/Contents/Home/bin/java>'' finished with non-zero exit value 1
    
    * Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':shared:cinteropMParticle-Apple-SDKIos'.
    ....
    Does anyone have an insight on how I can fix this issue? Thanks
    • 1
    • 2
  • i

    itnoles

    06/30/2021, 3:13 AM
    Why I am getting
    java.lang.IllegalStateException: org.jetbrains.kotlin.resolve.multiplatform.ExpectedActualResolver@3af53289
    ?
    • 1
    • 1
  • s

    Stefan Oltmann

    06/30/2021, 10:07 AM
    Maybe some iOS Devs knows this: I try to fetch all images from my photo library using
    PHAsset.fetchAssets(with: .image, options: *nil*)
    but photos synced from my Mac (shown as "From my mac" in the gallery) are not contained there. How do I fetch also these photos?
    ✅ 1
    • 1
    • 1
  • l

    Lena Stepanova

    06/30/2021, 10:51 AM
    Hi everyone! Is it possible to dynamically change the host when making a request? I use ktor to access a local source (host IP is determined from user input) and this code works for Android, but in Ios I get org.koin.core.error.InstanceCreationException: Could not create instance for [Single:'...shared.ktor.LocalKtorApi']
    class LocalApi (log: Kermit) : LocalKtorApi {
        private var localUrl = ""
    
        // If this is a constructor property, then it gets captured
        // inside HttpClient config and freezes this whole class.
        @Suppress("CanBePrimaryConstructorProperty")
        private val log = log
    
        private val client = HttpClientProvider().getHttpClient(localUrl).config {
            defaultRequest {
                host = ""
                header(HttpHeaders.ContentType, ContentType.Application.Json)
                url {
                    //protocol = URLProtocol.HTTPS
                }
            }
            install(JsonFeature) {
                accept(ContentType.Text.Plain)
                val json = Json {
                    ignoreUnknownKeys = true
                    useAlternativeNames = false
                }
                serializer = KotlinxSerializer(json)
            }
    
            install(Logging) {
                logger = object : Logger {
                    override fun log(message: String) {
                        log.v("Network") { message }
                    }
                }
    
                level = LogLevel.ALL
            }
    
        }
    
    
        init {
            ensureNeverFrozen()
        }
    
    
        override suspend fun verifyLocalCredentials(url: String, credentials: String) {
            localUrl = url
            log.v { "credentials: $credentials" }
            return client.get {
                url(path = "/apps")
                header("Authorization", "Basic $credentials")
            }
        }
    
    }
    May be the problem is with ios HttpClient? Because it's simply
    actual class HttpClientProvider actual constructor() {
        actual fun getHttpClient(
            host: String
        ): HttpClient {
            return HttpClient(Ios){}
        }
    }
    :thread-please: 2
    • 1
    • 1
  • j

    Jérémy CROS

    06/30/2021, 12:20 PM
    Hi guys 🙂 Getting stuck here on building for Android on a multiplatform mobile library (which I was not expecting to be the issue 😛) I’ve managed to create an XCFramework for ios thanks to this https://github.com/ge-org/multiplatform-swiftpackage But now, trying to build the android part just doesn’t seem to work. The error I have is
    * What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.
    > Failed to calculate the value of task ':compileDebugJavaWithJavac' property 'options.generatedSourceOutputDirectory'.
       > Querying the mapped value of map(java.io.File property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, /Users/jeremy/perso/projects/untitled/build/generated/ap_generated_sources/debug/out)) org.gradle.api.internal.file.DefaultFilePropertyFactory$ToFileTransformer@5cf2ca8c) before task ':compileDebugJavaWithJavac' has completed is not supported
    I’ll add the entire gradle file in a thread, in case anyone has the slighest idea 🙂 Thanks! 🙂
    l
    c
    • 3
    • 10
  • a

    Alberto

    06/30/2021, 6:48 PM
    Hello, is there a way to retrieve the class name of an anonymous class? I have a usecase where I’m passing some objects from Swift to KMP, but when trying to retrieve the class name via
    object::class
    I only get
    class <anonymous>
    so calling any of the
    ::simpleName
    or calling
    getOriginalClassName
    on it just returns null
    e
    • 2
    • 7
  • r

    Rak

    07/01/2021, 3:25 AM
    Hi all, I gave a presentation earlier today on KMM. I would like to share my experiences.
    👍 2
    • 1
    • 1
  • n

    Napa Ram

    07/01/2021, 7:46 AM
    Hello Everyone, How can i get test coverage for Common Shared Code as i am using for reference KaMPKit for test case but not able to get the Code coverage any help please https://github.com/touchlab-lab/KaMPKit/tree/brady-aiello/upgrade-gradle-7.1
    👀 1
    s
    m
    • 3
    • 3
Powered by Linen
Title
n

Napa Ram

07/01/2021, 7:46 AM
Hello Everyone, How can i get test coverage for Common Shared Code as i am using for reference KaMPKit for test case but not able to get the Code coverage any help please https://github.com/touchlab-lab/KaMPKit/tree/brady-aiello/upgrade-gradle-7.1
👀 1
s

Stefan Oltmann

07/01/2021, 8:56 AM
It's not possible if you have Android in it. I did not manage to get it working. I guess we have to wait for JetBrains to come up with their code coverage solution.
n

Napa Ram

07/01/2021, 8:58 AM
i have only android and ios currently
m

Mejdi

07/05/2021, 5:00 PM
is getting the report of your JVM target tests would be enough ? or also your tests are part of common ?
View count: 12