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

    Mario Ruiz

    09/16/2019, 2:38 AM
    Does anyone have a template for a kotlin multiplatform library for both Android and JVM?
    g
    • 2
    • 1
  • a

    ansman

    09/16/2019, 2:39 AM
    Is there any way to get the typealias target type when overriding a method on a specific platform:
    // Common
    expect class Input
    
    interface Foo {
      fun doStuff(input: Input)
    }
    
    // JVM
    actual typealias Input = InputStream
    
    // Use site
    object : Foo {
      // I want this type to be `InputStream` when implementing this
      override fun doStuff(input: Input) {
        ...
      }
    }
    n
    • 2
    • 16
  • k

    Konstantin Petrukhnov

    09/16/2019, 9:19 AM
    I have project 'FW' that have api dependencies 'LibA' and 'LibC'. When I build framework(cocoapods) for iOS, classes from LibA and LibC are not available top ios app. Only classes that explicitly mentioned (e.g. as return types) appears in header. How do i export all classes from api dependencies?
    a
    s
    • 3
    • 13
  • s

    SrSouza

    09/16/2019, 1:27 PM
    Hi guys, how I can create a publish artifact of a new source set created? I'm build a REST client for my backend and doing implementation in frontend(kotlin js), retrofit, ktor core(multiplatform). The ktor one I needed to create a new source set because the multiplatform plugin doesn't allow me to create a new common source set, but now I need to create an artifact for each target, but the Ktor one is not a target exactly.
    val ktorMain by creating {
        dependsOn(commonMain)
        dependencies {
            applyShared()
            implementation("io.ktor:ktor-client-core:$ktor_version")
        }
    }
    Someone can help me with that?
    • 1
    • 1
  • j

    jmfayard

    09/16/2019, 4:15 PM
    Hello, I would like to build a command-line tool with #kotlin-native (should I post there?) This would be a first time for me so any pointers would be appreciated. It would be something relatively simple and I need a command-line options parser, a way to parse JSON and do basic HTTP calls but that’s pretty much it.
    o
    g
    • 3
    • 4
  • l

    lsk

    09/16/2019, 4:48 PM
    I have a project for windows and linux. Both has cinterop mapping. I am trying to reduce code by having some kind of "native-common". Is it possible somehow? See my build gradle here https://github.com/skoky/mylaps-x2-kotlin/blob/master/build.gradle
    s
    • 2
    • 1
  • k

    Kapil Godhwani

    09/16/2019, 11:27 PM
    Hello all, I started some basic implementations on Kotlin multiplatform and started following some amazing blogs written by everyone here. I am trying to implement a basic Service Locator that relies on a lateinit var. I dont see a way to initialize this var in my iOS Code and I also dont see the var in the native compiled code. Code -
    @ThreadLocal
    object ServiceLocator {
    
        lateinit var applicationContext: ApplicationContext
    
        val CareApi by lazy { CareZoneApi(PlatformServiceLocator.httpClientEngine) }
    
        val performLogin: PerformLogin
            get() = PerformLogin(CareApi)
    
        val loginPresenter: LoginPresenter
            get() = LoginPresenter(performLogin, getUserSettings(applicationContext))
    
    }
    How do I access the
    applicationContext
    in my iOS app code to assign it a value. The ApplicationContext is my custom class. PS: Please let me know if this is also not the right place to ask this query.
    a
    r
    +3
    • 6
    • 6
  • k

    Konstantin Petrukhnov

    09/17/2019, 6:48 AM
    What is suggested way to distribute resource files in MPP library? E.g. iOS app <- fwbundle <- lib-a <- lib-b; androidApp <- lib-a <- lib-b. lib-b have file "mytext.txt" that need to be accessed from lib-a class. lib-a class is used from iOS app. In which folder mytext.txt should be created (src/commonMain/resources?)? How to ensure, that it is exported in fwbundle.framework (so it is available to code from lib-a and to code from iOS app itself)?
    g
    a
    s
    • 4
    • 14
  • j

    Jan Stoltman

    09/18/2019, 8:15 AM
    Hey guys, I'm working on multiplatform project with iOS app with K/N framework and everything worked just fine untill I've added a cinterop Keychain wrapper written in ObjectiveC. Right now I'm getting
    bitcode bundle could not be generated because (...) was built without full bitcode.
    when trying to build an archive of my app. Has anybody faced something like this before?
    s
    • 2
    • 7
  • d

    darkmoon_uk

    09/19/2019, 8:20 AM
    I need Thread-exclusive access to a Map in common code - synchronized is deprecated in K/MP and I'd rather not refactor this code to single coroutine + channel 'actor' style if it can be avoided...does anyone know a neat way to do mutual thread exclusion in K/MP? I'm writing for Android and iOS .
    a
    k
    • 3
    • 2
  • d

    darkmoon_uk

    09/19/2019, 8:23 AM
    I might just define a my own
    expect synchronized
    for now and alias it to the JVM implementation for Android, for iOS just pass through in the knowledge that its coroutines are single threaded anyway.
    t
    k
    • 3
    • 3
  • a

    adam-mcneilly

    09/19/2019, 6:09 PM
    Hi! I just walked through this hands on example, which was super helpful. Thanks to whoever wrote this:
    <https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction>
    I noticed that in this example we create a SharedCode module right inside the same folder as the Android app. Is this approach common, or is it normal to have your shared code as its own project that could be kept in its own git repository? If I do that, I'm not sure how difficult it becomes to link it to my Android app since it's no longer as simple as
    implementation project(':SharedCode')
    . Just curious what others have done about this.
    k
    a
    +6
    • 9
    • 36
  • l

    louiscad

    09/20/2019, 7:45 AM
    Is the
    androidMain
    sourceSet associated with any compilation?
    d
    k
    • 3
    • 3
  • k

    Klara Erlebachova

    09/20/2019, 9:26 AM
    Hi, I am developing my first MPP project. I am wondering if it is possible to make Android studio on Linux understand platform specific imports e.g.
    import platform.UIKit.UIDevice
    . On Mac it's working just fine but on Linux I am getting
    Unresolved reference: platform
    . It would be helpful to have syntax highlighting working also on Linux which is my primary platform. Any suggestions?
    r
    a
    k
    • 4
    • 5
  • f

    Fail

    09/20/2019, 3:13 PM
    Hi All! How to use kapt in multiplatform? I apply kap plugin and use kapt 'com.github.bumptech.glide:compiler:4.9.0' in androidMain section. but have an error Gradle DSL method not found: 'kapt()'
    k
    j
    +2
    • 5
    • 10
  • l

    Laura de la rosa

    09/20/2019, 8:42 PM
    Hi!! All Someone has coded location delegates in iosMain (the common part in Kotlin). I need to know if any type of delegates can be implemented in iosMain or the development must be in swift (because if that cannot be done, how scalable is KM?). Something like this https://discuss.kotlinlang.org/t/swift-delegate-cllocationmanagerdelegateprotocol/14320/5
    s
    • 2
    • 1
  • d

    darkmoon_uk

    09/21/2019, 3:56 AM
    I don't seem to be able to register two different, named Android targets in Kotlin/MP e.g.
    kotlin {
        android("standardAndroid") { ... }
        android("specialAndroid") { ... }
    }
    Get:
    Cannot add extension with name 'kotlinOptions', as there is an extension already registered with that name.
    ...is this expected?
    r
    • 2
    • 1
  • m

    Miguel Fermin

    09/21/2019, 5:57 PM
    Hi all, I just followed this tutorial - https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction I got it to work, but now I want to be able to use android packages inside my
    androidMain
    . ideas?
    l
    a
    • 3
    • 4
  • k

    Konstantin Petrukhnov

    09/23/2019, 7:46 AM
    After upgrading project from 1.3.31 (Konan, lipo linking) to 1.3.50 (MPP, fatframework task), tests stop working with error:
    *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Only one Kotlin framework can be loaded currently'
    *** First throw call stack:
    Any suggestion how to fix it? App runs fine, only tests are failing. And tests were working before without any problem.
    o
    k
    a
    • 4
    • 14
  • n

    Nikita Klimenko

    09/23/2019, 1:22 PM
    Hi, trying to build kotlin multiplatform project with version 1.3.60-dev-2303 and getting this error during the IOS build.
    > Task :linkMyLibReleaseFrameworkIos
    e: Compilation failed: Lowering DCEPhase: phases [Devirtualization] are required, but not satisfied
    I'm using these options
    freeCompilerArgs += "-Xdisable-phases=Devirtualization,BuildDFG"
    o
    • 2
    • 6
  • b

    Bino

    09/23/2019, 1:45 PM
    I’m trying to build a mac application with kotlin/native but I didn’t get an executable as result. Can someone point me to the configuration mistake I made please? https://gist.github.com/thebino/5d0b2992dc0ee1e65eca2a3b46de4f70
    a
    • 2
    • 4
  • m

    Miguel Fermin

    09/23/2019, 9:34 PM
    Hi all - The following check always fails for me, causing the
    iostarget
    to be set to
    iosX64
    .
    val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
            if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
                ::iosArm64
            else
                ::iosX64
    a
    c
    • 3
    • 5
  • b

    Big Chungus

    09/24/2019, 5:55 AM
    How would I add an extra common target/module/sourceSet?
    r
    k
    • 3
    • 2
  • a

    ansman

    09/25/2019, 1:37 PM
    After publishing my MPP library to Artifactory I get this error when building:
    Unable to find a matching variant of …
    The reason is that I introduced an additional build type in my project which of course doesn’t have a matching one in the MPP project. This doesn’t happen with other MPP projects. Is it because I’ve published both the
    debug
    and
    release
    types of my MPP library?
    r
    • 2
    • 9
  • a

    adam-mcneilly

    09/25/2019, 3:21 PM
    Is there a way to have something in the common folder that has default arguments, and just be called from iOS with a default constructor? When I try this, Xcode keeps telling me
    init()
    not allowed, and I need to add all params. So far the only work around I have is using a secondary constructor like this. It's not the worst thing but it feels kind of unnecessary:
    class MyClass(
    	private val paramOne: Int = 5,
    	private val paramTwo: Int = 10
    ) {
    	constructor() : this(5, 10)
    }
    k
    s
    r
    • 4
    • 7
  • k

    Kris Wong

    09/25/2019, 6:02 PM
    it looks like the
    iosTest
    gradle task, as created by the project template, doesn't have a results file?
    • 1
    • 1
  • p

    Patrick Jackson

    09/25/2019, 6:31 PM
    Anyone having trouble with common tests finding references from
    commonMain
    ? Running into this in a new project with nearly identical setup & build.gradle
    • 1
    • 3
  • l

    Lou Morda

    09/25/2019, 7:21 PM
    Anybody sharing ViewModel code between iOS and Android? I'd like to have the ViewModels be shared code, but it looks like the downside is that a custom ViewModel in the shared code would not be tied to the Android lifecycle like in the jetpack libraries. Has anyone come across this design decision and could offer advice? Thanks!
    k
    e
    +2
    • 5
    • 6
  • j

    Justin

    09/25/2019, 7:41 PM
    https://kotlinlang.slack.com/archives/C3SGXARS6/p1569440188115700
    b
    • 2
    • 5
  • s

    spierce7

    09/25/2019, 9:54 PM
    It appears that using the multiplatform plugin to publish a maven release with an Android target doesn’t release the Android library. Does anyone have a good example of how to do this along side multiplatform?
    k
    a
    l
    • 4
    • 16
Powered by Linen
Title
s

spierce7

09/25/2019, 9:54 PM
It appears that using the multiplatform plugin to publish a maven release with an Android target doesn’t release the Android library. Does anyone have a good example of how to do this along side multiplatform?
k

Kris Wong

09/25/2019, 9:59 PM
https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#publishing-android-libraries
s

spierce7

09/25/2019, 10:05 PM
wow. you are amazing. Thank you.
This is odd:
> Failed to notify project evaluation listener.
   > Kotlin target 'android' tried to set up publishing for Android build variants that are not library variants or do not exist:
     * release
     Check the 'publishLibraryVariants' property, it should point to existing Android library variants. Publishing of application and test variants is not supported.
   > Kotlin target 'android' tried to set up publishing for Android build variants that are not library variants or do not exist:
     * release
     Check the 'publishLibraryVariants' property, it should point to existing Android library variants. Publishing of application and test variants is not supported
the release variant does exist though, and it’s an android library
a

adam-mcneilly

09/26/2019, 4:26 AM
omg I was having this problem ALL day! I was going to post the lib I was testing to GitHub and see if anyone here had any clues. Were you able to get this to work, Scott?
s

spierce7

09/26/2019, 4:40 AM
yes I was
Currently using
kotlin {
  android {
    publishAllLibraryVariants()
  }
it’s releasing / uploading it. I’m currently having an issue though that it can’t be resolved. trying to work that out now.
interesting. switching to android studio fixes that. Now it can be resolved
a

adam-mcneilly

09/26/2019, 4:58 AM
Switching what to Android Studio? Opening the MPP?
s

spierce7

09/26/2019, 4:59 AM
it temporarily resolved it then I started seeing the issue again
I just fixed it though by importing the library into the common source only
importing the android target libs explicitly was causing errors, but just importing the common library through the common source set seems to work just fine, and it automagically pulls in the android targets
l

louiscad

09/26/2019, 5:42 AM
The docs talk about an option to group the variants by flavor. Using it should help and no longer require you to add the common dependency.
s

spierce7

09/26/2019, 5:55 AM
I’m not sure I understand how that helps. I don’t have any flavors for the library. Also - currently I’m ONLY adding the common dependency and it automatically imports the targets, is that not how it’s supposed to work?
l

louiscad

09/26/2019, 7:10 AM
@spierce7 Then you have default flavor, and debug and release variants would be grouped in the same artifact
View count: 2