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
multiplatform
  • k

    Kris Wong

    01/02/2020, 3:09 PM
    has anyone figured out a way to make resource files available when running iOS tests (on the sim)?
    • 1
    • 3
  • t

    Tristan

    01/02/2020, 3:53 PM
    Hello, I read it will be possible to use Jetpack Compose outside of android (community effort though), and I was wondering if it would be possible to do so with any other jetpack library (room, livedata, for instance)
    m
    f
    k
    • 4
    • 4
  • k

    Kris Wong

    01/02/2020, 5:46 PM
    is there anything similar to
    BuildConfig
    for Android? I haven't seen anything.
    r
    k
    • 3
    • 3
  • k

    Kris Wong

    01/02/2020, 5:53 PM
    it looks like expect/actual are not resolved properly by IDEA for
    commonTest
    , even though they are for
    commonMain
    . it doesn't handle source set dependencies properly.
    r
    • 2
    • 3
  • k

    kzotin

    01/02/2020, 6:38 PM
    Hi all, I wonder if anyone has hands-on experience with
    Flow
    in MPP/KN modules? Got any tips & tricks? I'm trying to expose shared repository layer for iOS/Android, and considering which
    Observable
    implementation to expose. Would really like to avoid
    Reaktive
    , having already coroutines and RxJava in the project... Thanks in advance!
    a
    k
    • 3
    • 3
  • d

    dambakk

    01/03/2020, 8:16 AM
    Good morning, folks! Now and then, when including a new library in my MP project, I get an
    unresolved reference
    error when trying to import the dependencies. Android Studio says everything is fine, and I can even inspect the source by cmd+clicking, but when building the project the errors starts appearing. Now it’s Kissme I’m trying to import. I’ve put the
    implementation
    in all source sets (including test, just in case) with the corresponding suffix. I don’t know what else to do. Any suggestions?
    • 1
    • 1
  • m

    mzgreen

    01/03/2020, 9:54 AM
    I’m trying to create a custom iOS
    UIView
    and override this function: https://developer.apple.com/documentation/uikit/uiview/1622529-draw but I don’t see it in Kotlin, what may be the reason?
    k
    • 2
    • 3
  • b

    Big Chungus

    01/03/2020, 10:44 AM
    Is there a way to obtain platformName in code without manually declaring
    expect val platform:String
    ?
    m
    d
    a
    • 4
    • 5
  • c

    Cristián Arenas

    01/03/2020, 2:00 PM
    Happy New Year! After updating Kotlin to 1.3.61, I have the a problem with iOS. I get
    unresolved reference: platform
    on Android Studio in my
    iosMain
    files, unless I add this:
    iosX64Main {
        …
        kotlin.srcDirs += project.file("src/iosMain/kotlin")
    }
    iosArm64Main {
        …
        kotlin.srcDirs += project.file("src/iosMain/kotlin")
    }
    (I can generate the library though, so it seems the problem is with Android Studio) But if I add that, then it starts expecting new actuals:
    expected class 'X' has no actual declaration in module my-app_iosX64Main for Native
    k
    e
    k
    • 4
    • 42
  • s

    Samuel Michael

    01/03/2020, 4:46 PM
    what do i need to change this to?
    c
    • 2
    • 5
  • h

    Hannes

    01/03/2020, 6:45 PM
    Hey folks, I'm struggeling a bit with kotlin mutliplatform and
    commonTest
    . In my
    build.gradle
    i have the following config:
    kotlin {
      ... 
      sourceSets {
         ...
           commonTest {
                dependencies {
                    implementation 'org.jetbrains.kotlin:kotlin-test-common'
                    implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
                }
            }
       }
    }
    However, if I run a test in
    src/commonTest/kotlin/my/package/FooTest.kt
    which looks like this
    import kotlin.test.Test
    import kotlin.test.assertEquals
    
    class FooTest {
        @Test
        fun filterState(){
            assertEquals(1, 2)
        }
    }
    I get
    Unresolved reference: Test
    e: ... /src/commonTest/kotlin/my/package/FooTest.kt: (3, 20): Unresolved reference: Test
    e: ... /src/commonTest/kotlin/my/package/FooTest.kt: (4, 20): Unresolved reference: assertEquals
    Any idea what I have misconfigured?
    g
    k
    • 3
    • 20
  • r

    René

    01/04/2020, 3:03 PM
    Hey guys, I observed for at least 6 month a strange behavior which I cannot fix. When I compile my mpp project from the cli it works fine, as expected. When I run the same gradle task from intellij I get tons of "Actual class foo has not corespondending expected declaration". If someone has some time to check it here is my repo: https://github.com/rewe-digital-incubator/Konversation/tree/feature/provisioning (that feature branch should have also all the latest versions of the dependencies) tbh I didn't care yet for this bug since I was able to compile my project, but this breaks debugging and running tests which is very annoying
    d
    • 2
    • 4
  • n

    Nick Halase

    01/04/2020, 7:47 PM
    What should I set
    core.symlinks
    to for my project if I have symbolic linked iosX86 and iosArm to a common directory? I assume I want
    false
    to maintain compatibility with Windows collaborators?
    e
    • 2
    • 1
  • b

    Brendan Weinstein

    01/05/2020, 5:37 AM
    Just trying out appcode for the first time and it is cool that it generates a .swift version of the generated objectivec. When I rebuild the framework this .swift file does not get regenerated. Is there anything I can do to regenerate the .swift file. I discovered it by cmd+b'ing into the generated objc classes.
    d
    s
    • 3
    • 3
  • a

    addamsson

    01/05/2020, 7:51 PM
    Hi guys! Is there something like a
    WeakReference
    in Kotlin MPP? I have a custom
    EventBus
    implementation which returns
    Subscription
    objects whenever the user subscribes to an event. My problem is that it is easy to forget to call
    Subscription.unsubscribe
    and there can be memory leaks when the subscriber drops the reference to the
    Subscription
    but the
    EventBus
    retains it forever. Is there a best practice for this scenario in the context of MPP?
    s
    • 2
    • 14
  • b

    Brendan Weinstein

    01/06/2020, 6:16 AM
    One selling point for winning over product managers on multiplatform is a far higher probability of consistent analytic events cross platform. Imagine a ViewController/Activity that has a
    fun render(state: ViewState)
    and observes
    ViewState
    's emitted by a StateMachine. The StateMachine is shared in the common module. If the analytics events are fired in the StateMachine, then the developer who implements the View would have to avoid using the shared StateMachine or use it in a way that breaks functionality in order to make analytics events inconsistent, which is a loose coupling and better than no coupling.
    👍 3
    c
    • 2
    • 1
  • v

    vanniktech

    01/06/2020, 10:32 PM
    Has anyone tried out getting a websocket working on iOS? Seems like ktor does not support it directly, but one could use their
    Engine
    API to bake Starscream or any other third party library into it
    f
    • 2
    • 6
  • j

    Joey

    01/08/2020, 1:51 AM
    Hi guys, our company uses bitbucket. Is it possible to upload a library from bitbucket to jitpack? I've heard that bitbucket doesn't support
    release
    features like the ones on github.
    k
    • 2
    • 6
  • t

    tylerwilson

    01/08/2020, 2:57 AM
    I am surprised I had not noticed this before, but I needed a String.format in common code (%.2d for example), and turns out it is only on JVM. Seems like some low hanging fruit. 🙂 Maybe for 1.4?
    j
    m
    • 3
    • 11
  • b

    Big Chungus

    01/08/2020, 12:26 PM
    How can I create a commonNative sourceSet (or better yet, target) with access to native stdlib and depend on it from linux and mingw targets?
    d
    k
    • 3
    • 5
  • k

    Kris Wong

    01/08/2020, 5:41 PM
    has anyone setup an MPP to build a fat jar? or configured the java/shadow plugins?
    d
    • 2
    • 8
  • g

    Gin Wang

    01/08/2020, 7:58 PM
    Hello, is there a preferred way to do url encoding on KMP? kTor seems to be the only option I've found so far
    s
    • 2
    • 2
  • a

    agta1991

    01/09/2020, 11:47 AM
    Hi guys, I have a multimodule multiplatform project which is imported into plain android project.The project can see it's interfaces and transitive dependecies, but cannot resolve the interface's return types which are from the transitive dependencies. The dependencies are declared as api(...) in the imported module. Is there anyone, who faced similar issues?
    • 1
    • 1
  • p

    Piasy

    01/09/2020, 11:52 AM
    Hello Guys, I want to build my KMPP iOS sources into an iOS static library, and my iOS kotlin code uses some ObjC classes from another iOS framework, which are accessed using cinterop. When my ObjC app code (
    ViewController.m
    ) calls iOS kotlin function (
    KmppBootstrap.test
    , built to iOS static library), which accept an ObjC object (
    IOSDummyObj
    from
    IOSDummyFramework.framework
    ), if
    KmppBootstrap.test
    use
    IOSDummyObj
    , my app will crash at
    Kotlin_Interop_refToObjC
    with
    EXC_BAD_ACCESS (code=1, address=0x1a102ba0120)
    , but if
    KmppBootstrap.test
    don't, my app runs fine. Could you guys please help me, thanks! I upload my repro project onto GitHub, in the
    ios_static_lib_repro
    branch of https://github.com/Piasy/KmppBootstrap , my iOS kotlin code is mainly
    kmpp/src/iosMain/kotlin/com/piasy/kmpp/KmppBootstrap.kt
    , and iOS app is under
    iOSExample2/iOSExample2/ViewController.m
    . Or maybe my app code is wrong?
    IOSDummyObj* obj = [[IOSDummyObj alloc] initWithInt:42];
    
        libkmpp_ExportedSymbols* lib = libkmpp_symbols();
    
        libkmpp_kref_com_piasy_kmpp_KmppBootstrap kmpp = lib-><http://kotlin.root.com|kotlin.root.com>.piasy.kmpp.KmppBootstrap.KmppBootstrap();
    
        libkmpp_kref_Dummy_IOSDummyObj dummy;
        dummy.pinned = (__bridge libkmpp_KNativePtr)(obj);
        lib-><http://kotlin.root.com|kotlin.root.com>.piasy.kmpp.KmppBootstrap.test(kmpp, dummy);
    a
    • 2
    • 14
  • s

    Sylvain Patenaude

    01/09/2020, 6:23 PM
    Anyone who would have a simple example (or link to it) of a React Native app calling a Kotlin Multiplatform library? Looking on the web for it, but haven't found exactly what I'm looking for yet. (NOTE: I'm just starting with React Native, I don't have any experience.) EDIT: I have 2 libraries (.jar for Android, .framework for iOS).
    s
    • 2
    • 1
  • v

    vanniktech

    01/10/2020, 5:42 PM
    Using ktor on iOS with
    io.ktor:ktor-client-core-native
    and I’m getting this:
    CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
        class = inet;
        "m_Limit" = "m_LimitAll";
        ptcl = htps;
        "r_Attributes" = 1;
        sdmn = "oauth2/client";
        srvr = "<http://myserver.app|myserver.app>";
        sync = syna;
    }
    Does anyone know what could be the issue?
    s
    • 2
    • 2
  • m

    mzgreen

    01/11/2020, 12:52 PM
    I have a project with following structure:
    common
      - commonMain (contains expect classes)
      - jvmMain (contains actual classes for jvm)
      - jsMain (contains actual classes for js)
    jvm (contains a jvm project and depends on common)
     - JVMMainClass
    js (contains a js project and depends on common)
     - JSMainClass
    the jvm works fine but I have a problem with js module.
    JSMainClass
    sees classes from common module but the implementations are from jvmMain instead of jsMain. How do I fix that?
    d
    • 2
    • 6
  • s

    Shan

    01/12/2020, 1:28 AM
    How would I specify a different name for
    commonMain
    in a mpp gradle file?
    b
    • 2
    • 7
  • s

    Shan

    01/12/2020, 3:11 AM
    Trying to get a set up that looks like this:
    jvmCore
      |_ main
           |_ kotlin
      |_ test
           |_ kotlin
    instead of
    jvmCoreMain
      |_ kotlin
    jvmCoreTest
      |_ kotlin
    But can't quite figure out how to configure my sourceSets properly. I have it set up like this:
    sourceSets {
        jvm().compilations {
            val core by creating {
                defaultSourceSet {
                    dependencies { //etc }
                }
            }
            val coreTest by creating {
                defaultSourceSet {
                    dependencies { //etc }
                }
            }
        }
    }
    Is it possible to set it up more like..
    sourceSets {
        jvm().compilations {
            val core by creating {
                sourceSet("main") {
                    dependencies {}
                }
                sourceSet("test") {
                    dependencies {}
                }
            }
        }
    }
    ?
    d
    • 2
    • 5
  • s

    Shan

    01/12/2020, 8:22 AM
    If I have a multi-module program, and one of the project is kotlin multiplatform and the other is not, is there a way to get it to depend on the multiplatform module in the dependencies block? e.g.-
    //project: android-local
    
    //android config omitted
    
    dependencies {
        api(project(":android-remote"))
    }
    and then I have a mpp (in the same repo, different module)
    //project: android-remote
    
    kotlin {
        jvm()
        sourceSets {
            val commonMain by getting {
                dependencies {
                    implementation("core-lib") //an example
                }
            }
    
            val jvmMain by getting {
                //depends on commonMain by default
            }
        } 
    }
    using
    api(project(":android-remote"))
    does not add anything from
    android-remote
    to the dependencies of
    android-local
    . Is there some way I need to specify the target it since
    android-remote
    is a MPP? Or is this not possible?
    u
    s
    • 3
    • 11
Powered by Linen
Title
s

Shan

01/12/2020, 8:22 AM
If I have a multi-module program, and one of the project is kotlin multiplatform and the other is not, is there a way to get it to depend on the multiplatform module in the dependencies block? e.g.-
//project: android-local

//android config omitted

dependencies {
    api(project(":android-remote"))
}
and then I have a mpp (in the same repo, different module)
//project: android-remote

kotlin {
    jvm()
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("core-lib") //an example
            }
        }

        val jvmMain by getting {
            //depends on commonMain by default
        }
    } 
}
using
api(project(":android-remote"))
does not add anything from
android-remote
to the dependencies of
android-local
. Is there some way I need to specify the target it since
android-remote
is a MPP? Or is this not possible?
u

Ugi

01/12/2020, 1:11 PM
Do you have
enableFeaturePreview("GRADLE_METADATA")
In your project
settings.gradle
s

Shan

01/13/2020, 9:22 PM
I do!
u

Ugi

01/14/2020, 11:25 PM
Huh, it should work then but it could be a bunch of different reasons why it doesn't. I have a working sample android project that imports the mp module from the same project here https://github.com/ionspin/kotlin-multiplatform-bignum/blob/android/android-usage-sample/build.gradle.kts you just need to replace
implementation("com.ionspin.kotlin:bignum:0.1.5")
with
implementation(project(":bignum"))
. Maybe you'll spot some differences there that could help you.
s

Shan

01/19/2020, 2:03 AM
Still can't get this to compile 😞 Thank you for the example, but it seems to break if I use a MPP local dependency rather than a hosted one. Looking for any other suggestions if anyone has any
s

sikri

01/19/2020, 8:45 AM
Try to close project, delete all .iml files, .idea, .build, .gradle, and re-import project in the end
I couldn’t make jvm module to see non-android jvm module (I got both android() and jvm() source targets) and it didn’t work until full reimport of the project
s

Shan

01/19/2020, 8:51 AM
I have reimported twice already unfortunately. No dice.
s

sikri

01/19/2020, 8:54 AM
hm, you can do this as workaround: to android-local (nonmpp!) add mpp plugin for example, this is mine:
plugins {
    id("com.android.application")
    kotlin("multiplatform")
    kotlin("android.extensions")
    kotlin("kapt")
    id("kotlinx-serialization")
}
after
android { ... }
put
kotlin {
    android()
}
The only problem is with
kapt
, as for now I have to write
"kapt"(someDep)
instead of
kapt(someDep)
s

Shan

01/19/2020, 10:16 PM
I found the solution! You need to specify for it to use the proper configuration. I was trying
jvmMainApi
and
jvmCompile
and all sorts of variations of configs that are supplied by the multiplatform plugin, but the one I needed was
jvmDefault
.
api(project(":android-remote","jvmDefault"))
It now sees `android-remote`'s dependencies correctly!
🎉 3
The only issue is that it doesn't include sources, so that's a bit annoying. Will have to figure out how to do that as well..
I actually refactored this a bit by using @sikri’s solution and the
jvmDefault
configuration in order to get the project sources to point to the correct project instead of the sources jar. I added the multiplatform plugin to my android library and used the
android()
setup as specified above, but used
jvmDefault
as the configuration for the project as I didn't want a specific android target on my
android-remote
mpp. Everything works great now!
View count: 6