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

    jmfayard

    10/07/2019, 9:39 AM
    Is there a non-painful way to migrate to AndroidX? I’m not sure wheteher Android Studio’s
    Migrate to AndroidX
    is broken in general or just in my project
    l
    b
    +7
    • 10
    • 15
  • k

    khairil.ushan

    10/08/2019, 6:21 AM
    I just realized that with the latest fragment-ktx updates, we can now have code like this
    class MyFragment : Fragment(R.layout.my_fragment_layout)
    . But how to initialized our binding (DataBinding) if we use this constructor approach?
    z
    • 2
    • 2
  • e

    Etinge Edward Mabian

    10/08/2019, 8:39 AM
    Hello everyone, i am new to Kotlin, can anyone point me to the best Kotlin material for me to kick off with? thanks
    v
    m
    z
    • 4
    • 5
  • m

    mingkangpan

    10/08/2019, 11:52 AM
    hey does some one know this error? if I do gradlew assemble I get this, I have databinding enabled in gradle
    > Task :myapp:kaptDebugKotlin FAILED
    e: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    a
    z
    j
    • 4
    • 8
  • p

    pawel.rybicki

    10/08/2019, 12:28 PM
    Hello guys, I wanted to use moshi to parse object to json string, the example on the lib docs says smth like this along the lines in order to achieve that:
    Moshi moshi = new Moshi.Builder().build();
    JsonAdapter<BlackjackHand> jsonAdapter = moshi.adapter(BlackjackHand.class);
    
    String json = jsonAdapter.toJson(blackjackHand);
    and I've been thinking its a bit of a boiler plate to write it for each class, so I came up with the idea of this:
    fun Any.toJson() = Moshi.Builder().build().adapter(Any::class.java).toJson(this)
    this way I can simply call
    AnyObj.toJson()
    , but I wonder if there is any downside of such solution?
    j
    • 2
    • 5
  • p

    pawel.rybicki

    10/08/2019, 1:07 PM
    have you tried turning off obfuscation first? And check if you can see events when it is disabled?
    👍 1
    s
    • 2
    • 2
  • m

    Mohamed

    10/08/2019, 4:46 PM
    Why it should not ?
    value
    is
    nullable
    r
    • 2
    • 1
  • t

    Tolriq

    10/09/2019, 7:39 AM
    Beware that things have changed recently about that and they fixed those issues only recently if you are still using Androidx 1.0 then it's probably why.
    c
    • 2
    • 2
  • j

    Jemshit Iskenderov

    10/09/2019, 12:33 PM
    Hello, does anybody knows where this "Terminate Application" icon is in new Android Studio? I want to simulate process death
    s
    z
    • 3
    • 7
  • k

    koufa

    10/09/2019, 12:35 PM
    Hello to all. I have a question about the following dependencies:
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7")
    I recently read the we should use the first one on Android as the latter ones contain it and do not provide any value on Android and the last one also has features that are not supported yet on Android ( at least for
    minSdkVersion: 21
    ) . Is that true? What are your suggestions?
    j
    • 2
    • 3
  • p

    Paul Dhaliwal

    10/09/2019, 4:15 PM
    Is there a Kotlin language feature that could reduce the verbosity of accessing views from our classes with Data Binding? According to this (https://android-review.googlesource.com/c/platform/frameworks/support/+/882241) kotlinx.android.synthetic is no longer recommended. And since I use the data binding library already I figured I’d remove all those imports and just use data binding to access the views. However I end up with a lot of calls such as
    dataBinding.featureHostBottomNavigationViewFrame.featureHostCustomerAccountPointBalance.text = someNumber
    . I don’t know too much about Kotlin yet however I’m curious if there’s some way I can simplify these calls to just
    featureHostCustomerAccountPointBalance.text = someNumber
    m
    w
    • 3
    • 7
  • s

    Shan

    10/09/2019, 9:34 PM
    Anyone know the work around for ignoring a val in a `Parcelize`d data class so I can avoid bundling it? My only thought as of right now is to make a separate data class for
    UINonBundledState
    , but I'd rather just have the annotation working. It gives me this error when trying to use it like I have in the example:
    @IgnoredOnParcel is inapplicable to properties declared in the primary constructor
    Untitled
    n
    • 2
    • 1
  • c

    capitalthree

    10/10/2019, 2:41 AM
    Can anyone help me find a working open source app that uses square's sqldelight? I'm having trouble getting it to work in my project, and I learn best by example, but the toy sample projects I've found seem outdated and don't build
    m
    l
    • 3
    • 4
  • m

    Mohamed Ibrahim

    10/10/2019, 7:47 AM
    GSearchConfig.INSTANCE.getCONFIG()
    -> how to get rid off the INSTANCE when accessing Kotlin class from Java
    m
    z
    s
    • 4
    • 5
  • t

    Tsafack Dagha cedrick

    10/10/2019, 11:01 AM
    hi, i have a little problem, i try to use a viewPager with a tabLaout to display an infinite list of data grouped by date so that the title each tab is a date (a month). I know how to use the FragmentPagerAdapter to display a limited number of fragments, but for an infinite list, I learned that we must use the FragmentStatePagerAdapter but I do not know how to use it. Can someone help me please?
    d
    z
    p
    • 4
    • 11
  • t

    Thomas Nordmeyer

    10/10/2019, 5:52 PM
    Looks like Transformations.map() does not update depending LiveData in any case. What am I doing wrong? This works
    val contract: LiveData<Contract?> = MutableLiveData()
        val authState: LiveData<AuthState?> = MutableLiveData()
        init {
            contract.observeForever { contract ->
                (authState as MutableLiveData).value = when {
                    tokenRepository.tokens.accessToken.isNullOrEmpty() -> AuthState.ANONYMOUS
                    contract != null -> AuthState.LOGGED_IN_WITH_CONTRACT
                    else -> AuthState.LOGGED_IN_WITHOUT_CONTRACT
                }.also { authState ->
                    Timber.d("Refreshing auth state to $authState after contract live data update")
                }
            }
        }
    But this doesn't
    val contract: LiveData<Contract?> = MutableLiveData()
        val authState = Transformations.map(contract)
        {
            when {
                tokenRepository.tokens.accessToken.isNullOrEmpty() -> AuthState.ANONYMOUS
                contract != null -> AuthState.LOGGED_IN_WITH_CONTRACT
                else -> AuthState.LOGGED_IN_WITHOUT_CONTRACT
            }.also { authState ->
                Timber.d("Refreshing auth state to $authState after contract live data update")
            }
        }
        init {
            contract.observeForever { Timber.d("Updated contract value to ${it?.contract}")}
        }
    I would expect the logs from the observer in init method be followed trom the Transformations observer always. But sometimes I get the init method's only (setting contract.value=null).
    w
    j
    • 3
    • 12
  • p

    Priyankkumar Patel

    10/10/2019, 5:53 PM
    is there any option in Android Studio from which, we can customize the default imports ,so we don't have to add the kotlin synthetic library again and again in every activity file.
    m
    a
    • 3
    • 11
  • m

    Mark

    10/11/2019, 6:23 AM
    I’m building an app with minSdk 23 but also have kotlin compile options set to target jvm 1.8. I see now that sdk 23 does not support jvm 1.8, so I’m left with a choice between increasing minSdk to 24 or lowering compile target to 1.6. What are the obvious drawbacks of targeting 1.6 (for a kotlin-only app)? Anything else I should be considering?
    g
    • 2
    • 7
  • h

    hetang

    10/11/2019, 6:39 AM
    java 1.8 comes with
    java.time.datetime
    Going back means either you need to build your own version of date manipulation or integrate with joda library
    👍 2
    g
    • 2
    • 2
  • s

    Sergio C.

    10/11/2019, 9:08 AM
    Which implementation should we use in gradle, jdk7 or jdk8?
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    Is there support for higher versions?
    🇳🇴 1
    w
    s
    s
    • 4
    • 4
  • p

    Pablichjenkov

    10/13/2019, 4:02 AM
    If it needs to be accessed from different Activities/Services/BroadcastRecievers I would move it to the Application object, then inject it all the way down. I like it better than making it an
    object
    .
    s
    l
    • 3
    • 10
  • c

    capitalthree

    10/13/2019, 9:15 AM
    What DSLs and whatnot do people like for doing programmatic layouts? Or do most people still like doing the xml layouts? Does anyone know how mature anko is? It hasn't had an update in a while.
    p
    • 2
    • 1
  • j

    Jonny

    10/13/2019, 1:48 PM
    I recently started testing the MVVM pattern in android and I've spent a lot of time trying to move the seekbar functionality to my viewmodel. The problem I'm having now is that I need to update more than one value when a MutableLiveData is set, and I'm getting a circular dependency problem. I'm not even sure if this is how you're supposed to do it, but I'm overriding setValue and postValue. seekBarProgress.value cannot be set because it's not initialized.
    class AddJobViewModel() : ViewModel() {
        val minPrice = 20
        val maxPrice = 1000
        val step = 10
        var description: MutableLiveData<String> = MutableLiveData("")
        var displayPrice: MutableLiveData<String> = MutableLiveData(String.format("Price: %d Kr", minPrice))
        val seekBarMax: MutableLiveData<Int> = MutableLiveData((maxPrice - minPrice) / step)
    
        var currentPrice: MutableLiveData<Int>
        var seekBarProgress: MutableLiveData<Int>
    
        init {
            currentPrice = object: MutableLiveData<Int>(minPrice) {
                override fun setValue(value: Int?) {
                    if (this.value == value) {
                        return
                    }
                    super.setValue(value)
                    displayPrice.value = String.format("Price: %d Kr", value)
                    seekBarProgress.value = value!! / step - minPrice
                }
    
                override fun postValue(value: Int?) {
                    if (this.value == value) {
                        return
                    }
                    super.postValue(value)
                    displayPrice.postValue(String.format("Price: %d Kr", value))
                    seekBarProgress.postValue(value!! / step - minPrice)
                }
            }
            seekBarProgress = object: MutableLiveData<Int>(0) {
                override fun setValue(value: Int?) {
                    if (this.value == value) {
                        return
                    }
                    super.setValue(value)
                    currentPrice.value = minPrice + value!! * step
                }
    
                override fun postValue(value: Int?) {
                    if (this.value == value) {
                        return
                    }
                    super.postValue(value)
                    currentPrice.postValue(minPrice + value!! * step)
                }
            }
    
            currentPrice.value = 200
        }
    }
    t
    • 2
    • 13
  • t

    Thomas Nordmeyer

    10/14/2019, 7:32 AM
    What is the recommended way to turn wifi on/off while running Espresso tests?
    :google: 3
    :stackoverflow: 4
    m
    • 2
    • 2
  • j

    Joan Colmenero

    10/14/2019, 10:08 AM
    Hello anyone of you have a "boilerplate" or a "skeleton" to use with a new project? that are divided by modules like
    app
    core
    core-testing
    features
    (inside different features as a modules)? I'm about to start a new project and I want to have a "guide". Thank you guys 🙂
    👀 2
    j
    • 2
    • 1
  • s

    Shan

    10/14/2019, 11:28 PM
    Anyone run into Proguard issues using Kotlinx-Serialization? Getting this error which is making me suspicious it's either an issue with Proguard or R8 (or, a serialization issue, which I don't think is actually happening)
    j.b.u: Can't locate argument-less serializer for class e.b.b.d.a (Kotlin reflection is not available). For generic classes, such as lists, please provide serializer explicitly.
    d
    p
    • 3
    • 3
  • s

    spierce7

    10/15/2019, 3:19 AM
    I thought it’d be fun to take a poll: In production one of my companies server team recently did a release where they broke the contract of an endpoint. One app immediately crashed after login with a JSON serialization exception, and another app caught the exception, ‘gracefully’ failing, showing a blank screen to the user after login. We found the issue and reverted the server changes quickly because we got alerts from crashlytics that we had a crash that an abnormal number of users experienced in a very small time frame. Use the ‘YES’ emote on this post if you think the application should crash, and use the ‘NO’ emote if you think the app should gracefully fail, with a blank screen, or perhaps a dialog or something. Feel free to explain why in the thread, or perhaps offer an alternative solution that you feel is better.
    🇳🇴 23
    :yes: 8
    y
    p
    +6
    • 9
    • 18
  • a

    Akbar

    10/15/2019, 7:04 AM
    what should I use when I need to work with background in kotlin?
    m
    m
    +2
    • 5
    • 18
  • b

    Bruno_

    10/15/2019, 12:50 PM
    anyone knows an approximate date of jetpack compose release?
    🇳🇴 2
    a
    s
    +3
    • 6
    • 9
  • j

    Joan Colmenero

    10/16/2019, 10:04 AM
    Hello guys I'm wondering if there's a "secure" way to do the Basic Authentication with retrofit, I'm about to create a
    BasicAuthenticatorInterceptor
    that implements
    Interceptor
    and then create there the Basic Authentication, the thing is I do not like to have the credentials inside the APP, how do I store the credentials to avoid someone that get the source code could do api calls? I was thinking to do an endpoint call first get the credentials from server and then store them in SP but I do not know if I have to encrypt them or what. Any other suggestions?
    :stackoverflow: 2
    g
    j
    • 3
    • 11
Powered by Linen
Title
j

Joan Colmenero

10/16/2019, 10:04 AM
Hello guys I'm wondering if there's a "secure" way to do the Basic Authentication with retrofit, I'm about to create a
BasicAuthenticatorInterceptor
that implements
Interceptor
and then create there the Basic Authentication, the thing is I do not like to have the credentials inside the APP, how do I store the credentials to avoid someone that get the source code could do api calls? I was thinking to do an endpoint call first get the credentials from server and then store them in SP but I do not know if I have to encrypt them or what. Any other suggestions?
:stackoverflow: 2
g

gildor

10/16/2019, 10:05 AM
This is not related to Kotlin
j

Joan Colmenero

10/16/2019, 10:31 AM
There's no channel #retrofit 😕
g

gildor

10/16/2019, 10:35 AM
There is no channel for such questions on this Slack, because it’s not related to Kotlin The closest one is #squarelibraries, but I believe it’s also offtopic for this channle
j

Joan Colmenero

10/16/2019, 10:37 AM
ok thanks 🙂
j

Jorge R

10/16/2019, 3:10 PM
Hi Skizo
These are the links I’ve followed to write authenticator in android
http://blog.udinic.com/2013/04/24/write-your-own-android-authenticator/
https://github.com/Udinic/AccountAuthenticator/blob/master/exampleApp/src/main/java/com/udinic/accounts_example/Main1.java
https://www.pilanites.com/android-account-manager/
http://lgvalle.xyz/2015/07/27/okhttp-authentication/
Good luck!
View count: 10