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
squarelibraries
  • v

    veyndan

    07/06/2021, 12:38 PM
    Yeah, support for it has been merged (here, here), but it isn’t in the latest release
    j
    • 2
    • 1
  • j

    Jorge Castillo

    07/06/2021, 1:19 PM
    Unrelated question. I am trying to get
    RETURNING
    working for an
    INSERT
    query using postgresql, and seems that only using this
    WITH
    style it is possible. Still I'm getting errors:
    CREATE TABLE IF NOT EXISTS userEntity (
        user_id SERIAL PRIMARY KEY,
        slack_user_id VARCHAR NOT NULL,
        slack_channel_id VARCHAR
    );
    
    insert:
    WITH inserted_ids AS (
      INSERT INTO userEntity(slack_user_id, slack_channel_id)
      VALUES (:userId, :channelId)
      RETURNING user_id AS insert_id
    ) SELECT insert_id FROM inserted_ids;
    Pasting the stacktrace on the thread to avoid bloating the chat
    v
    • 2
    • 9
  • r

    rook

    07/07/2021, 3:32 PM
    I’m looking for the place in Retrofit source where suspend calls are placed on a particular coroutine dispatcher. Does anyone know where it is?
    • 1
    • 1
  • c

    Colton Idle

    07/09/2021, 4:03 PM
    Related off of the above question. I'm using mockwebserver and creating my own dispatcher. Which originally was a really simple when statement, but now I'm dealing with api calls that have url params and I feel like I'm missing something basic in order to get something like "wildcards" working correctly.
    when (request.path) {
        "/api/one/two" ->
            return "blah"
        "/api/three/four?arg=myArg" ->
            return "boop"
    I want the second case to basically catch all 
    api/three/four*
     instead of hard coding the arg. Or maybe there's another way I should go about this. e.g. Only get the path without the args, and then if I need the args I can drill down and get them from the request if need be? Thoughts?
    m
    j
    • 3
    • 6
  • j

    jw

    07/14/2021, 12:44 PM
    https://github.com/cashapp/sqldelight/discussions/2470#discussioncomment-1003652
    j
    m
    • 3
    • 17
  • e

    eygraber

    07/15/2021, 4:03 AM
    This didn't get much traction on SO so xposting: If I have the following inline class:
    interface StringId {
      val raw: String
    }
    
    @JvmInline
    value class MyId(override val raw: String) : StringId
    is it safe to pass it to a Retrofit function?
    interface MyApiEndpoints {
      @GET("/fetch/{id}")
      suspend fun fetch(@Path("id") id: MyId): Response<JsonObject>
    }
    https://stackoverflow.com/questions/68232128/is-it-safe-to-pass-a-kotlin-inline-class-to-a-retrofit-function
    b
    e
    • 3
    • 5
  • t

    Trevor Stone

    08/03/2021, 4:37 PM
    Ignorant question, if we need to create a new table with no relation to prior tables, does that still need a migration file? Seems like we would be needing to copy paste from the .sq file to a .sqm file
    b
    • 2
    • 1
  • m

    MiSikora

    08/03/2021, 6:39 PM
    It’s not a separate application. It’s an activity registered in the manifest https://github.com/square/leakcanary/blob/main/leakcanary-android-core/src/main/AndroidManifest.xml
    🙏 1
    👍 2
    w
    • 2
    • 1
  • m

    Michael Friend

    08/09/2021, 7:29 PM
    Were there any changes around the
    verifySqlDelightMigration
    task in the 1.5.0 release? After updating from 1.4.4 the task goes from passing to failing on a migration that reorders columns by renaming to a temp table, copying the rows, then dropping the temp table. The migration works fine when running on device but when running the verify task on 1.5.0+ I get the error
    Execution failed for task ':shared:verifyCommonMainDatabaseMigration'.
    > A failure occurred while executing com.squareup.sqldelight.gradle.VerifyMigrationTask$VerifyMigrationAction
       > Could not retrieve foreign keys for table TableA: Table not found: 'TempTableB'
    Here’s a small repo that recreates the issue https://github.com/mrf7/sqldelight-migration-verify
    a
    p
    • 3
    • 4
  • e

    Emiliano Schiavone

    08/09/2021, 10:57 PM
    Hello, Im using retrofit + koltin serializer and Kotlin Serialization Converter (Jake library). I want to see request and responses on the logcat. I added a convert into retrofit
    private val contentType =  "application/json".toMediaType()
    private val json = Json {
        prettyPrint = true
        ignoreUnknownKeys = true
    }
    
    ..
    
    ..addConverterFactory(json.asConverterFactory(contentType))
    But i cannot see the logs on logcat screen. Any idea how to display it?
    a
    • 2
    • 2
  • d

    dimsuz

    08/10/2021, 4:40 PM
    Seeking advice on
    wire
    +
    grpc client
    . On android client which uses okhttp as transport, blocking calls work 👌 , but our test streaming call "hangs" and then exits using socket timeout. We can see that server receives the request but then breakpoint which we have set in server code inside a generated grpc method doesn't even hit, so it hangs somewhere inside grpc stuff on server (presumably). Swift client, generated using some Apple library, connects and successfully works with the same streaming call. Any idea on how to debug where to look at would be appreciated.
    b
    j
    • 3
    • 30
  • t

    Trevor Stone

    08/10/2021, 6:02 PM
    With Turbine we were trying to structure some tests that we could trigger a source flow passed in via the constructor using a MutableStateFlow. Ended up seeing some strange behavior when we then do a statein on the output flow and unsure if it is a coroutine bug or a Turbine bug. We simplified it down to the smallest test to prove the case
    @Test
        fun passesOnJavaFailsOnNative() = runBlocking {
            val failingFlow = MutableStateFlow(null).stateIn(GlobalScope, SharingStarted.Eagerly, "")
            failingFlow.test { assertNull(expectItem()) }
        }
    
        @Test
        fun passesOnNativeFailsOnJava() = runBlocking {
            val failingFlow = MutableStateFlow(null).stateIn(GlobalScope, SharingStarted.Eagerly, "")
            failingFlow.test { assertEquals("", expectItem()) }
        }
    ➕ 1
    • 1
    • 1
  • d

    dimsuz

    08/11/2021, 5:47 PM
    One more
    wire
    +
    grpc
    question. If I have a service like this
    rpc getItemsStream(ItemRequest) returns (stream ItemResponse) {}
    How do I send the initial request? Wire generates the implementation of GrpcStreamingCall which has 2 channels. Do I understand correctly that I must send initial request using a
    sendChannel
    ? My issue posted above seems to be caused by no request body being sent. Sending it to the channel doesn't help, maybe I must do it otherwise? Stub implementation generated by
    grpc-kotlin
    library has this explicitly:
    fun getItemsStream(request: ItemsRequest): Flow<Response>
    , but
    wire
    generates function with no params in this case.
    b
    j
    r
    • 4
    • 21
  • r

    Rob Smith

    08/12/2021, 2:57 AM
    I'm clearly missing something obvious, but are there any examples of using a bearer token for auth with
    wire
    ?
    b
    j
    • 3
    • 9
  • j

    jw

    08/12/2021, 1:45 PM
    You should add a JsonAdapter for the nested type to your method signature and delegate to that. I'll put the full snippet (in Java) as a threaded reply to this message (BOOOO threads)
    w
    • 2
    • 4
  • w

    William Reed

    08/13/2021, 1:21 PM
    Hi again - another moshi question. I have a java class with a no arg constructor and the following field
    private long camera_id = 0;
    when the field is absent in the JSON I get a
    com.squareup.moshi.JsonDataException: Expected a long but was NULL at path $.camera_id
    Do I need to make my own type adapter to handle this case? Trying to migrate my teams project from GSON
    a
    p
    • 3
    • 4
  • a

    aravind

    08/18/2021, 10:05 AM
    Hello all, I instantiate
    AndroidSqliteDriver
    in androidMain instead of application module. It works fine until i enable progaurd and throws `java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/sqldelight/android/AndroidSqliteDriver`;. And also i could notice that mapping.tx file has no entry of this class. Can someone be able to help on this?
    c
    • 2
    • 2
  • d

    dimsuz

    08/19/2021, 10:17 AM
    Hi. Trying to upgrade
    Timber
    to
    5.0.1
    and get this error:
    No matching variant of com.jakewharton.timber:timber:5.0.1 was found. The consumer was configured to find an API of a library compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
              - Variant 'releaseApiPublication' capability com.jakewharton.timber:timber:5.0.1 declares an API of a library, and its dependencies declared externally:
                  - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, preferably in the form of class files
    Indeed, it's being declared as a dependency in a kotlin-plugin module (no android), but the thing is that timber
    4.x
    was
    aar
    too. I'm curious what has changed?
    e
    j
    • 3
    • 7
  • s

    spierce7

    08/19/2021, 8:40 PM
    How close is the okio filesystem to being ready to be used across Android and iOS?
    s
    j
    • 3
    • 5
  • j

    jw

    08/23/2021, 3:36 AM
    Are you saying you use package-less imports to work around the lack of type resolution to know definitively from which package a type exists?
    e
    • 2
    • 6
  • e

    ephemient

    08/23/2021, 3:49 AM
    I was recently bitten by https://github.com/square/kotlinpoet/issues/1035 after upgrading from 1.6.0 to 1.9.0 - looks like 1.8.0 started quoting "value". would it be feasible to get kotlinpoet not to quote soft keywords except when necessary?
    ➕ 1
    e
    • 2
    • 1
  • j

    jean

    08/24/2021, 7:16 AM
    I’m testing a flow with turbine and I wonder if there is a better way to do this :
    sealed class SideEffect {
        data class Effect1(val someValue: String) : SideEffect()
        Effect2 : SideEffect()
    }
    val mutableSharedFlow = MutableSharedFlow<SideEffect>(replay = 0)
    flowOfSideEffects.test {
        mutableSharedFlow.emit(Effect1("test")
        assertTrue((awaitEvent() as Event.Item).value is CustomerScreenSideEffect.NavigateToCustomerDetails)
    }
    Now
    awaitEvent()
    returns a value of type
    Event<SideEffect>
    rather than just a
    SideEffect
    like
    expectItem
    did, if I remember correctly. So my question is, is there a better way to down cast the value returned
    awaitEvent
    ?
    j
    • 2
    • 2
  • r

    Rob Smith

    08/26/2021, 8:08 PM
    Experiencing an issue with
    wire
    and an rpc call that returns
    google.protobuf.Empty
    service AService {
       rpc Working(AParam) returns (AReturn)
       rpc Fails(AParam) returns (google.protobuf.Empty)
    }
    b
    • 2
    • 7
  • d

    dimsuz

    08/27/2021, 1:22 PM
    I remember reading that sorting collections in sqlite can be way faster than doing it in memory (after reading from sqlite into List and then doing
    sort
    ). Is that true, despite the fact that sqlite is on disk (so IO)? But there's that
    mmap
    and memory cache magic, so IO may not be as tough as it seems. I can't recall the article I've read.
    d
    • 2
    • 1
  • c

    Colton Idle

    08/29/2021, 6:19 AM
    I have a plain old java-library gradle module. In this module I'm making use of mockhttpserver from okhttp and I'm just hardcoding responses to api calls. Everything is working great. I have this
    path == "/api/myendpoint" -> {
        return MockResponse()
            .setResponseCode(200)
            .setBody(
                """
                {"status":0,"message":"SUCCESS"}
                """.trimIndent())
    }
    I now want to take this json, place it into
    resources/json/myendpoint.json
    and read it from the file instead of having large json snippets in my kotlin code. As an end result I'd love to be able to do this but I'm a bit in over my head in terms of grabbing a resource and converting it to a string. There seems to be like 1000 different ways to do this via SO and from what I would expect... maybe there's an easy way to do this with okhttp/mockwebserver/okio that I'm missing?
    path == "/api/myendpoint" -> {
        return MockResponse()
            .setResponseCode(200)
            .setBody(javaClass.classLoader.getResourceAsStream("json/myendpoint.json").toString())
    }
    e
    • 2
    • 10
  • n

    nitrog42

    08/30/2021, 8:17 AM
    Hello, I'm currently working on a plugin to generate ressources for android projets, and I'm using Kotlin Poet to generate .kt files containing compose colors (parsed from a Txt). I have a quick question and didn't want to make an issue for that as it probably not the wanted behavior -> when generating properties to a file, it adds a newline between each property :
    import androidx.compose.ui.graphics.Colors
    
    public val white: Color = Color(0xFFFFFFFF)
    
    public val black: Color = Color(0xFF000000)
    Is there anyway to prevent this ? (or better, control the newlines, to make section ?) I'm using
    addProperty(
        PropertySpec.builder("white", ClassName("androidx.compose.ui.graphics", "Color"))
            .initializer("Color(0xFFFFFFFF)")
            .build()
    )
    m
    r
    • 3
    • 11
  • m

    myanmarking

    08/31/2021, 2:30 PM
    is there any way to debug android sqldelight plugin? The code isn’t generated, unless i run the task ./gradlew generateSqlDelight
    m
    a
    • 3
    • 32
  • e

    eygraber

    08/31/2021, 9:32 PM
    Is there any plan to make workflow a multiplatform library?
    z
    s
    • 3
    • 4
  • c

    Colton Idle

    09/01/2021, 11:08 PM
    A bit over my head here. I'm using charles and it works fine inspecting all of my retrofit calls. But when I use mockHttpServer from okhttp and I'm hooked up to charles I get a failure.
    <h1>Charles Error Report</h1>
    <h2>Failed to connect to remote host</h2>
    Is there some kind of configuration I can set on mockHttpServer so I can have it set to localhost but also use charles?
    e
    • 2
    • 13
  • j

    jw

    09/02/2021, 11:01 AM
    Flow is not supported. You should just return ResponseBody directly in a suspend fun
    m
    z
    p
    • 4
    • 4
Powered by Linen
Title
j

jw

09/02/2021, 11:01 AM
Flow is not supported. You should just return ResponseBody directly in a suspend fun
m

ms

09/02/2021, 12:44 PM
the how can I listen to the stream?
z

Zach Klippenstein (he/him) [MOD]

09/02/2021, 1:11 PM
It’s not a stream then, it’s a single suspending call. Individual network calls were never conceptually streams even with Rx, it just happened that it was convenient to treat them as streams of a single item in order to integrate with the whole RxJava model. Suspend functions are a much better way to model network calls because they're much closer to how the call actually works - you invoke the call (send the request), then wait for the response (suspend), and when the response comes back your program can continue with processing it (suspend cal resumes/returns).
You can easily convert a suspend function into a Flow if you need to treat it as a stream for other reasons. I believe there’s an
asFlow
extension function on suspend function references, or you can do something like
flow { service.call() }
p

Paul Woitaschek

09/06/2021, 8:58 PM
Yep, suspend {}.asFlow
View count: 10