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

    Siggi Gunnarss

    10/13/2020, 1:15 PM
    Hi all. I have a highlighting bug in my project where any references in .kt files in my main module to classes in other modules are marked in red.
    (Cannot access class...)
    The project compiles and runs as expected and Java files are not affected. It started with the kotlin plugin version 1.4 and it's still an issue with 1.4.20-M1. Using an older plugin, 1.3.72 fixes the issue, but the project is on Kotlin 1.4 so that's not a good workaround. The project is a kotlin multiplatform project so I suspect that's the issue Before I raise an issue with Jetbrains I want to understand the problem better, has anyone encountered this?
    m
    • 2
    • 3
  • j

    jean

    10/14/2020, 7:07 AM
    I’ve been trying to configure sqldelight in my project since yesterday, but without any success so far
    plugins {
        kotlin("multiplatform") version "1.4.10"
        id("com.squareup.sqldelight")
    }
    
    buildscript {
        repositories {
            jcenter()
        }
    
        dependencies {
            classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0")
            classpath ("com.squareup.sqldelight:gradle-plugin:1.4.3")
        }
    }
    
    sqldelight {
        database("MyDatabase") {
            packageName = "com.my.package.name.sqldelight"
        }
    }
    I also created a
    News.sq
    file in
    src/commonMain/sqldelight/com/my/package/name/sqldelight
    Running
    gradlew build
    succeed but I can’t see that
    MyDatabase
    class is generated. Am I suppose to do anything more?
    m
    a
    • 3
    • 10
  • m

    Mikołaj Kąkol

    10/14/2020, 12:05 PM
    I've added atomicfu to project like this in commonMain
    compile "org.jetbrains.kotlinx:atomicfu-common:0.14.4"
    now my build on ios fails, any suggestion
    Execution failed for task ':shared:compileKotlinIos'.
     > Could not resolve all files for configuration ':shared:iosCompileKlibraries'.
        > Could not resolve org.jetbrains.kotlinx:atomicfu-common:0.14.4.
          Required by:
              project :shared
           > No matching variant of org.jetbrains.kotlinx:atomicfu-common:0.14.4 was found. The consumer was configured to find a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' but:
               - Variant 'metadata-api' capability org.jetbrains.kotlinx:atomicfu-common:0.14.4:
                   - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
                   - Other compatible attribute:
                       - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
               - Variant 'metadata-commonMainMetadataElements' capability org.jetbrains.kotlinx:atomicfu-common:0.14.4 declares a usage of 'kotlin-api' of a component:
    ...
    m
    • 2
    • 5
  • a

    altavir

    10/14/2020, 4:59 PM
    @dsavvinov Really nice talk. I had to listen to it with a slight delay due to lectures, but it was really helpful.
    ➕ 7
    😊 1
    👀 1
    d
    k
    +6
    • 9
    • 14
  • с

    Соловьев Георгий

    10/15/2020, 11:48 AM
    Hello, I have a problem with linkDebugFrameworkIosX64 gradle task. linkDebugFrameworkIosArm64 and linkReleaseFrameworkIosX64 work without any problems. But on x64 debug I have that error. How can I fix it?
    a
    • 2
    • 1
  • a

    Aleksandr Ivanov

    10/15/2020, 12:24 PM
    Is there anyone experienced with apollo graphql multiplatform library? It is working fine on android but on iOS we got empty body on our backend.
    l
    m
    • 3
    • 24
  • m

    myrronth

    10/15/2020, 1:17 PM
    How do I declare a weak variable with the expect/actual pattern that also becomes a weak variable when used in Swift? I’ve tried
    actual var listener: WeakReference<T>? = null
    and updated my calls to
    listener?.get()?.method()
    . But once I use my shared code in Swift, the
    listener
    variable is not the expected
    weak var listener: T
    but a wrapped
    KotlinWeakReference
    . If I use this, it is the same as without – the value assigned to listener, a UIViewController, does not get deallocated once all the references in the concrete implementation are gone (the view controller gets dismissed and should not receive further messages from the listener)
    a
    • 2
    • 5
  • e

    Elka

    10/15/2020, 2:39 PM
    Hello, I am trying to build a multi-platform client that retries the request automatically when the token expired and 401 is returned from the server. For that I am using a sample code by moko-network. The refresh token api is being triggered but when it retries the  request using 
    request
     , I never get a 
    result
     as if some “deadlock” occurred.
    val requestBuilder = HttpRequestBuilder().takeFrom(context.request)
    val result: HttpResponse = context.client!!.request(requestBuilder)
    Any idea? Anyone implemented a RefreshToken feature that works with latest Ktor?
    r
    • 2
    • 6
  • r

    rsetkus

    10/15/2020, 4:15 PM
    Hi. I am fairly new to Multiplatform. Sounds quite trivial question but is it possible to run unit tests from IDE for common module? Created an empty project and when clicking 'Run' button 'Nothing here' pops up.
    s
    g
    m
    • 4
    • 15
  • a

    Anvith

    10/16/2020, 5:58 AM
    I recently upgraded to kotlin 1.4.1 and it seems that the adding any pod file via the native.cocoapods plugin is causing the the gradle task
    linkDebugFrameworkIosSim
    to throw an error
    Could not find <project-name> in …
    I’ve attached the relevant trace for completeness. How do I resolve this or am I missing something?
    log.rtf
    a
    • 2
    • 6
  • s

    sendoav

    10/16/2020, 8:25 AM
    Hi All! I have recently updated to kotlin 1.4.0 and when trying to execute the compileKotlinIos task I get "java.io.FileNotFoundException: /../build/classes/kotlin/ios/main/presentation/manifest (No such file or directory)"
    a
    i
    • 3
    • 12
  • a

    aleksey.tomin

    10/16/2020, 11:20 AM
    Can I use two different JVM targets with different JDK versions? Fox example - spark and android require JDK8 but for the jvm application, we wont to use the last JVK.
    b
    • 2
    • 3
  • b

    Big Chungus

    10/16/2020, 12:53 PM
    @jetbrains
    Could we have kotlin version added to gradle metadata attributes, please? This would be useful in determining library compatibilities. Also would play a key role when consuming it and deciding which schema/attributes to expect, since those seem to be quite volatile between versions
    r
    l
    +3
    • 6
    • 15
  • b

    basher

    10/16/2020, 9:12 PM
    I’m getting into multi-project builds, and I noticed jvmTest runs jvmTest for all subprojects too. is there a way to make it only run tests from the root project?
    e
    • 2
    • 7
  • k

    kartik1712

    10/17/2020, 3:59 PM
    Hi! I am trying to port a project to Kotlin Multiplatform. Due to some issues with the serialization library, I am unable move to latest Kotlin version. Where can I find the documentation of older versions ? I was unable to find it on the kotlinlang wesite.
    l
    • 2
    • 4
  • r

    rocketraman

    10/17/2020, 4:39 PM
    What are people using for multiplatform mobile (android and iOS) logging? I've found Napier but looking for something else. Napier doesn't even log stack traces on iOS.
    a
    a
    j
    • 4
    • 4
  • m

    Marc Knaup

    10/17/2020, 5:53 PM
    Is there a multiplatform identity hashmap? Or any way to get an internal unique ID for an object in JS? On JVM there is
    System.identityHashCode(…)
    and on native there is
    Any?.identityHashCode()
    .
    s
    a
    • 3
    • 7
  • w

    william

    10/17/2020, 9:38 PM
    in my android module i depend on my multiplatform module, but I am getting an error saying
    Duplicate JVM class name
    Am I depending on the multiplatform module incorrectly? i am doing
    implementation(project(":mobile"))
    • 1
    • 2
  • e

    Even André Fiskvik

    10/18/2020, 8:29 PM
    Hi all 🙂 We have an existing native iOS/Android project where we are trying to create a shared KMM library create more consistent code between the platforms and reuse code. What we would like to retain is the way we build the projects (that means using Xcode for iOS). Does anyone know if there's some official documentation on how to integrate kotlin KMM module well with an existing project or have managed to do it somehow? So far it seems for iOS the best working solution for us have been to use the Cocoapods integration, however we are having some issues there since we manage multiple configurations in our iOS project (not just Develop and Release, which is the only configurations supported by the plugin by default).
    a
    • 2
    • 3
  • a

    Aleksandr Ivanov

    10/18/2020, 9:24 PM
    Trying to publish library artefacts to private repo. Got a following error
    > 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.
    i
    k
    l
    • 4
    • 6
  • d

    Dana Haukoos

    10/19/2020, 5:17 PM
    I've created the example KMM Hello World app described at Create your first multiplatform application. Next I created a new KMM Module via AndroidStudio's File->New->New Module...->KMM Shared Module, and named it kmmsharedmodule. I edited that to return the date using system libraries for each platform (referencing code snippets from Getting started with Kotlin Multiplatform.) Exactly how do I edit my build.gradle files to make the overall app dependent on kmmsharedmodule? I'm hoping it can be configured to automatically generate both Android and iOS libraries for this module, but I haven't found an example describing this specifically.
    k
    r
    • 3
    • 102
  • u

    Ugi

    10/19/2020, 9:14 PM
    Hey all, I think I'm having some troubles with my maven snapshot publishing. I'm using three different machines to publish to various mac linux and windows builds, each of those creates their own common entry, but the problem is, modules file in those common entries contain links only to artifacts from that machine, i.e. mac: https://oss.sonatype.org/content/repositories/snapshots/com/ionspin/kotlin/multiplatform-crypto-libsodium-bindings/0.1.1-SNAPSHOT/multiplatform-crypto-libsodium-bindings-0.1.1-20201019.205459-4.module linux: https://oss.sonatype.org/content/repositories/snapshots/com/ionspin/kotlin/multiplatform-crypto-libsodium-bindings/0.1.1-SNAPSHOT/multiplatform-crypto-libsodium-bindings-0.1.1-20201019.202701-1.module So the problem is as follows: If the last machine to publish to snapshot with the same version was
    mac
    , trying to resolve the dependancy for a sample project on
    linux
    machine will fail because it's missing links to artifacts in latest module:
    No matching variant of com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.1.1-SNAPSHOT:20201019.205459-4 was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
              - Variant 'iosArm32-api' capability com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.1.1-SNAPSHOT:
                  - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
                  - Other compatible attribute:
                      - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
    And vice versa. I haven't faced this behavior before, so is it something new, or am I doing something stupid because I'm tired?
    • 1
    • 1
  • c

    chi

    10/20/2020, 12:57 AM
    I'm trying to write tests for a KMP project, I get the following error when trying to run the Android test, what could be wrong?
    unable to enhance gradle daemon classloader with idea_rt.jar
    org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':shared:debugUnitTestRuntimeClasspath'.
    	...
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find org.junit.jupiter:junit-jupiter:.
    Required by:
        project :shared
    j
    • 2
    • 1
  • r

    rocketraman

    10/20/2020, 6:49 AM
    I use the cocoapods integration with a KMM project with a
    Firebase/Auth
    dependency. I keep getting the dreaded code 65 error:
    Executing of 'xcodebuild -project Pods.xcodeproj -scheme Firebase -sdk iphonesimulator -configuration Release' failed with code 65 and message
    . Anyone have this working?
    e
    a
    +3
    • 6
    • 31
  • r

    rocketraman

    10/20/2020, 5:18 PM
    My k/n build importing
    kotlin.native.concurrent.AtomicReference
    in
    commonMain
    is failing when I build it on my Linux box with
    Unresolved reference: AtomicReference
    , but working on my Mac. According to the docs,
    AtomicReference
    is available in
    Common
    .
    a
    • 2
    • 4
  • m

    Mikołaj Kąkol

    10/21/2020, 10:49 AM
    Hi, is
    suspendCoroutine
    broken in
    1.3.9-native-mt-2
    ? I'm getting an error like on iOS:
    Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.coroutines.SafeContinuation@368d808
    <unknown>:0: error: -[Example_iOS_Tests.SharedModuleTests testSharedModule] : Unexpected Failure
    /Users/jenkins4/workspace/q-lib-branch_feature_screensArch/Example/Example-iOS/Example-Tests/SharedModuleTests.swift:113: error: -[Example_iOS_Tests.SharedModuleTests testSharedModule] : Failed due to unwaited expectation 'Test Shared Module'.
    Test Case '-[Example_iOS_Tests.SharedModuleTests testSharedModule]' failed (0.190 seconds).
    j
    l
    • 3
    • 18
  • j

    jeggy

    10/21/2020, 2:21 PM
    Is it possible to extend the test libraries from one project into another project's test libraries? I'm creating a multiproject multiplatform project and I'm using a line like this:
    implementation(project(":kgraphql"))
    within jvmMain, but it's not possible to get the jvmTest from that project to it's side project. Are there any solutions for this except just copy and paste it?
    m
    r
    s
    • 4
    • 6
  • r

    rsetkus

    10/21/2020, 3:31 PM
    Hi. Changed ios platform declaration from
    iosX64("ios")
    to
    ios()
    and now need to create modules iosArm64Main and iosX64Main. Is there any way to point both targets to iosMain sourceset only? Does it mean that now I would need duplicate
    actual
    implementation for each target?
    ⬆️ 1
    c
    • 2
    • 2
  • k

    Kris Wong

    10/21/2020, 4:18 PM
    so I have run into an issue where I have a default value provided for a method argument on an expect class, and on iOS, this value is received correctly in the actual implementation, but on Android it's null. has anyone seen this before?
    m
    • 2
    • 2
  • u

    Umar Ata

    10/21/2020, 6:22 PM
    Hi there, My name is Umar, I am from India Nice meeting you to all worlds best developers I have a question I actually transformed one of my android application logic code to kotlin multiplatform Problem: When the iOS developer needs the logic code I need to execute the command
    *cd* "$SRCROOT/.."
    ./gradlew :shared:packForSimulator -PXCODE_CONFIGURATION=${CONFIGURATION}
    shared is the name of my multiplatform module I am sharing the common code between Android and iOS so the problem is that whenever I run above command from runScript of XCode it actually builds the framework for Selected device like either iPhone device or iPhone Simulator and it never gives me one framework that runs on both iOS device and simulator
    k
    g
    • 3
    • 20
Powered by Linen
Title
u

Umar Ata

10/21/2020, 6:22 PM
Hi there, My name is Umar, I am from India Nice meeting you to all worlds best developers I have a question I actually transformed one of my android application logic code to kotlin multiplatform Problem: When the iOS developer needs the logic code I need to execute the command
*cd* "$SRCROOT/.."
./gradlew :shared:packForSimulator -PXCODE_CONFIGURATION=${CONFIGURATION}
shared is the name of my multiplatform module I am sharing the common code between Android and iOS so the problem is that whenever I run above command from runScript of XCode it actually builds the framework for Selected device like either iPhone device or iPhone Simulator and it never gives me one framework that runs on both iOS device and simulator
k

Kris Wong

10/21/2020, 6:38 PM
you need to create a fat framework task https://medium.com/vmware-end-user-computing/building-an-ios-fat-framework-for-a-kotlin-multiplatform-project-4f2e0b5de2aa
u

Umar Ata

10/21/2020, 6:44 PM
Thank you, I want to know that if I use Fat framework so can I use same in Android?
k

Kris Wong

10/21/2020, 6:44 PM
i don't understand the question. Android doesn't use frameworks.
u

Umar Ata

10/21/2020, 6:47 PM
I have one android app, I want the same logic in both iOS and Android, so I copied my logic code in newly created shared multiplatform module and in Android I am using it as a project dependency like
implementation project(':shared')
and for iOS I use script to generate xcode-frameworks
and then use it in there
I don’t want to code separate framework for iOS, I only want to make framework that runs for both iOS device and simulator
for now I created two functions in gradle each for iOS device and simulator
val packForXCode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    //val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "iosArm64"//+  if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
val packForSimulator by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = /*System.getenv("SDK_NAME") ?: */"iphonesimulator"
    val targetName = "ios" +/*+ if (sdkName.startsWith("iphoneos")) "Arm64" else*/ "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
so when I want to generate framework for iPhone device I use ./gradlew shared:packFor XCode and for simulator I use ./gradlew shared:packForSimulator
in this way I don’t need to select iPhone or Simulator in XCode
g

georg

10/21/2020, 7:03 PM
You could also create an XCFramework. It contains both the framework for the device and the simulator. I created a Gradle plugin that can do that for you. Check it out on Github: https://github.com/ge-org/multiplatform-swiftpackage
k

Kris Wong

10/21/2020, 7:21 PM
a normal framework file contains the same. there's no need for a plugin
g

georg

10/21/2020, 7:25 PM
With a fat framework you need to remove the unused architectures (i.e. simulator) before uploading to the App Store. Otherwise Apple will reject the binary. An xcframework does not require this step
k

Kris Wong

10/21/2020, 7:25 PM
gotcha
or just use the coacoapods plugin and don't worry about it
g

georg

10/21/2020, 7:29 PM
True. It takes care of removing the simulator frameworks. But then you’re stuck with Cocoapods 😉 There are plenty of options out there. Just pick whatever suits your needs
u

Umar Ata

10/21/2020, 7:32 PM
So if I setup cocoa pods for my framework then I don’t need to generate framework?
but then it will become publicly available ?
g

georg

10/21/2020, 7:37 PM
It wont’t be public unless you publish it. There’s a nice article by Jetbrains about the integration of Cocoapods and KMP. https://kotlinlang.org/docs/reference/native/cocoapods.html
u

Umar Ata

10/21/2020, 7:38 PM
okay
View count: 12