I updated the Kotlin version of my project then th...
# multiplatform
j
I updated the Kotlin version of my project then the gradle shows this warning. It tells me to replace
ios
with a function that looks like doing something complete different. This is a simple multiplatform library that is mostly common-only, so I want to support as many platform as possible. Is there a simple way to do this now?
I looked at the document and found
The plugin sets up those source sets automatically based on the targets specified in your project.
But here I'm using
ios
to specify the target. Which should I replace?
l
Something like
iosArm64
? I've never used iphone, but that's what this page appears to suggest: https://kotlinlang.org/docs/multiplatform-hierarchy.html
j
Is there a simple way to make my library work in every target, since it use common kotlin only (with a few specialize just for JVM).
l
You need to declare which platforms are supported and build for those.
j
Ok. I find a solution by looking at the how
kotlinx-coroutines-core
does. 1. Add all platforms. Can reference this file. 2. Programmically configure the dependency, so I don't have to configure each one by one. Like this.
j
Beginning in Kotlin 1.9.20, the default hierarchy template is applied to your project by default. As long as you don't manually declare a
dependsOn
relationship between any source sets, you don't even have to call
applyDefaultHierarchyTemplate
. This simplifies creating source set dependencies and intermediate source sets by automatically creating the default hierarchy for you for all targets you declare. So you really only need step 1. Declare all the targets your code supports. You probably don't need to target Android directly, since it can consume the JVM artifact, unless you need Android-specific APIs. So you can declare
jvm
,
js
, and all native targets.
👍 1