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

    Piasy

    01/29/2020, 9:41 AM
    Hi @Artyom Degtyarev [JB], I want C++ code invoke a callback that is implemented in Kotlin, and that callback need to return a string, is that possible? Currently I declare the callback in C header like this:
    typedef const char* (*PCClientOnPreferCodecs)(void*, const char*, const char*);
    And my Kotlin code implementing it is:
    private fun PCClientCallbackOnPreferCodecs(opaque: COpaquePointer?, peerUidPtr: CPointer<ByteVar>?, sdpPtr: CPointer<ByteVar>?): CPointer<ByteVar>? {
      initRuntimeIfNeeded()
      if (opaque == null) {
        return null
      }
      memScoped {
        return opaque.asStableRef<PeerConnectionClientCallback>().get().onPreferCodecs(peerUid, sdp).cstr.ptr
      }
    }
    I pass it into C++ with
    staticCFunction(::PCClientCallbackOnPreferCodecs)
    , and pass
    opaque
    with
    StableRef.create(callback).asCPointer()
    . It could be compiled and linked, but at runtime the string I get at C++ is scrambled code.
    a
    m
    • 3
    • 12
  • o

    Olenyov Kirill

    01/29/2020, 9:46 AM
    Hi, I hava another issue now with generics and obj-c. In kotlin I have a simple class with Int types:
    data class MyTestDataClass(val ppp: Int, val ttt: List<Int>)
    But in obj-c it looks like: CommonMyTestDataClass : KotlinBase - (instancetype)initWithPpp:(int32_t)ppp ttt:(NSArray<CommonInt *> *)ttt So different types: int32_t and CommonInt WTF?
    a
    • 2
    • 6
  • k

    Kris Wong

    01/29/2020, 5:13 PM
    has anyone added a cinterop (Obj-C framework) to a test executable?
    s
    d
    k
    • 4
    • 13
  • d

    dimsuz

    01/29/2020, 5:57 PM
    Hi! How to do this
    jvm {
            compilations.main.kotlinOptions { 
                jvmTarget = "1.8"
            }
        }
    for android? it works for jvm, but on android target I get:
    Could not get unknown property 'main' for KotlinJvmAndroidCompilation container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.
    during gradle sync
    k
    • 2
    • 12
  • n

    Nikky

    01/29/2020, 11:18 PM
    is there any multiplatform logging library that will actually be able to print the original location of the code in the debugger? i tried kotlin-logging but all i get is
    ConsoleOutputAppender.kt:6
    what do you use for logging inside shared code ?
    d
    • 2
    • 2
  • l

    Larten

    01/30/2020, 7:28 AM
    Hello, I split firebase dependencies into submodules in kmp project. auth, database, remoteconfig, storage are working fine, but the analytics module has something wrong. I’m using Carthage in cinterop, I checked the analytics dependency’s framework.
    language = Objective-C
    modules = FirebaseAnalytics
    compilerOpts = -framework FIRAnalyticsConnector -framework FirebaseAnalytics -framework FirebaseCore -framework FirebaseCoreDiagnostics -framework FirebaseInstallations -framework FirebaseInstanceID -framework GoogleAppMeasurement -framework GoogleDataTransport -framework GoogleDataTransportCCTSupport -framework GoogleUtilities -framework nanopb
    linkerOpts = -framework FIRAnalyticsConnector -framework FirebaseAnalytics -framework FirebaseCore -framework FirebaseCoreDiagnostics -framework FirebaseInstallations -framework FirebaseInstanceID -framework GoogleAppMeasurement -framework GoogleDataTransport -framework GoogleDataTransportCCTSupport -framework GoogleUtilities -framework nanopb
    Undefined symbols for architecture x86_64:
      "_OBJC_CLASS_$_SKPaymentQueue", referenced from:
          objc-class-ref in GoogleAppMeasurement(APMAnalytics_8b8a060bbe8023e2a8dc40576f3452ac.o)
      "_OBJC_CLASS_$_SKProductsRequest", referenced from:
          objc-class-ref in GoogleAppMeasurement(APMProductsRequest_769d88c7ff80f19356bd57d9fa02e637.o)
    ....
    ....
    I have no idea, what’s wrong. I did everything similiar as the the other modules (which are testes and working), but I can’t build this module. Actually the Studio can solve dependencies, I could use FIRAnalytics for iOS and FirebaseAnalytics for Android, but build run into error. Any idea? Can somebody add Analytics dependency to kmp project? Oh and I set firebase modules binary to 6.15.0, because 6.16.0 has something problem in every module 🙂
    a
    h
    • 3
    • 7
  • k

    Kris Wong

    01/30/2020, 2:57 PM
    woot - got artifactory working together with maven-publish. turns out to be pretty simple once you figure out how it all comes together.
    🎉 5
    k
    • 2
    • 2
  • m

    Mikołaj Karwowski

    01/30/2020, 3:25 PM
    Anybody has experience with Ktor Websockets when implementing for Android/iOs?
    s
    d
    b
    • 4
    • 3
  • m

    Mikołaj Karwowski

    01/30/2020, 3:26 PM
    I'm willing to create a HttpClient(CIO), but CIO is not found/accessible Although the package io.ktor.http.cio and CIOHeaders is well visible 😕
    k
    • 2
    • 23
  • n

    Nick Halase

    01/31/2020, 2:22 AM
    Is there something I can do to make
    fun sectionForIndex(index: Int): Section?
    not compile to
    Int32
    in my objective-c framework?
    s
    k
    b
    • 4
    • 20
  • j

    Joffrey

    01/31/2020, 2:47 PM
    Hi guys, has anyone here got some experience with Ktor websockets client in a multiplatform project? Does it work properly? Last time I checked (a few months ago) the doc was not really in sync with the artifacts, and it failed at runtime, so I wondered if things had moved since then. Any multiplatform websocket client would do, I just didn’t find anything other than Ktor so far. I’m mostly interested in JVM + JS support, but all-platform support would be a big plus.
    k
    m
    b
    • 4
    • 7
  • m

    Mikołaj Karwowski

    01/31/2020, 4:05 PM
    When using data class in iOS, it's fields are renamed to component1, component2 etc Is there a fix for that?
    b
    • 2
    • 3
  • v

    Venkat , Bangalore , India

    02/01/2020, 6:51 AM
    Hi , Need you folks valuable insights on how reliable to adopt to Multiplatform at this stage as its still in Experimental phase..
    f
    k
    • 3
    • 10
  • v

    Venkat , Bangalore , India

    02/01/2020, 6:53 AM
    is it safe to go with KMP at this point of time keeping in mind that Apple Rejection criteria in focus?
    l
    s
    k
    • 4
    • 4
  • g

    GarouDan

    02/01/2020, 4:29 PM
    I think I’ve seen this before but I don’t remember now. How can we avoid the creation of the
    commonMain
    and
    commonTest
    source sets?
    s
    • 2
    • 2
  • m

    moltendorf

    02/01/2020, 7:27 PM
    Hi all, I’ve mostly got a multiplatform library working; sans a couple of issues when I attempt to add a few things: • In the android `actual`s, I can’t seem to access android packages/classes (i.e.
    android.os.Build
    ) • When I add a second
    jvm()
    target (for the server), the library builds, but the android app is no longer able to resolve dependencies.
    r
    d
    • 3
    • 15
  • s

    SrSouza

    02/02/2020, 2:24 PM
    The main pain point of Kotlin multiplatform now for me is build libraries, like a data structure library that doesn't depend on any platform specific implementation. The current problem is publish the library because you need to compile for all platforms native platforms. I was checking the Jetbrains Kotlinx library and they use a gradle plugin called infra that does this work, but I think is an internal plugin, anyone has an idea if this infra plugin will be shared to the community or any other current alternative to do it?
    d
    • 2
    • 2
  • b

    Big Chungus

    02/02/2020, 8:09 PM
    Did anyone manage to link their MPP library published to bintray to jcenter? I've been banging my head at this for weeks now, and from the latest response from bintray support it seems impossible:
    1.) JCenter hosts open source applications using the Maven naming convention which has 3 components. For example, a valid allocated path might be: org/apache/maven
    
    2.) You can only have one JCenter path assigned to one bintray package. Since the above requires 3 components your path options are the following: 
    
    /lt/petuska/kvdom-dsl
    /lt/petuska/kvdom-dsl-js
    /lt/petuska/kvdom-dsl-metadata
    /lt/petuska/kvdom-dsl-wasm32
    Do I get this right and that essentially means there's no way to publish MPP libraries with gradle metadata to any mainstream maven repo?
    m
    • 2
    • 3
  • k

    krtko

    02/02/2020, 8:59 PM
    Hey I haven't used Kotlin MPP since they did their major redesign of the project structure and I can't seem to figure it out. I just want to add a Kotlin-only MPP module to my Android app and failing horribly. Heres the
    build.gradle.kts
    file for the new module
    plugins {
        kotlin("multiplatform")
    }
    
    kotlin {
        targets {
            targetFromPreset(presets.getByName("jvm"), "android")
        }
        sourceSets {
            commonMain {
                dependencies {
                    implementation("org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61")
                }
            }
            getByName("androidMain") {
                dependencies {
                    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61")
                }
            }
        }
    }
    Everything builds fine, but my Android module can't see the kotlin MPP one
    s
    • 2
    • 7
  • t

    Tony

    02/03/2020, 8:33 PM
    Hi, I am having troubles with getting Parcelize/Parcelable onto my MPP. My build gradle has
    kotlin {
        jvm {
            apply plugin: 'kotlin-android-extensions'
    
            ...
    
            androidExtensions {
                experimental = true
            }
        }
    }
    Can someone help me?
    k
    • 2
    • 6
  • d

    Dariusz Rusin

    02/04/2020, 10:34 AM
    Hi. I'm trying to add genercis support to iOS project. My build.gradle.kts is:
    targets {
            final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
                                  ? presets.iosArm64 : presets.iosX64
    
            fromPreset(iOSTarget, 'ios') {
                binaries {
                    framework('multiplatform-code') {
                        freeCompilerArgs.add("-Xobjc-generics")
                    }
                }
            }
    
            fromPreset(presets.jvm, 'android')
        }
    And I'm getting this error:
    Build file '/..../multiplatform-code/build.gradle' line: 40
    
    * What went wrong:
    A problem occurred evaluating root project 'multiplatform-code'.
    > Operation is not supported for read-only collection
    And line 40 is:
    freeCompilerArgs.add("-Xobjc-generics")
    I dont understand the source of the problem. What exactly "Operation is not supported for read-only collection" is mean?
    r
    s
    • 3
    • 6
  • k

    Kris Wong

    02/04/2020, 1:31 PM
    does anyone have an example repo(s) where they have setup publication for some android/iOS library modules, along w/ an umbrella framework for iOS that consumes the artifacts from the library modules?
    d
    • 2
    • 2
  • l

    louiscad

    02/04/2020, 4:19 PM
    As I'm dogfooding the next release of #splitties, I noticed the source jars are empty for some modules. It seems all modules that have common code have their sources properly put in the jar files, but all the modules that have only Android sources have no source files (only MANIFEST.MF). Did anyone experience something similar when publishing a #multiplatform library? I'm wondering what can be the cause of this issue. Maybe I found a bug?
    b
    k
    • 3
    • 13
  • k

    Kris Wong

    02/04/2020, 6:06 PM
    hmmm, moved a dependency from a compile-inline project to pulling a klib from artifactory, and now its APIs are no longer being exported correctly
    • 1
    • 4
  • j

    james

    02/05/2020, 4:56 AM
    Having an issue with the cocoapods plugin. • Have included the pod in build.gradle
    cocoapods { }
    block • Generate podspec with Gradle task •
    pod install
    in the ios project folder successfully • Try to build from Xcode but get the following error:
    > Task :someapp:cinteropSomeModuleIos
    
    `Showing All Messages
    Exception in thread "main" java.lang.Error: /var/folders/nv/hdlrvk9j2g77bsvj_npsm46r0000gn/T/tmp8525659560237793549.m:1:9: fatal error: module 'SomeModule' not found`
    I checked FRAMEWORK_SEARCH_PATHS and it includes the path to SomeModule.framework Any ideas?
    a
    f
    r
    • 4
    • 8
  • k

    Kashif

    02/05/2020, 7:26 AM
    hey all, what is best tutorial to start multiplatform? I want to implement UseCase, Repository, DataSource and Network layer in multiplatform. Is it possible? if yes then can you please share some good tutorial to start. Thanks
    k
    k
    • 3
    • 4
  • n

    Nikolay Kasyanov

    02/05/2020, 11:01 AM
    Hey folks, is this expected that importing
    import kotlin.test.Test
    is highlighted red in the IDE when the test is located in the
    commontTest
    source set? Gradle build doesn’t fail, seems like an IDE issue.
    k
    b
    • 3
    • 7
  • p

    Patrick Jackson

    02/05/2020, 1:43 PM
    Is MOKO resources https://github.com/icerockdev/moko-resources the only MP string resource solution?
    k
    • 2
    • 1
  • c

    curioustechizen

    02/05/2020, 3:37 PM
    This is a newbie question, but I'm finding some confusing and potentially out-of-date info about this: Can you separate out your source-sets into separate gradle modules while using KMP?
    k
    j
    • 3
    • 4
  • c

    curioustechizen

    02/05/2020, 3:41 PM
    My use-case: I already have a modular Android app and I want to add iOS. Here's the structure
    MyApp
      - app
      - feature1_domain
      - feature1_presentation
      - feature2_domain
      - feature2_presentation
      - and so on
    All the _`domain` modules serve the purpose of
    common
    in KMP (they have platform-agnostic code already).
    app
    , and all the
    _presentation
    modules have Android-specific code. Wondering what's the best approach to add iOS here. From what I understand, the goal is to generate a single
    .framework
    from the common code for use in iOS. I did not find any examples of this
    k
    s
    +2
    • 5
    • 13
Powered by Linen
Title
c

curioustechizen

02/05/2020, 3:41 PM
My use-case: I already have a modular Android app and I want to add iOS. Here's the structure
MyApp
  - app
  - feature1_domain
  - feature1_presentation
  - feature2_domain
  - feature2_presentation
  - and so on
All the _`domain` modules serve the purpose of
common
in KMP (they have platform-agnostic code already).
app
, and all the
_presentation
modules have Android-specific code. Wondering what's the best approach to add iOS here. From what I understand, the goal is to generate a single
.framework
from the common code for use in iOS. I did not find any examples of this
k

Kris Wong

02/05/2020, 3:49 PM
i would separate cross-platform code into modules based on function
➕ 1
and yes, you will need to pull all your iOS modules into one umbrella framework
s

Sam

02/05/2020, 3:51 PM
Something like:
MyApp //Android depends on MyAppLib
  - app
  - feature1_presentation
  - feature2_presentation
  - and so on
MyAppIOS //depends on MyAppLib.framework (umbrella framework)
MyAppLib //Android & iOS lib
  - feature1_domain
  - feature2_domain
  - and so on
c

curioustechizen

02/05/2020, 4:35 PM
I'm not sure I understand. The structure I presented is a single project with multiple gradle modules. Are you suggesting making sub-projects?
k

Kris Wong

02/05/2020, 4:36 PM
or separate repos
c

curioustechizen

02/05/2020, 4:38 PM
So there isn't a way to create a "shell" module that depends on other platform-agnostic modules and generates a .framework out of them?
k

Kris Wong

02/05/2020, 4:40 PM
yes, you can do that
c

curioustechizen

02/05/2020, 4:41 PM
Thinking out aloud, all my
_domain
modules are currently are
apply plugin: 'kotlin'
and
apply plugin: 'java-library'
I could turn them all into
apply plugin: 'org.jetbrains.kotlin.multiplatform'
Wait I'm confused now. I still don't know how the sourceSet setup works with gradle modules. Maybe I should give it a try first 😄
k

Kris Wong

02/05/2020, 4:43 PM
would probably help make it clearer
l

Larten

02/05/2020, 4:50 PM
Check this thread: https://kotlinlang.slack.com/archives/C3PQML5NU/p1579505801024300?thread_ts=1579505801.024300&amp;cid=C3PQML5NU
There is a little problem with the setup, but we found 2 workaround to fix on android. Ios works, the result 1 single framework dependency.
👍 1
k

Kurt Renzo Acosta

02/07/2020, 9:28 AM
What I did was create another module just for iOS.
Android:
- app
- feature-1
- feature-2

Shared:
- shared-feature-1 (domain and data)
- shared-feature-2 (domain and data)
- shared-ios
shared-ios
just exports the modules through
export(project(:shared-feature-1
and all other modules and you can consume it in android normally.
👍 1
View count: 6