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

    iamsteveholmes

    07/29/2021, 7:13 PM
    Hey Folks! I noticed when I build a new project it has a simple
    iosApp.swift
    class with:
    import SwiftUI
    
    @main
    struct iOSApp: App {
    	var body: some Scene {
    		WindowGroup {
    			ContentView()
    		}
    	}
    }
    Instead of the whole AppDelegate and SceneDelegate thing. Being new to IOS and swift entirely I know very little except the new way seems WAY simpler and maybe more versatile and configurable to create multiple scenes, etc. Has anyone converted from the old way to the new way?
    👀 1
    u
    • 2
    • 2
  • m

    MJegorovas

    07/30/2021, 12:28 PM
    Hey everyone, I'm trying to upload ios app to store but when building archive for it I get error from my swift library interop task (followed this guide)
    Exception in thread "main" java.lang.IllegalStateException: Could not find 'libCryptoKitWrapper.a' binary in neither of [CryptoKitWrapper/build/Release-iphoneos]
    even though the file is present in the location. Any ideas what might be wrong?
    • 1
    • 1
  • s

    Simonas Brazauskas

    07/30/2021, 1:10 PM
    Hello, it seems abstract classes does not force subclassed classes to implement interface methods in swift. For example
    abstract class KotlinAbstractClass : KotlinInterface {
    
    }
    
    interface KotlinInterface {
        fun testFunction()
    }
    
    //Swift code
    class SwiftClass : KotlinAbstractClass {
        
    }
    XCode compiles
    SwiftClass
    successfully, but then fails with an exception at runtime if someone tries to call
    SwiftClass::testFunction
    . Is this a bug or works as intended? We are having some issues with ios devs, as sometimes they forget to implement all interface methods, which results in crashes. Also it would cause issues, when additional methods in interfaces are added.
    r
    n
    • 3
    • 2
  • l

    Lena Stepanova

    07/30/2021, 2:20 PM
    Hi everyone, I will appreciate it very much if you could take a look at a problem I have regarding sharing HttpClient between Coil and Ktor https://stackoverflow.com/questions/68592479/how-to-share-httpclient-between-multiplatform-ktor-and-coil
    i
    • 2
    • 2
  • t

    tylerwilson

    07/30/2021, 2:46 PM
    Ugh, this is frustrating! I am trying to update to latest Ktor, serialization and/or coroutines in my shared KMM module. This combo works:
    val kotlinVersion = "1.5.21"
    val coroutinesVersion = "1.5.0-native-mt"
    val ktorVersion = "1.6.1"
    val serializationVersion = "1.2.1"
    if i try to update any of them (1.5.1-native-mt, 1.6.2 or 1.2.2), then the linkDebugFrame taks will either fail silently (create an empty klib folder) or spit out the error below, depending on the target (I have it set up for android, jvm, ios, watchos and macos). Using latest AS Arctic Fox with latet Kotlin 1.5.21 plugin.
    w: skipping /Users/tylerwilson/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-serialization-iosx64/1.6.2/681f93a891846267e5050007bc41a01e459dbe74/ktor-client-serialization.klib. Incompatible abi version. The current default is '1.4.2', found '1.5.0'. The library produced by 1.5.20 compiler
    e: Could not find "/Users/tylerwilson/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-serialization-iosx64/1.6.2/681f93a891846267e5050007bc41a01e459dbe74/ktor-client-serialization.klib" in [/Users/tylerwilson/Projects/salonbiz-stylist-android, /Users/tylerwilson/.konan/klib, /Users/tylerwilson/.konan/kotlin-native-prebuilt-macos-1.5.10/klib/common, /Users/tylerwilson/.konan/kotlin-native-prebuilt-macos-1.5.10/klib/platform/ios_x64]
    Can anybody help????
    r
    • 2
    • 7
  • l

    Landry Norris

    07/30/2021, 3:41 PM
    Is there a good way to force builds for Android to use a different compiler version? Right now, Jetpack Compose specifically requires 1.5.10, but I have an import in iOS main that requires 1.5.21
    m
    • 2
    • 2
  • n

    Nacho Ruiz Martin

    07/30/2021, 5:59 PM
    Hey! 👋 What’s the meaning of an error during the iOS build that says “ld: framework not found X”? It’s complaining about a library I’m using that is supposed to be working on iOS.
    b
    • 2
    • 9
  • m

    Michal Harakal

    07/30/2021, 7:37 PM
    [SOLVED] Is it a good idea to use shared KMP module in NotificationServiceExtension on iOS? NotificationServiceExtension is used for handling remote notifications in case an app is in background. Important is, that extension code is spinned not only in a new thread but even in a new process. I tested naive approach to use a shared module for the extension target with cocoapod and it compiles fine, but crashes badly with kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared
    • 1
    • 1
  • e

    Eric O'Connell

    07/30/2021, 8:03 PM
    From https://kotlinlang.org/docs/mpp-share-on-platforms.html#share-code-in-libraries
    Kotlin doesn’t currently support sharing a source set for these combinations:
    …
    JVM + Android targets
    Is this limitation expected to remain for a while?
    a
    • 2
    • 2
  • l

    Landry Norris

    07/30/2021, 9:43 PM
    In my KMM project, I have a variable of type CustomClass<Session?>, where Session is a data class and CustomClass<T> is a class that uses a generic. I noticed that when I access this variable in Swift, the type is CustomClass<Session>. CustomClass also has a variable of type T, which Kotlin sees as Session?, and Swift sees as Session. When Kotlin sets this inner variable equal to a Session Object, Swift sees the new value. When I set it equal to null, Swift sees the old value. Is this expected behavior? I would expect Swift to see the same types as Kotlin.
    • 1
    • 1
  • b

    Bradford Canonigo

    07/30/2021, 11:58 PM
    is there a mockito dependency in kotlin multiplatform? or other unit testing frameworks?
    x
    • 2
    • 1
  • a

    aiidziis

    07/31/2021, 8:04 AM
    Hey! Sorry if this has been already answered here. Tried to search it, but couldn’t get an answer to my question. The Question: Is there a way to get a good stack trace for crashes that happen for iOS when using Kotlin Multiplatform? Our current implementation uses this library to include shared code inside iOS App, but when we receive crashes due to shared code it is so painful to debug.
    m
    • 2
    • 1
  • n

    Nacho Ruiz Martin

    07/31/2021, 8:01 PM
    I'm having a hard time to build my app on iOS when I add some Multiplatform dependency (Firebase Kotlin sdk). Gradle script is just failing silently. Is there any sane way to debug this? Starting to loose my mind here.
    a
    l
    k
    • 4
    • 14
  • d

    Daniel Kunis [JB]

    08/02/2021, 11:17 AM
    Hey all! We want to dive into KMM-development experience regarding: • Networking (Ktor and serialisation especially) • Sharing resources, localization • Crash analytics So if you have anything you'd like to share with us regarding these topics, please, leave a :kotlinnew:  reaction and I'll gladly contact you
    :kotlin-intensifies: 2
    :kotlinnew: 8
    o
    • 2
    • 1
  • a

    Alexander Ignatiev

    08/02/2021, 11:47 AM
    Hello everyone 👋 I just started trying KMM :kotlin: Does anyone have any useful links or best practices for memory management on iOS+KMM?
    l
    k
    • 3
    • 3
  • s

    Stefan Oltmann

    08/02/2021, 3:47 PM
    I'm looking for a sample how to use Gradle testFixture with a Kotlin Multiplatform Project
    p
    • 2
    • 2
  • z

    Zahn

    08/02/2021, 6:24 PM
    Hello, Anyone got that when trying to build the framework on native mac (M1) using
    iosArm64("ios")
    ?
    Task 'embedAndSignAppleFrameworkForXcode' not found in project ':common'.
    t
    z
    +2
    • 5
    • 6
  • e

    Evan

    08/02/2021, 9:10 PM
    Has anyone had issues building an iOS application that uses a KMM library on an Apple Silicon M1 macbook? Someone on my team just upgraded, and XCode won’t compile the project unless it’s put in Rosetta mode. It builds fine on our older Intel machines.
    ☝️ 1
    w
    h
    • 3
    • 2
  • c

    coolcat

    08/03/2021, 8:02 AM
    Hi all, I have a KMM library integrated into my Xcode project using the Cocoapods plugin. It builds well on my own machine, and also on my CI build node when I SSH in and invoke the build manually. However, when I build on the build node using Jenkins, it just hangs at the Build Shared phase. I enabled debug logging on the Gradle command and it seems the last few logs are about connecting to the daemon
    2021-08-02T22:52:01.227+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
    2021-08-02T22:52:01.228+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
    2021-08-02T22:52:01.230+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
    2021-08-02T22:52:01.230+0100 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpOutgoingConnector] Attempting to connect to [77b233a7-ef8c-4285-9d34-29b590570f08 port:61870, addresses:[/127.0.0.1]].
    2021-08-02T22:52:01.230+0100 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpOutgoingConnector] Trying to connect to address /127.0.0.1.
    2021-08-02T22:52:01.234+0100 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpOutgoingConnector] Connected to address /127.0.0.1:61870.
    Does anybody have any hints for troubleshooting? I already tried setting
    -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx2g
    as my
    GRADLE_OPTS
    env variable.
    k
    • 2
    • 3
  • l

    Landry Norris

    08/03/2021, 2:29 PM
    I'm currently using expect/actual for camera operations on Android and iOS. Android's CameraX integrates beautifully with KMM, but I'm noticing that the iOS equivalent is extremely verbose. When I define a Kotlin class that implements the AV...RecordingDelegateProtocol for use with the AVCaptureMovieFileOutput, Kotlin forces me to define a lot of extra functions, such as 'class', conformsToProtocol, isKindOfClass, etc that are not related to the Swift equivalent of the interface In case it helps anyone, subclassing NSObject removes the requirement to implement these extra methods. Has anyone else encountered this while trying to use iOS's camera library in Kotlin using expect/actual? (I'm trying to do this in Kotlin, not Swift, so I can use the result in shared code).
    m
    o
    • 3
    • 4
  • m

    Michal Klimczak

    08/03/2021, 4:12 PM
    Hint for people who come from android background and try to do shared code for ios. Most of
    delegates
    in ios are weak. You need to keep a strong reference somewhere for them to not get deallocated unexpectedly. This is even more problematic, because usually the problem doesn't manifest itself on debug build, only release build crash and the stacktrace is rubbish.
    • 1
    • 2
  • m

    mike.holler

    08/03/2021, 7:46 PM
    I've been working with Kotlin/JS and Ktor's HTTP client, and although my tests pass in JVM and native, they fail for JavaScript. The reason why is cryptic. If it helps, I'm using the IR compiler and targeting the NodeJS runtime. Is there any way to get better error messages for something like this?
    Error_0: Fail to fetch
    Error_0: Fail to fetch
    	at _no_name_provided__246.invoke_1ti8hr(kotlin/multiplatform-sdk-end-to-end-tests-test.js:69724)
    	at <global>.<unknown>(/home/mjholler/Git/multiplatform-sdk/build/js/packages/multiplatform-sdk-end-to-end-tests-test/kotlin/multiplatform-sdk-end-to-end-tests-test.js:69752)
    	at <global>.processTicksAndRejections(internal/process/task_queues.js:93)
    b
    t
    • 3
    • 8
  • n

    Ngenge Senior

    08/04/2021, 2:19 AM
    Hello all. I happen to be migrating my Jetpack Compose code to Kotlin Multiplatform since I want to reuse part of the common code in SwiftUI. I have followed all the necessary instructions given at the following URL,https://kotlinlang.org/docs/mobile/integrate-in-existing-app.html#use-the-shared-module-from-swift after creating a shared module and created a fresh Xcode project in the same directory as the android app and shared module but when I build the XCode project, it keeps failing. The log is found here,https://gist.github.com/ngengesenior/bbdf12ee129bb12427cf25bc6b78ce3b . I really need some help as it is my first time creating a kmm project
    t
    • 2
    • 4
  • f

    Fanis Paschos

    08/04/2021, 6:00 AM
    Hello everyone. I have a KMM project and when I try to run the gradle task to create the iOS Framework, it fails with error: “e: java.lang.AssertionError: Unbound symbols not allowed Unbound public symbol for public kotlinx.serialization.json.internal/StreamingJsonDecoder.decodeNullableSerializableElement|7091057077819363828[0] public kotlinx.serialization.json.internal/StreamingJsonDecoder.decodeNullableSerializableElement|7091057077819363828[0] e: Compilation failed: Unbound symbols not allowed” Any ideas what might be the issue here? *Full error snippet in comments
    • 1
    • 1
  • c

    Cdev

    08/04/2021, 5:02 PM
    Does anyone know how to make an XCFramework build that works for iosArm32 as well as iosArm64 and iosX64? I have my xcframework build working great with iosArm64 and iosX64 together, but when I try to add in iosArm32 I get a build error of "KotlinTarget with name 'iosArm32 not found"
    val buildXcFramework by tasks.registering {
        dependsOn("deleteXcFramework")
        group = "build"
        val mode = "Release"
        val frameworks = arrayOf("iosArm64", "iosX64", "iosArm32")
            .map { kotlin.targets.getByName<KotlinNativeTarget>(it).binaries.getFramework(mode) }
        inputs.property("mode", mode)
        dependsOn(frameworks.map { it.linkTask })
        doLast { buildXcFramework(frameworks) }
    }
    t
    • 2
    • 14
  • r

    Raul Macías

    08/05/2021, 11:23 AM
    Hello, how can i connect to firestore from the shared module?
    ☝️ 1
    m
    m
    • 3
    • 4
  • k

    Kareem Waleed

    08/05/2021, 2:36 PM
    Hello, any ideas when to expect
    KMM
    to be stable and ready for production ?
    c
    k
    +4
    • 7
    • 7
  • a

    Akram Bensalem

    08/05/2021, 3:00 PM
    Yesterday they announced that "compose multiplatform" reach alpha stage. I retry for the second time to creat a project that work on "Android, desktop and Web" after updating plugin to alpha in IntilijIdea But unfortunately I had problem in both Android and Desktop parts (just the web that worked correctly). ... The problem with the Desktop is "MainKT is not found" And the problem with Android is that Compose libraries are not known. ... So my question is there any one who can teach me how to start a project that work on the 3 platform ?! Because It's obvious that the project that initialise in the default is not working or it missing something that I'm not able to figure out !!! Any help please
    g
    c
    • 3
    • 7
  • m

    Marko Novakovic

    08/05/2021, 3:11 PM
    when I create multiplatform project in Intellij IDEA and I try to run desktop app nothing happens. any suggestions?
    c
    s
    • 3
    • 11
  • c

    Cdev

    08/05/2021, 5:48 PM
    import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
    
    plugins {
        kotlin("multiplatform")
        kotlin("plugin.serialization")
        id("com.android.library")
    }
    
    val iOSProjectName = "MBKMMShared"
    val xcFrameworkPath = "xcframework/" + iOSProjectName + ".xcframework"
    
    tasks.create<Delete>("deleteXcFramework") { delete = setOf(xcFrameworkPath) }
    
    
    
    kotlin {
        val serializationVersion = "1.1.0"
        val koTestVersion = "4.4.3"
    
        android()
    
        iosArm32()
    
        ios {
            binaries {
                framework {
                    baseName = "MBKMMShared"
                }
            }
        }
    
        sourceSets {
            val commonMain by getting {
                dependencies {
                    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
                }
            }
            val commonTest by getting {
                dependencies {
                    implementation(kotlin("test-common"))
                    implementation(kotlin("test-annotations-common"))
                    implementation("io.kotest:kotest-property:$koTestVersion")
                    implementation("io.kotest:kotest-assertions-core:$koTestVersion")
                }
            }
            val androidMain by getting
            val androidTest by getting {
                dependencies {
                    implementation(kotlin("test-junit"))
                    implementation("junit:junit:4.13")
                }
            }
            //val iosMain by getting
            val iosTest by getting
    
            val iosX64Main by sourceSets.getting
            val iosArm64Main by sourceSets.getting
            val iosArm32Main by sourceSets.getting
    
            val iosMain by sourceSets.getting {
                dependsOn(commonMain)
                iosX64Main.dependsOn(this)
                iosArm64Main.dependsOn(this)
                iosArm32Main.dependsOn(this)
            }
        }
    }
    
    android {
        compileSdkVersion(30)
        defaultConfig {
            minSdkVersion(21)
            targetSdkVersion(30)
        }
        sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    }
    
    val packForXcode by tasks.creating(Sync::class) {
        group = "build"
        val mode = System.getenv("CONFIGURATION") ?: "RELEASE" // TODO Fix before release
        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(projectDir, "xcode-frameworks")
        from({ framework.outputDirectory })
        into(targetDir)
    }
    tasks.getByName("build").dependsOn(packForXcode)
    
    
    
    
    fun Task.buildXcFramework(frameworks: List<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>) {
        val buildArgs: () -> List<String> = {
            val arguments = mutableListOf("-create-xcframework")
            frameworks.forEach {
                arguments += "-framework"
                arguments += "${it.outputDirectory}/" + iOSProjectName + ".framework"
            }
            arguments += "-output"
            arguments += xcFrameworkPath
            arguments
        }
        exec {
            executable = "xcodebuild"
            args = buildArgs()
        }
    }
    
    val buildXcFramework by tasks.registering {
        dependsOn("deleteXcFramework")
        group = "build"
        val mode = "Release"
        val frameworks = arrayOf("iosArm32", "iosArm64", "iosX64")
            .map { kotlin.targets.getByName<KotlinNativeTarget>(it).binaries.getFramework(mode) }
        inputs.property("mode", mode)
        dependsOn(frameworks.map { it.linkTask })
        doLast { buildXcFramework(frameworks) }
    }
    :thread-please: 3
    • 1
    • 1
Powered by Linen
Title
c

Cdev

08/05/2021, 5:48 PM
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
}

val iOSProjectName = "MBKMMShared"
val xcFrameworkPath = "xcframework/" + iOSProjectName + ".xcframework"

tasks.create<Delete>("deleteXcFramework") { delete = setOf(xcFrameworkPath) }



kotlin {
    val serializationVersion = "1.1.0"
    val koTestVersion = "4.4.3"

    android()

    iosArm32()

    ios {
        binaries {
            framework {
                baseName = "MBKMMShared"
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("io.kotest:kotest-property:$koTestVersion")
                implementation("io.kotest:kotest-assertions-core:$koTestVersion")
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13")
            }
        }
        //val iosMain by getting
        val iosTest by getting

        val iosX64Main by sourceSets.getting
        val iosArm64Main by sourceSets.getting
        val iosArm32Main by sourceSets.getting

        val iosMain by sourceSets.getting {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosArm32Main.dependsOn(this)
        }
    }
}

android {
    compileSdkVersion(30)
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(30)
    }
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "RELEASE" // TODO Fix before release
    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(projectDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)




fun Task.buildXcFramework(frameworks: List<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>) {
    val buildArgs: () -> List<String> = {
        val arguments = mutableListOf("-create-xcframework")
        frameworks.forEach {
            arguments += "-framework"
            arguments += "${it.outputDirectory}/" + iOSProjectName + ".framework"
        }
        arguments += "-output"
        arguments += xcFrameworkPath
        arguments
    }
    exec {
        executable = "xcodebuild"
        args = buildArgs()
    }
}

val buildXcFramework by tasks.registering {
    dependsOn("deleteXcFramework")
    group = "build"
    val mode = "Release"
    val frameworks = arrayOf("iosArm32", "iosArm64", "iosX64")
        .map { kotlin.targets.getByName<KotlinNativeTarget>(it).binaries.getFramework(mode) }
    inputs.property("mode", mode)
    dependsOn(frameworks.map { it.linkTask })
    doLast { buildXcFramework(frameworks) }
}
:thread-please: 3
Moved to thread. I also tried to use this (https://github.com/ge-org/multiplatform-swiftpackage) to create an XCFramework with both arm64 and arm32 and still can't get the arm32 part to work.
View count: 23