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

    rsetkus

    11/01/2020, 7:39 PM
    Hi. When new multiplatform project is created (Linux machine),
    iosMain
    platform target is set to Multiplatform (screenshot bellow). That causes issues on Mac machine.
    iosMain
    cannot access platform code and have to duplicate code in
    iosArm64Main
    and
    iosX64Main
    . What platform target should be selected for
    iosMain
    on which
    iosArm64
    and
    iosX64
    depends on? Also, noticed that on Android Studio, using new KMM plugin,
    iosMain
    platform is set to multiple values Native(ios_arm64), Native(ios_x64). Is it possible to achieve the same on Intellij (platform target is single selection field)?
    b
    • 2
    • 13
  • n

    Nikita Khlebushkin

    11/02/2020, 6:46 AM
    Hello! We’re deciding how do we want to include the shared KMM library into iOS (and Android, but it’s waaaay easier to decide). As I can see it, we can have three ways: 1. Deliver it as raw Kotlin code and have it as a separate Kotlin module in iOS and Android. Cons: adds compile time to the projects; requires the environment to have Kotlin in setup; in some cases requires minor alterations in client (I had to add Maven repo to a sample Android app in the new repo, but probably I’m just missing something) 2. Deliver via private Cocoapods repo (or private Maven for Android). Cons: we need to wait for the library to build before using it every time, similar approach for another project on our CI/CD takes 30 minutes; we need to create a new version number each time we push something into the Cocoapods repo 3. Deliver it as a pre-built (on CI/CD step) classes into submodules, which are then plugged into the projects. Cons: still not built immediately, can only be used after CI/CD is done What are the best practices here? How people usually use KMM without adding dependencies to developers’ environments and without long waits?
    👍 2
    m
    • 2
    • 2
  • n

    Nikky

    11/02/2020, 6:59 PM
    is there any tips and tricks for adding sources to multiplatform libs published to maven? i am using
    maven-publish
    to
    mavenLocal()
    but when using the library from a jvm project
    libname-jvm
    and navigate to definition idea is unable to attach sources it seems
    l
    d
    • 3
    • 7
  • j

    jeran

    11/02/2020, 8:22 PM
    hi all, happy monday! I'm attempting to use cocoapod dependencies in the shared module of a kotlin multiplatform mobile project and failing miserably. Full details in thread:
    • 1
    • 1
  • z

    zalewski.se

    11/03/2020, 7:33 AM
    Is there any plan to add support for different constructor per platform with `expect`/`actual` mechanism? For example with Android and iOS, usually for Android there is a need to pass a context while for iOS there is no such thing. Currently I’m playing around with some
    setup()
    functions that initialize my object and I hide the real constructor from the client. This approach seems far from perfect though 🤔
    g
    m
    r
    • 4
    • 11
  • v

    Vinod Rai

    11/03/2020, 10:41 AM
    Hey! have anyone faced this issue?
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':SharedCode:compileKotlinIos'.
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:205)
    	at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:203)
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:184)
    	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    	at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    	at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    	at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    Caused by: org.jetbrains.kotlin.backend.konan.KonanCompilationException: Compilation finished with errors
    	at org.jetbrains.kotlin.cli.bc.K2Native$Companion$mainNoExitWithGradleRenderer$1.invoke(K2Native.kt:277)
    	at org.jetbrains.kotlin.cli.bc.K2Native$Companion$mainNoExitWithGradleRenderer$1.invoke(K2Native.kt:260)
    w
    • 2
    • 1
  • w

    william

    11/03/2020, 1:27 PM
    i am passing lambdas to some native libraries (iOS) - do I need to freeze the lambda before passing it on? how would you mutate a lambda anyway? would calling it be considered mutation?
    s
    • 2
    • 3
  • c

    christophsturm

    11/03/2020, 2:17 PM
    i have a kotlin multiplatform project that uses a kotlin-jvm project via gradle composite build. and i cannot run it:
    ```15:14:37: Executing task 'FetcherKt.main()'...
    
    > Task :r2dbcfun:buildSrc:compileKotlin UP-TO-DATE
    > Task :r2dbcfun:buildSrc:compileJava NO-SOURCE
    > Task :r2dbcfun:buildSrc:compileGroovy NO-SOURCE
    > Task :r2dbcfun:buildSrc:pluginDescriptors UP-TO-DATE
    > Task :r2dbcfun:buildSrc:processResources NO-SOURCE
    > Task :r2dbcfun:buildSrc:classes UP-TO-DATE
    > Task :r2dbcfun:buildSrc:inspectClassesForKotlinIC UP-TO-DATE
    > Task :r2dbcfun:buildSrc:jar UP-TO-DATE
    > Task :r2dbcfun:buildSrc:assemble UP-TO-DATE
    > Task :r2dbcfun:buildSrc:compileTestKotlin NO-SOURCE
    > Task :r2dbcfun:buildSrc:pluginUnderTestMetadata UP-TO-DATE
    > Task :r2dbcfun:buildSrc:compileTestJava NO-SOURCE
    > Task :r2dbcfun:buildSrc:compileTestGroovy NO-SOURCE
    > Task :r2dbcfun:buildSrc:processTestResources NO-SOURCE
    > Task :r2dbcfun:buildSrc:testClasses UP-TO-DATE
    > Task :r2dbcfun:buildSrc:test NO-SOURCE
    > Task :r2dbcfun:buildSrc:validatePlugins UP-TO-DATE
    > Task :r2dbcfun:buildSrc:check UP-TO-DATE
    > Task :r2dbcfun:buildSrc:build UP-TO-DATE
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Initialization script '/private/var/folders/99/084s2g6s4pbgwr4_46ysxms80000gn/T/FetcherKt_main__.gradle' line: 27
    
    * What went wrong:
    A problem occurred configuring project ':r2dbcfun'.
    > Could not create task ':r2dbcfun:FetcherKt.main()'.
       > SourceSet with name 'jvmMain' not found.
    • 1
    • 2
  • c

    christophsturm

    11/03/2020, 3:00 PM
    can i split a multiplatform project into multiple gradle subprojects, and have the jvm main be just a normal kotlin project that consumes the jvm build of the common module?
    a
    j
    • 3
    • 5
  • j

    jeran

    11/03/2020, 6:43 PM
    let me give this another shot. has anyone successfully managed to get external cocoapod dependencies working in a kotlin multiplatform project? i feel like i've followed the guide to a t with no luck. https://kotlinlang.slack.com/archives/C3PQML5NU/p1604348567259000
    t
    • 2
    • 13
  • f

    Fanis Paschos

    11/03/2020, 10:15 PM
    Hello everyone, I am really sorry for the ‘simple’ question, but I am quite new to KMM. I have one KMM App (like general utils library for both Android & iOS apps that I have) from Plugin in Android Studio. — How do I build both .jar & .framework to transfer them to my main project and where do they get saved? Thanks guys 🙂
    k
    • 2
    • 56
  • a

    Ali Kabiri

    11/04/2020, 8:10 AM
    Hi everyone 🙂 when using the Ktor client for authentication, is it possible to decode the JWT token payload in the common module (using pure Kotlin)*?*
    m
    e
    m
    • 4
    • 6
  • t

    Tomasz Krakowiak

    11/04/2020, 11:17 AM
    Hello, I frequently have a problem that in MPP directory src/jvmMain/kotlin is not being recognized as source folder by IntelliJ. When inspecting Project structure I can see that src/jvmMain is being source root of 2 modules: main and jvmMain. Anyone knows a solution / workaround?
    a
    • 2
    • 5
  • p

    phisch

    11/04/2020, 1:17 PM
    what's the best practice to write tests in a multiplatform 1.4.10 project? i am new to kotlin and gradle and fail to get testing setup
    • 1
    • 1
  • a

    Azur Haljeta

    11/04/2020, 9:05 PM
    Hello, why it isn't possible to use the multiplatform plugin with
    apply (plugin = ...)
    but it is within the
    plugins { }
    block?
    j
    g
    l
    • 4
    • 32
  • w

    why

    11/05/2020, 8:07 AM
    hello.. when I try using Int.countOneBits() in commonMain project I get this error: Task :y-collections:compileKotlinJvm FAILED, Unresolved reference: countOneBits. It’s weird because the function is there in NumbersJVM.kt, it delegates to the JVM function Integer.bitCount(this), any idea?
    • 1
    • 1
  • d

    darkmoon_uk

    11/05/2020, 11:01 AM
    Kotlin Intensifies
    :kotlin-intensifies: 23
    😂 4
    a
    a
    • 3
    • 2
  • e

    Elka

    11/06/2020, 1:34 PM
    Hello, Using the Ktor HttpClient on Android and iOS.  I need to do some kind of json validation for authorization purposes… I am trying to create a 
    Feature
     that parses the json, does the checking and then proceed with the response… The problem is that I cannot call 
    readBytes
     twice. The second time it’s empty as the response has already been consumed when doing the validation. Is there any way to do it
    r
    • 2
    • 4
  • a

    Arkadii Ivanov

    11/06/2020, 2:24 PM
    I'm using the "packForXcode" Gradle task to build my shared library as a Framework. This works fine from Xcode when the Framework is not built yet or I don't change the build target in Xcode. But once I already have the Framework build for e.g. "iOS" and I switch to "iOS Simulator", build fails. It fails before even executing the script from Build Phases (it is put on the second position from top). Is there any solution for this? Currently I can only manually delete the Framework folder before building.
    ➕ 4
    :youtrack: 2
    d
    t
    n
    • 4
    • 15
  • j

    Jozef Matus

    11/08/2020, 1:46 PM
    Hi guys, sorry for stupid question. I’ve seen multiple usages of
    NSString.create(data = it, encoding = NSUTF8StringEncoding).toString()
    and I cant find out how do you know about function name and definition. I have read on github kotlin native repo that those initializers are done via create factory but I cant find any documentation. Where can i find functions declarations please? I looked into platform.Foundation.NSString but I didn’t see
    create
    a
    • 2
    • 5
  • m

    Michael Pohl

    11/09/2020, 3:26 PM
    Hi everyone! Maybe someone can help me out with what are probably Multiplatform beginner questions... I just went through the Kotlin Multiplatform Hands-on: Networking and Data Storage tutorial. the Android build is running, but iOS crashes at startup. I've been double and triple checking everything but I cannot find anything I did wrong. Tbh, I also have trouble understanding what the stacktrace tells me (as in: Which of the mentioned classes in there is the origin of the problem):
    s
    s
    • 3
    • 10
  • d

    Deor

    11/09/2020, 6:23 PM
    Hey, Can I somehow have multiple threads using coroutines ? I know that in the documentation they say:
    The current version of kotlinx.coroutines, which can be used for iOS, supports usage only in a single thread.
    but supposedly there is a multithreded version
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt"){
        version {
            strictly("1.3.9-native-mt")
        }
    }
    I can’t seem to make it work though and in the iOS app Everything is still done on a single background thread.
    l
    • 2
    • 14
  • x

    xiaobailong24

    11/10/2020, 4:57 AM
    https://kotlinlang.org/docs/reference/ Kotlin lastest version is 1.4.10. But I want refer to v1.3.72 docs, how do that? Help me. What link is kotlin old version docs?
    👍 1
    g
    • 2
    • 2
  • f

    Ferran

    11/10/2020, 9:19 AM
    with Kotlin
    1.4.0
    we can use
    SharedFlow
    . Is this supported from kotlin multiplatform native? in this example:
    fun start() {
            actionsFlow.asSharedFlow().onEach { action ->
                when (action) {
                    Action.Refresh -> refresh()
                    Action.Load -> Unit
                }
            }.launchIn(coroutineScope)
        }
    
        suspend fun action(action: Action) {
            actionsFlow.emit(action)
        }
    it works from Android but from iOS there are no events coming through the flow, the coroutineScope implementation (CustomMainScope) that I’m using for iOS is the following:
    internal actual fun CustomMainScope(): CoroutineScope = CustomMainScopeImpl()
    
    internal class CustomMainScopeImpl : CoroutineScope {
        private val dispatcher = MainDispatcher()
        private val job = Job()
        private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
            println("${throwable.message}: ${throwable.cause}")
        }
    
        override val coroutineContext: CoroutineContext
            get() = dispatcher + job + exceptionHandler
    }
    
    private class MainDispatcher : CoroutineDispatcher() {
        @Suppress("TooGenericExceptionCaught")
        override fun dispatch(context: CoroutineContext, block: Runnable) {
            dispatch_async(dispatch_get_main_queue()) {
                try {
                    block.run()
                } catch (err: Throwable) {
                    throw err
                }
            }
        }
    }
    and the dependency for iOS is:
    "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0"
    Is
    SharedFlow
    supposed to work on iOS even if its on a main thread?
    r
    j
    p
    • 4
    • 11
  • m

    mzgreen

    11/10/2020, 11:35 AM
    I’m considering creating a multiplatform library using KMM. I would like to produce aar for Android and framework for iOS and then consume them in client apps which are developed as separate projects. Is this possible with KMM? Are there any guidelines on how to setup the project to produce proper binaries for both Android and iOS?
    a
    • 2
    • 2
  • r

    rsetkus

    11/10/2020, 3:36 PM
    Hi. Trying to publish artifacts to local maven but getting weird error for Android target. When add this to android target
    android {
        publishLibraryVariants("release", "debug")
    }
    I get error:
    > Kotlin target 'android' tried to set up publishing for Android build variants that are not library variants or do not exist:
         * release
         * debug
    But when I add
    buildType
    block to android configuration block like this:
    android {
        ....
        buildTypes {
            val release by creating {
               isMinifyEnabled = false
            }
            val debug by creating {
                isDebuggable = true
            }
        }
    }
    I get error:
    Please initialize at least one Kotlin target in 'kommon (:kommon)'.
    l
    • 2
    • 4
  • m

    mzgreen

    11/10/2020, 5:23 PM
    Is there a guide or a sample project showing how to do CI (for example using github actions) setup (running tests for iOS/Android and common code, building iOS/Android apps etc) for a KMM project? I’ve done that for Android projects before but with KMM everything is in the same repo so I’m a bit confused.
    f
    m
    • 3
    • 2
  • a

    Amritansh

    11/10/2020, 10:18 PM
    I am trying to make a post request using Ktor HttpClient in commonMain on a singleThread using Dispatcher.Default and I am getting this exception on iOS
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@c1c6c8 from other thread
        at 0   shared                              0x000000010ac441bd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
        at 1   shared                              0x000000010ac3d0ab kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
        at 2   shared                              0x000000010ac3d26b kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
        at 3   shared                              0x000000010ac7006b kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/Runtime.kt:30:36)
        at 4   shared                              0x000000010ac7438d ThrowIllegalObjectSharingException + 621 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:98:11)
        at 5   shared                              0x000000010ad5a002 _ZN12_GLOBAL__N_128throwIllegalSharingExceptionEP9ObjHeader + 34
        at 6   shared                              0x000000010ad5e52e _ZNK27BackRefFromAssociatedObject3refEv + 78
        at 7   shared                              0x000000010ad44bd4 _ZN12_GLOBAL__N_111toKotlinImpEP11objc_objectP13objc_selectorPP9ObjHeader + 52
        at 8   shared                              0x000000010ad87c81 Kotlin_Interop_refFromObjC + 65
        at 9   shared                              0x000000010aff65ea _696f2e6b746f723a6b746f722d636c69656e742d696f73_knbridge28 + 330 (/opt/buildAgent/work/a85294440dc5c6e/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosResponseReader.kt:100:14)
        at 10  shared                              0x000000010afff37a _696f2e6b746f723a6b746f722d636c69656e742d696f73_kncfun30 + 74
        at 11  CFNetwork                           0x00007fff22f31ade _CFNetworkHTTPConnectionCacheSetLimit + 207606
        at 12  Foundation                          0x00007fff25752d51 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
        at 13  Foundation                          0x00007fff25752c49 -[NSBlockOperation main] + 98
        at 14  Foundation                          0x00007fff25755bd6 __NSOPERATION_IS_INVOKING_MAIN__ + 17
        at 15  Foundation                          0x00007fff25751e49 -[NSOperation start] + 731
        at 16  Foundation                          0x00007fff25756530 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 17
        at 17  Foundation                          0x00007fff2575603a __NSOQSchedule_f + 182
        at 18  libdispatch.dylib                   0x000000010b75a3c9 _dispatch_block_async_invoke2 + 83
        at 19  libdispatch.dylib                   0x000000010b74bd48 _dispatch_client_callout + 8
        at 20  libdispatch.dylib                   0x000000010b759de6 _dispatch_main_queue_callback_4CF + 1500
        at 21  CoreFoundation                      0x00007fff23bd4049 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
        at 22  CoreFoundation                      0x00007fff23bceca9 __CFRunLoopRun + 2329
        at 23  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
        at 24  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
        at 25  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
        at 26  iosApp-sample                       0x000000010a8b905b main + 75 (/User/iosApp-sample/iosApp-sample/AppDelegate.swift:4:7)
        at 27  libdyld.dylib                       0x00007fff5227ec25 start + 1
    This is what my implementation looks like
    fun postRequest() {
            MainScope().launch {
                withContext(Dispatchers.Default) {
                     HttpClient().post("URL"){
                       body = "some json"
                     }
                }
            }
        }
    This request is working fine for the Android application and only throws the exception in iOS. Also if I try to run HttpClient().post on the main thread, it works fine on iOS and I am successfully able to send the request. ktorVersion = "1.4.1" coroutinesVersion = "1.3.9-native-mt-2" Based on this documentationhttps://github.com/Kotlin/kotlinx.coroutines/blob/native-mt/kotlin-native-sharing.md#switching-threads for
    "1.3.9-native-mt-2"
    my understanding is it should work. Any help is appreciated!
    t
    a
    • 3
    • 9
  • w

    william

    11/10/2020, 11:18 PM
    does anyone have suggestions for a multiplatform friendly
    BigInteger
    type of class?
    z
    • 2
    • 2
  • t

    tylerwilson

    11/11/2020, 1:17 AM
    Time for those Catalyst builds…. 🙂
    👆 1
    s
    • 2
    • 4
Powered by Linen
Title
t

tylerwilson

11/11/2020, 1:17 AM
Time for those Catalyst builds…. 🙂
👆 1
s

Sam

11/11/2020, 1:55 PM
Not for a while. I asked about it in the Reddit AMA. https://www.reddit.com/r/Kotlin/comments/ji9z19/kotlin_team_ama_2_ask_us_anything/ga6l793/
t

tylerwilson

11/11/2020, 1:56 PM
So unfortunate. I have an iPad app that uses KMP extensively and I would love to have a ‘native’ macOS Catalyst version of it…
s

Sam

11/11/2020, 5:36 PM
Yeah. Ultimately Catalyst is a dead end technology so I can understand why it isn’t a priority. On one hand as Intel Macs go away and Apple chips take their place, we won’t need Catalyst. On the other hand, if you’re using SwiftUI for the UI layer, it should just be a matter of adding a macOS module to your KMP build and recompiling. Unfortunately the app I’m working on isn’t using SwiftUI so it will be a while before our users can use it on their desktops.
t

tylerwilson

11/11/2020, 5:58 PM
‘ultimately’ being the key word here. ‘ultimately’, objective-c will be dead. meanwhile, it is a valid solution and thus ought to be supported.
👍 1
View count: 8