This library provides convenient methods and common implementations to simplify
concurrency/multi-threading in Kotlin Multiplatform projects for iOS and Android.
By default, KMP plugin cannot create universal binaries ( a single klib which works on both X64 and Arm64). Each platform must be configured with a preset and a unique target name. However, the code base for each platform is same (at least, at the moment). So there is no reason to create different source sets for each of them. Therefore, a common source set iosMain and iosTest is configured (without any target preset) and the platform specific code targets simply used this common source set.
However, this poses a problem because now, IntelliJ does not know that iosMain and iosTest are really two ios source sets. It thinks of them as a generic source set and you lose all the code completion. The code will compile fine, its just that IntelliJ will not know about it as you are typing.
As a fix to this problem, by default, iosMain and iosTest source sets are created for either X64 or Arm64 depending on where your code is running. So Intellij now gives you are all the good features. Then, to upload klibs for each platform separately, :release task
Creates iosMain and iosTest as generic resources (doesn't tie them to any platform).
Creates two new targets iosX64 and iosArm64.
Connects their source sets to iosMain and iosTest.
Build Plugin
Each sub project uses SuparnaturalPlugin defined in buildSrc. It provides a very simple api
to configure a new project to avoid a lot of boilerplate code.
The properties of suparnatural extension are copied over to cocoapods and bintray by default. Bintray properties can be overridden in its in closure if needed.
The bintray credentials are supplied from .local.build.gradle.kts by setting 3 extra properties on the project. For example
subprojects {
this.extra["bintrayUsername"] = "bintray username"
this.extra["bintrayApiKey"] = "bintray api key"
this.extra["bintrayRepository"] = "bintray repository name (just the name)"
}
Applying this plugin creates following target names with source sets and some default libs if applicable
SourceSet
Dependencies
Configuration
commonMain
stdlib-common
Always created
commonTest
test-common, test-annotations-common
Always created
jvmMain
stdlib
supportsJvm = true
jvmTest
test, test-junit
supportsJvm = true
androidMain
stdlib
supportsAndroid = true
androidTest
test, test-junit
supportsAndroid = true
iosMain
none
supportsIos = true*
iosTest
none
supportsIos = true*
iosX64Main
none
supportsIos = true*
iosX64Test
none
supportsIos = true*
iosArm64Main
none
supportsIos = true*
iosArm64Test
none
supportsIos = true*
The iOS targets are special because they are not always created the same. The iosX64Main, iosX64Test, iosArm64Main and iosArm64Test targets are created only when gradle task :release is run. This creates one artifact for each platform (X64 and Arm64) and uploads to bintray. Otherwise, by default, only iosMain and iosTest targets are created during development depending on whether the code is running in the simulator or a real device. This is done so because otherwise IntelliJ does not know as to which platform does iosMain and iosTest belong to while developing and it cannot offer code completion. This step is required only when publishing klibs. If you are using the the framework directly using cocoapods, then don't worry about it.
The :release gradle task performs clean, build, connectedAndroidTest, iosTest, publishToMavenLocal and bintrayUpload tasks in this strict order.
The dependencies for each source set are split into two kinds defaults and additional. By default, some dependencies are configured for the source sets out of the box (as mentioned in the table above). To disable all of them, use disable() or to disable a single default dependency, set its value to false.
Additional dependencies can be added using under additional block.
The iosX64Main, iosX64Test, iosArm64Main and iosArm64Test dependencies are shared with iosMain and iosTest targets. For example, if you are building locally or using cocoapods in a simulator, all dependencies defined in iosX64Main will be used in iosMain target and same thing happens for the real device as well.
Following is an example of project configuration used by fs module.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
请发表评论