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
touchlab-tools
  • p

    Peter Kucera

    07/10/2020, 10:40 AM
    Hi all, theoretically, should it be possible to access dynamically generated R class in androidMain code?
    r
    • 2
    • 2
  • k

    Kapil Godhwani

    07/10/2020, 4:15 PM
    Hi folks, I am trying to figure out the workings of the KaMP kit and i saw the creation of
    NativeViewModel
    in the shared code. Wondering if that is needed for avoiding any concurrency issues on native or is it because android ends up using the standard android
    ViewModel
    component and we are trying to create a VM for Native with almost the same functionality except android specific one. Another query I had was, if instead of doing a MVVM architecture, if I create a project structure in MVP(going a bit old school), can I put both my Model and Presenter in common code and avoid creating 2 different ViewModels that are platform specific. Considering KaMP kit uses MVVM, I am sure this debate would have come up in the past and would be very glad if you could share its outcome and avoid me some future pains 😂.
    r
    • 2
    • 3
  • d

    David Chavez

    07/15/2020, 7:25 AM
    Hey all, is there a way to specify for a cocoapod to only be linked and not have cinterop run? Context: I've run into a lib that requires this -- but they assume you use their cocoapods plugin (which I'd rather not do if it can be helped).
    • 1
    • 1
  • p

    Peter Kucera

    07/16/2020, 10:27 AM
    Hey all, pls is there some alternative of Thread.current.name or Thread.stacktrace in Kotlin/Native?
    r
    • 2
    • 1
  • p

    Peter Kucera

    07/20/2020, 2:54 PM
    Hi all, quick one - How do you manage your enviroments while using KMP? Is there a way to define build variants so they are accesible even in commonMain? Thanks.
    r
    • 2
    • 1
  • a

    Alex Trotsenko

    07/24/2020, 10:36 PM
    Hi, I am trying to request KMP starter kit via https://touchlab.co/kamp-kit-touchlab/, but I am constantly getting "Subscription Error: An error occurred, please try later.". Does anyone know what might be wrong or how to fix this issue?
    e
    • 2
    • 2
  • p

    Peter Kucera

    07/28/2020, 10:15 AM
    I’m implementing FIFO Queue in Kotlin/Native, and I need to add elements to back and front of the queue. Is there some thread safe collection that allows this in Kotlin/Native? In Kotlin/JVM I would use e.g. ConcurrentLinkedDeque.
    r
    • 2
    • 1
  • d

    Daniele B

    08/07/2020, 1:15 PM
    I have a question about platform-specific libraries. For example Ktor. Let’s say, I use Ktor only in the shared project. And the shared project just has “CommonMain”. So, it doesn’t have neither “AndroidMain” nor “IosMain”. All the shared code is written in CommonMain and it’s perfectly compatible for both. There is not expect/actual implementation. In such case, do I still need to add platform-specific libraries such as “io.ktor:ktor-client-core-jvm”. And considering “AndroidMain” doesn’t exist, should I add it in “CommonMain” sourceset?
    r
    • 2
    • 5
  • a

    Alberto

    08/10/2020, 4:28 PM
    I'd like to create some interfaces in the common shared code that will be implemented in platform specifics code (Android/iOS either via expect/actual, but more likely interfaces implemented in separate packages). What would be the best way to pass in Platform specific objects, for example Context / Activity in Android, and equivalents in iOS? I'd imagine this could be a quite common scenario, didn't find an example on the Kamp Kit app (unless I've missed it).
    r
    • 2
    • 11
  • d

    Daniele B

    08/12/2020, 11:33 AM
    @russhwolf I had a look at your multiplatform-settings library and it seems very interesting. I was browsing the sample you have in Github and I can see that you defined the settings in the commonMain, but you are instantiating it in the specific-platform app code. I am actually trying to do something a bit different. I have written a ViewModel (and a DataRepository) in CommonMain, while on the platform-specific app code I only keep the UI layer (JetpackCompose in Android and SwiftUI in iOS, then I am planning to use Vue.JS for Web). So in my case the DataRepository is fully on CommonMain. I would like to find a way to connect the MultiplatformSettings to the DataRepository. So I am not looking to instantiate MultiplatformSettings in each platform-specific app code, but just on the shared code, as any data coming from there it would populate the ViewModel, which is shared among all platforms. I wonder if MultiplatformSettings would work in this way too. Clearly, as the Settings Android constructor requires the applicationContext to be passed, I need to find a way to pass the context to the DataRepository where I want to instantiate Settings. As you understand, I am very new to the whole multiplatform thing. Do you have any sample that could explain how to do that in the shared code (in case it’s a feasible thing) ?
    r
    • 2
    • 29
  • d

    Daniele B

    08/12/2020, 11:47 AM
    I can see KampKit uses MultiplatformSettings in another different way. Settings are defined in AndroidMain and IosMain, but they are instantiated in the platform-specific app code via Koin.
    p
    k
    • 3
    • 6
  • r

    romtsn

    08/19/2020, 1:28 PM
    hi guys, I am trying to integrate sqldelight with sqlcipher on ios - I’ve gone through your article and did everything like suggested (building a static framework with sqlcipher pod as a dependency), but now am facing a weird issue - it looks like this works from code, so I can do some operations over a database (at least the last_changed_date in the file system changes), but when I try to open the db file with the db-browser or decode via sqlcipher-cli the password does not seem to work, so I cannot access the data. Could this be due to the recent fix which is not yet released in sqliter? Or is the db encrypted with some different algorithm than the default one for sqlcipher 4.+? Here is my database config just in case:
    val dbConfig = DatabaseConfiguration(
                name = "name.db",
                version = MyDb.Schema.version,
                create = { connection -> wrapConnection(connection) { MyDb.Schema.create(it) } },
                upgrade = { connection, oldVersion, newVersion ->
                    wrapConnection(connection) {
                        MyDb.Schema.migrate(it, oldVersion, newVersion)
                    }
                },
                basePath = customDirPath,
                key = key,
                journalMode = JournalMode.DELETE
            )
    Thanks!
    s
    • 2
    • 12
  • k

    kpgalligan

    08/24/2020, 1:38 PM
    Multithreaded coroutines doesn’t always play nice with the freezing stuff. The second block…
    withContext(Dispatchers.Default) {
                log.e { "Never get's executed" }
                log.e { "Never called" }
            }
    references
    log
    , which is a field of
    BreedModel
    . That will cause
    BreedModel
    to freeze when coroutines tries to run that block on a different thread. That happens inside of coroutines “machinery”, which prior to native, didn’t really expect passing state between threads to throw exceptions.
    ensureNeverFrozen()
    is new and coroutines hasn’t always dealt with it properly. I’ve seen some bugs submitted about it. Also, look at other output and see if you see anything about coroutines and “machinery”. Sometimes you will see that.
    k
    • 2
    • 1
  • i

    Ivann Ruiz

    08/27/2020, 7:17 PM
    Hey, been playing around with KaMPKit since yesterday and noticed that the
    androidMain
    folder in the android view doesn't show. However, I can see that folder when I switch to the project view. Do you all see the same? it should be visible in the android view as well...
    n
    k
    • 3
    • 4
  • z

    zsperske

    08/31/2020, 1:50 AM
    I was taking a look at the
    iOSTest
    directory and noticed there isn't a corresponding block in the build.gradle, are its dependencies inherited from
    iOSMain
    or am I missing something?
    r
    • 2
    • 1
  • d

    Daniele B

    08/31/2020, 3:15 PM
    Currently just testing multiplatform on Android (not iOS or Web yet). I would like to clarify the configuration of coroutines and ktor. In the KaMPKit,
    androidMain
    has
    org.jetbrains.kotlinx:kotlinx-coroutines-android
    , but in my project it seems to compile also without specifying it. However it doesn’t compile if from
    androidMain
    I remove
    io.ktor:ktor-client-android
    . Can anyone give an explanation? Is there a reason why Ktor requires the android-specific library and coroutines doesn’t?
    r
    • 2
    • 2
  • d

    Daniele B

    08/31/2020, 3:31 PM
    One other source of confusion is Kotlin serialization. Sometimes specified as
    kotlin-serialization
    and sometimes as
    kotlinx-serialization
    . I have seen it specified in different ways: 1) as
    plugins{ id("kotlinx-serialization") }
    in *common*’s build.gradle.kts file 2) as
    plugins{ kotlin("plugin.serialization") }
    in *common*’s build.gradle.kts file 3) as
    kotlin{ sourceSets{ dependencies{ implementation("org.jetbrains.kotlinx:kotlinx-serialization-core) }}}
    in *common*’s build.gradle.kts file 4) as
    buildscript{ dependencies{ classpath("org.jetbrains.kotlin:kotlin-serialization") }}
    in project-level build.gradle.kts file
    r
    • 2
    • 3
  • p

    Peter Kucera

    09/01/2020, 12:40 PM
    Hey all, what is the best way of implementing functionality similar to JVM Collections.synchronizedList only by using Kotlin/Native? Thanks! https://developer.android.com/reference/java/util/Collections#synchronizedList(java.util.List%3CT%3E)
    t
    k
    • 3
    • 5
  • d

    Daniele B

    09/01/2020, 2:53 PM
    is the newly announced JetBrains Kotlin Multiplatform Mobile plugin going to do everything which was previously done by TouchLab Xcode plugin, or there are still reason to install the latter?
    k
    • 2
    • 7
  • p

    Peter Kucera

    09/04/2020, 3:40 PM
    Hey all, please what version of Android Studio do you use to build projects based on Kampkit? Is Kampkit working well on AS 4+?
    r
    • 2
    • 1
  • i

    Ian Arbuckle

    09/05/2020, 1:38 PM
    Hey guys. Any progress on the current issue with adding
    ios()
    target? https://github.com/touchlab/KaMPKit/issues/133
    👍🏽 1
    r
    • 2
    • 2
  • p

    Peter Kucera

    09/15/2020, 3:52 PM
    Hey all, is there some way to share also resources like colors/themes using KMP shared module? Have you tried to move colors to shared? Thanks
    k
    • 2
    • 1
  • k

    kpgalligan

    10/15/2020, 1:51 PM
    buildscript {
        repositories {
            google()
            mavenCentral() //<-- This
            jcenter()
        }
        dependencies {
            classpath(Deps.android_gradle_plugin)
            classpath(Deps.SqlDelight.gradle)
            classpath(Deps.cocoapodsext)
            classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
    
            classpath(kotlin("gradle-plugin", Versions.kotlin))
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build gradle files
        }
    }
    v
    • 2
    • 22
  • k

    kpgalligan

    10/16/2020, 7:50 PM
    This is a little out of “kampkit” territory, but I guess is this on a new db? This error basically says you’re violating foreign key constraints.
    v
    • 2
    • 1
  • r

    Reshadf

    11/13/2020, 12:36 PM
    hello is it possible to keep our existing iOS and Android projects in separate repos while having the Kotlin Shared Library as a separate repo?
    k
    a
    • 3
    • 6
  • p

    Peter Kucera

    11/16/2020, 1:28 PM
    Hi guys. I have written UseCases using Observables (for logic that emits values) and then Completables(Logic that only has to be executed and doesnt return value, e.g. InvalidateDataUseCase). Currently I am migrating this implementation from RxJava to coroutines & Kotlin/Native. My question - what is the best way to replace Completables using coroutines and write alternative to CompletableUseCases inside shared?
    r
    • 2
    • 1
  • c

    CamiloVega

    12/17/2020, 8:39 PM
    Has anyone had issues debugging on android studio? Trying to set a breakpoint on the Breed model, and the IDE says Breakpoint does not belong to any Class Debugging works on the Activity and the view model
    r
    • 2
    • 6
  • k

    kpgalligan

    12/29/2020, 4:07 PM
    Mt coroutines supports background dispatchers, including Dispatchers.Defaut. data passed between threads is frozen, just fyi
    🙌 1
    w
    • 2
    • 2
  • p

    Paul Woitaschek

    02/04/2021, 8:23 AM
    The stately iso collection release 1.1.1 is missing. https://mvnrepository.com/artifact/co.touchlab/stately-iso-collections When I use 1.1.1-a1, it fails to build with:
    e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
        class co.touchlab.stately.collections.IsoMutableMap, unresolved supertypes: co.touchlab.stately.isolate.IsolateState
    It seems it has no dependency on
    stately-isolate
    r
    k
    • 3
    • 13
  • l

    Lena Stepanova

    02/10/2021, 1:45 PM
    Hi, I'm wondering if there is a way to implement something like suspend fun Transacter.transactionWithContext, but that would return result. I tried something like this, but I feel stuck In Couroutine Extensions:
    suspend fun <T: Any> Transacter.transactionWithContextResult(
        coroutineContext: CoroutineContext,
        noEnclosing: Boolean = false,
        body: TransactionWithReturn<T>.() -> T
    ): T {
        return withContext(coroutineContext) {
            this@transactionWithContextResult.transactionWithResult(noEnclosing) { body }
        }
    }
    Using in DatabaseHelper:
    suspend fun getAllItems(): List<Item> {
        dbRef.transactionWithContextResult<List<Item>>(backgroundDispatcher) {
            dbQueries.getAllItems(::mapItemsSelecting).executeAsList()
        }
    }
    r
    • 2
    • 4
Powered by Linen
Title
l

Lena Stepanova

02/10/2021, 1:45 PM
Hi, I'm wondering if there is a way to implement something like suspend fun Transacter.transactionWithContext, but that would return result. I tried something like this, but I feel stuck In Couroutine Extensions:
suspend fun <T: Any> Transacter.transactionWithContextResult(
    coroutineContext: CoroutineContext,
    noEnclosing: Boolean = false,
    body: TransactionWithReturn<T>.() -> T
): T {
    return withContext(coroutineContext) {
        this@transactionWithContextResult.transactionWithResult(noEnclosing) { body }
    }
}
Using in DatabaseHelper:
suspend fun getAllItems(): List<Item> {
    dbRef.transactionWithContextResult<List<Item>>(backgroundDispatcher) {
        dbQueries.getAllItems(::mapItemsSelecting).executeAsList()
    }
}
r

romtsn

02/11/2021, 9:04 AM
I guess it’s a better question for #squarelibraries but what exactly does not work here? The type cannot be inferred I assume?
l

Lena Stepanova

02/11/2021, 9:08 AM
r

romtsn

02/11/2021, 9:09 AM
you have to invoke your
body
actually, so change it to either
body.invoke()
or just
body()
l

Lena Stepanova

02/11/2021, 9:11 AM
🤦‍♀️ Thanks! I'll give it a try later :)
View count: 5