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

    gts13

    09/13/2022, 2:36 PM
    can someone please explain me why the androidx.compose.material3 is not enough when I want my theme to inherit from
    Theme.Material3.DayNight.NoActionBar
    and I also need to add the material-components-android which gives me also components from material 2 when the dependency is added in the project?
    g
    • 2
    • 2
  • s

    Sylvain Patenaude

    09/13/2022, 3:14 PM
    Not sure if in good channel, but we have a client that uses an android library (.jar) generated from kotlin multiplatform from React Native code. (They also use an iOS library generated from the same kotlin multiplatform code.) Now the iOS code still works fine, but on the Android side, they now have a java.lang.NoSuchMethodError as the static (extension) method UByteArray.get-impl isn't found anymore. I couldn't reproduce on my side from a Java client. Here are some info: java.lang.NoSuchMethodError: No static method get-impl([BI)B in class Lkotlin/UByteArray; or its super classes (declaration of 'kotlin.UByteArray' appears in /data/app/com.monbuilding.app-GLyhWQ0PinE67M1jnUSHPw==/base.apk:classes29.dex) Build Information: buildToolsVersion = "30.0.2" minSdkVersion = 26 compileSdkVersion = 30 targetSdkVersion = 30 RNNKotlinVersion = "1.5.30" // Or any version above 1.3.x RNNKotlinStdlib = "kotlin-stdlib-jdk8"
  • s

    Sergio C.

    09/13/2022, 4:57 PM
    Is it necessary to escape the dollar sign in a string?
    "**/R\$*.class"
    m
    j
    • 3
    • 3
  • r

    Radoslaw Juszczyk

    09/14/2022, 11:27 AM
    Hey guys, I am updating kotlin from 1.6.10 to 1.7.10 in my project and now when I try to sync gradle it fails with:
    A problem occurred configuring project ':android'.
    > Failed to notify project evaluation listener.
       > Could not create task ':android:compileDebugAndroidTestKotlin'.
          > Cannot invoke "String.trim()" because "in" is null
       > KotlinJvmAndroidCompilation with name 'debugAndroidTest' not found.
    If I try the same with kotlin 1.6.10 it works fine. Any ideas?
    q
    • 2
    • 5
  • p

    paulex

    09/14/2022, 9:34 PM
    Any major idea why one would use the Android Instrumentation class for within an app, is this a good practice ?
    j
    • 2
    • 2
  • s

    svenjacobs

    09/15/2022, 6:48 AM
    Hey there, in an Android project with 100% Kotlin code, what benefits are there to target JVM 11 instead of 1.8?
    android {
        compileSdkVersion 33
    
        compileOptions {
          sourceCompatibility JavaVersion.VERSION_11
          targetCompatibility JavaVersion.VERSION_11
        }
    
        kotlinOptions {
          jvmTarget = "11"
        }
    }
    I assume the Android Gradle plugin will desugar the bytecode to be compatible with Java 1.8 (or 1.6?) so what are the benefits of letting the Gradle plugin do this instead of using 1.8 as JVM target?
    m
    • 2
    • 4
  • m

    martin suchodol

    09/15/2022, 11:59 AM
    Hi, I'm working on an app to display weather using openWeather API, retrofit and moshi. The last thing I need to do. It is to display weather information for each day. For this I need to create an adapter for listview. So I had an idea inside the onResponse method. Add individual elements to the array. But that doesn't work. Could someone advise me how to do this?
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
    
    
            val _status = MutableLiveData<String?>()
    
            val status: LiveData<String?> = _status
            val api : String = "33aa634c216259f797f35e862f0*****"
    
            val spinner = findViewById<Spinner>(R.id.cities)
            //val result = findViewById<TextView>(R.id.result)
            val cities = arrayOf("New York", "Sydney")
            val cnt = findViewById<EditText>(R.id.NumberOfDays)
            val button = findViewById<Button>(R.id.button)
    
            val arrayAdapter: ArrayAdapter<*>
            val data = arrayListOf<String>();
            var listView = findViewById<ListView>(R.id.list)
            arrayAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, data)
            listView.adapter = arrayAdapter
    
    
            spinner.adapter = ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, cities)
    
    
            button.setOnClickListener {
                val selected = spinner.selectedItem as String
    
                var lat: String = ""
                var lon: String = ""
                if (selected == "New York") {
                    lat = "40.79052384606425"
                    lon = "-73.95908688800822"
                } else if (selected == "Sydney") {
                    lat = "-33.8470241774331"
                    lon = "151.0624326592654"
                }
    
                if(!TextUtils.isEmpty(cnt.text.toString())){
                    lifecycleScope.launch{
                        WeatherApi.retrofitService.getWeatherData(lat, lon, api, "metric", cnt.text.toString()).enqueue(object: Callback<WeatherInfo> {
                            override fun onResponse(call: Call<WeatherInfo>, response: Response<WeatherInfo>) {
                                data.add(response.body()?.city?.name.toString())
                                //result.text = response.body().toString()
                                Log.d("Full response: ", response.body().toString())
                            }
    
                            override fun onFailure(call: Call<WeatherInfo>, t: Throwable) {
                                Log.d("Failure: ", t.message.toString())
                            }
    
                        })
                    }
                }
            }
    
        }
    }
    j
    • 2
    • 6
  • a

    Ahmed Dridi

    09/15/2022, 12:53 PM
    Hey guys good morning. i am trying to publish a KMM library to maven central i hape followed this article https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k but the publishment is always failing i am getting the error in the screenshot attached below.
    j
    l
    • 3
    • 4
  • c

    Christy K

    09/15/2022, 7:04 PM
    Note: I have two adapters in this app. It will recognize the interface functions I have in the other one. But not this one
  • a

    Adam Cooper

    09/15/2022, 7:06 PM
    You're trying to call a method as a static function. What you want is
    interface OnDeleteItemClickListener {
        companion object {
            fun onDeleteItemClick(position: BarrelFreestyle)
        }
    }
    https://www.programiz.com/kotlin-programming/companion-objects
    c
    g
    • 3
    • 6
  • b

    Ben Edwards

    09/15/2022, 9:56 PM
    Having a problem calling setDefaultDisplayHomeAsUpEnabled. The tutorial I am doing actually says I should use
    supportActionBar?.setDefaultDisplayHomeAsUpEnabled(enableHome)
    but this gives more errors, the version I am trying with true gives `ActionBar.setDefaultDisplayHomeAsUpEnabled can only be called from within the same library group prefix (referenced groupId=
    androidx.appcompat
    with prefix androidx from groupId=
    Flicker Browser
    )` Any ideas?
    package com.funkytwig.flickerbrowser
    
    import android.util.Log
    import android.view.View
    import androidx.appcompat.app.AppCompatActivity
    import androidx.appcompat.widget.Toolbar
    
    private const val TAG = "BaseActivity"
    
    // internal as don't have to be available outside this project ?? check ??
    internal const val FLICKER_QUERY = "FLICKER_QUERY"
    internal const val PHOTO_TRANSFUR = "PHOTO_TRANSFUR"
    
    open class BaseActivity : AppCompatActivity() {
        internal fun activateToolbar( home:Boolean) {
            Log.d(TAG, "activateToolbar")
    
            var toolbar = findViewById<View>(R.id.toolbar) as Toolbar
            setSupportActionBar(toolbar)
            supportActionBar?.setDefaultDisplayHomeAsUpEnabled(true) // does not work
    
        }
    }
    c
    • 2
    • 1
  • a

    Anshulupadhyay03

    09/16/2022, 7:31 AM
    Hi All, Can anyone direct me how to achieve the same thing

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

    . on Android recycler view with pagination ??
  • n

    nuhkoca

    09/16/2022, 10:45 AM
    Hey people, do you know how to find a distance between 2 points along the curve in circle in Canvas?
    r
    s
    • 3
    • 7
  • s

    Sarthak Gupta

    09/16/2022, 12:31 PM
    Hi Guys, can anyone help debug uiJank using profiler and jetpack compose ?
    n
    • 2
    • 3
  • k

    KotlinLeaner

    09/16/2022, 1:33 PM
    Hi I am trying to add OptIn in my compiler gradle.
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            freeCompilerArgs += [
                "-Xuse-experimental=com.google.accompanist.permissions.ExperimentalPermissionsApi"
            ]
        }
    }
    I tried this piece of code but it giving me error. Can anyone guide me what I am doing wrong here
    c
    j
    • 3
    • 7
  • e

    Eric Womer

    09/17/2022, 9:45 PM
    Is there a site for Jetpack Compose API references, like what classes need what imports to import?
    n
    • 2
    • 1
  • e

    Eric Womer

    09/17/2022, 9:50 PM
    Like something I can search without dragging out everything with the word surface attached to it.
  • o

    Omar Qadour

    09/19/2022, 9:38 AM
    Hey guys, i'm tryin to make a MAD scorecard but the page madscorecard.withgoogle.com is not working. Do you have any idea why is it down and if it will work again soon?
    t
    i
    l
    • 4
    • 7
  • s

    Sufyan Sattar

    09/19/2022, 2:51 PM
    You all are working in Jetpack compose
    y
    • 2
    • 1
  • s

    Sufyan Sattar

    09/19/2022, 2:51 PM
    What you think, compose is good or not?
    j
    c
    c
    • 4
    • 8
  • j

    Jorge Cordero Camarena

    09/19/2022, 3:53 PM
    Hey guys, need some help, I have the following scenario: I have an object that gets populated through multiple screens (I use Compose), what is the right way to do this? • A - Have a ViewModel scoped to the Activity/Fragment and mutate the object in each screen? • B - Pass the object down to each Composable and mutate it in each VM (scoped to the Composable) ? • C - What would be the right way?
    c
    • 2
    • 2
  • t

    Travis Griggs

    09/19/2022, 4:01 PM
    I am trying to add some simple JSON deserialization to our app; I'm trying to follow the instructions here: https://kotlinlang.org/docs/serialization.html. What's befuddling me is where I'm supposed to put these two build.gradle lines:
    plugins {
        id 'org.jetbrains.kotlin.jvm' version '1.7.10'
        id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10'
    }
    There's two build.gradle files. Which one? I've tried placing it in both of them at various locations, and I always get errors about it needing to above or before one thing or another. Is the snippet/instructions up to date?
    p
    j
    +2
    • 5
    • 10
  • l

    Lilly

    09/19/2022, 11:11 PM
    I have multiple
    Long
    Int
    and
    Byte
    variables which I use across my codebase but have to convert them to different types. Lets take a
    Long
    variable which I have to convert to int (
    toInt()
    ) or byte (toByte()) at different places. Is it common to provide the same variable as
    Int
    or as Byte, e.g.
    myVariableAsLong
    ,
    myVariableAsInt
    ,
    myVariableAsByte
    ? Does this approach make sense, is there another common approach for this case or is it pointless?
    j
    j
    • 3
    • 5
  • h

    Harshad Pawar

    09/20/2022, 6:42 AM
    hello everyone i am facing following issue after updating my android studio to dolphin. someone help me on this https://stackoverflow.com/questions/73772547/android-studio-dolphin-2021-3-1-does-not-show-layout-preview
    i
    • 2
    • 1
  • c

    czuckie

    09/20/2022, 8:16 AM
    is there any recommended approach for integrating google cast whilst using jetpack compose? Getting a cast icon that manages itself in a compose world seems to be a massive pain (I think due to activity lifecycle and initial composition, but I have no idea)
  • m

    Morgane Soula

    09/21/2022, 10:06 AM
    I have something very similar in my code and data should be cast as a Request.
    j
    • 2
    • 3
  • a

    Alexandru Hadăr

    09/21/2022, 10:36 AM
    What’s the difference between
    "org.jetbrains.kotlin.android
    and
    "org.jetbrains.kotlin.jvm
    gradle plugins ?
    k
    • 2
    • 1
  • k

    krmlv

    09/21/2022, 2:26 PM
    Hi ✌️
  • a

    althaf

    09/21/2022, 4:41 PM
    Hey there, i have already asked this in the #flow its been 3 days without answer, so i'm posting it here I"m not able to use coroutine Context, in the flowOn(....), app is crashing with
    java.lang.IllegalArgumentException: Flow context cannot contain job in it. Had [SupervisorJobImpl{Active}@7b4ca1f, <http://Dispatchers.IO|Dispatchers.IO>]
    interface UseCaseScope : CoroutineScope {
        override val coroutineContext: CoroutineContext
            get() = SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>
    }
    FlowUsecase : UseCaseScope {
     <snip>
    }
    The intention here is to cancel the coroutine context when we business logic need to cancel it. So that i can call coroutineContext.cancel()
    class LoginUseCase(private val authRepository: AuthRepository) : FlowUseCase<LoginRequest, Boolean>() {
    
        override fun execute(parameter: LoginRequest): Flow<Result<Boolean>> =
            flow {
                authRepository.login(parameter.username, parameter.password).collect { response ->
                    this.defaultResultHandler(onSuccess = {
                        emit(Result.success(true))
                    }, response)
                }
            }.flowOn(coroutineContext)
    
        override fun cancel() {
            coroutineContext.cancel()
        }
    }
    ^^^ will cause app the crash
    c
    • 2
    • 4
  • m

    mkrussel

    09/22/2022, 12:15 PM
    That does not work. Here’s a link to a thread I responded to earlier that included how to do it. https://kotlinlang.slack.com/archives/C3PQML5NU/p1663688167990759
    l
    n
    m
    • 4
    • 5
Powered by Linen
Title
m

mkrussel

09/22/2022, 12:15 PM
That does not work. Here’s a link to a thread I responded to earlier that included how to do it. https://kotlinlang.slack.com/archives/C3PQML5NU/p1663688167990759
l

Landry Norris

09/22/2022, 12:55 PM
You need
implementation(files("/path/to/aar"))
m

mkrussel

09/22/2022, 1:03 PM
That will work if you are only accessing the library from an app project and not a library project.
n

Nipun Rajput

09/22/2022, 1:07 PM
THanks 🙂
m

marlonlom

09/22/2022, 8:12 PM
@Nipun Rajput i think is related to how gradle handles the dependency, if youre using local aar, try to put inside some common folder for that, using android studio wizard for that worked. https://stackoverflow.com/questions/67724242/how-to-import-aar-module-on-android-studio-4-2
n

Nipun Rajput

09/26/2022, 4:29 AM
Thank You 🙂
View count: 15