From c2a4949025a7e6d075d90dd719286e8ce5670d01 Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Wed, 1 Oct 2025 16:18:06 +0200 Subject: [PATCH 1/6] update: new Android KMP library Gradle logic --- .../multiplatform-publish-lib-setup.md | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index c174febb..9b529e98 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -132,7 +132,7 @@ This guarantees that all artifacts are available and correctly referenced. Kotlin/Native supports cross-compilation, allowing any host to produce the necessary `.klib` artifacts. However, there are still some limitations you should keep in mind. -**Compilation for Apple targets** +### Compilation for Apple targets You can use any host to produce artifacts for projects with Apple targets. However, you still need to use a Mac machine if: @@ -141,22 +141,36 @@ However, you still need to use a Mac machine if: * You have [CocoaPods integration](multiplatform-cocoapods-overview.md) set up in your project. * You need to build or test [final binaries](multiplatform-build-native-binaries.md) for Apple targets. -**Duplicating publications** +### Duplicating publications -To avoid any issues during publication, publish all artifacts from a single host to avoid duplicating publications in the -repository. Maven Central, for example, explicitly forbids duplicate publications and fails the process. +To avoid duplicating publications in the repository, publish all artifacts from a single host. +Maven Central, for example, explicitly forbids duplicate publications and fails the process when they are created. ## Publish an Android library To publish an Android library, you need to provide additional configuration. -By default, no artifacts of an Android library are published. To publish artifacts produced by a set of Android [build variants](https://developer.android.com/build/build-variants), -specify the variant names in the Android target block in the `shared/build.gradle.kts` file: +By default, no artifacts of an Android library are published. To publish artifacts them, add the `androidLibrary {}` block +to the `shared/build.gradle.kts` file, and use the publication DSL as is usual for the `android {}` block. +For example: ```kotlin kotlin { androidTarget { - publishLibraryVariants("release") + namespace = "org.example.library" + compileSdk = libs.versions.android.compileSdk.get().toInt() + minSdk = libs.versions.android.minSdk.get().toInt() + + // Enables Java compilation support + withJava() + + compilations.configureEach { + compilerOptions.configure { + jvmTarget.set( + JvmTarget.JVM_11 + ) + } + } } } ``` @@ -249,10 +263,11 @@ kotlin.publishJvmEnvironmentAttribute=false ## Promote your library -Your library can be featured on the [JetBrains' search platform](https://klibs.io/). +Your library can be featured on the [JetBrains' multiplatform library catalog](https://klibs.io/). It's designed to make it easy to look for Kotlin Multiplatform libraries based on their target platforms. -Libraries that meet the criteria are added automatically. For more information on how to add your library, see [FAQ](https://klibs.io/faq). +Libraries that meet the criteria are added automatically. For more information on how to make sure your library appears in the catalog, +see [FAQ](https://klibs.io/faq). ## What's next From c76234730e74a34642e90fc2aa4a50dc596488fd Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Wed, 1 Oct 2025 16:21:07 +0200 Subject: [PATCH 2/6] fix: block name --- topics/development/multiplatform-publish-lib-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index 9b529e98..519844aa 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -156,7 +156,7 @@ For example: ```kotlin kotlin { - androidTarget { + androidLibrary { namespace = "org.example.library" compileSdk = libs.versions.android.compileSdk.get().toInt() minSdk = libs.versions.android.minSdk.get().toInt() From a44a2efe5c6747493b1897437801f2ecddb4b6af Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Wed, 1 Oct 2025 16:31:33 +0200 Subject: [PATCH 3/6] update: remove the flavors section irrelevant for the new Android KMP library plugin --- .../multiplatform-publish-lib-setup.md | 46 +++++-------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index 519844aa..87035c21 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -149,9 +149,17 @@ Maven Central, for example, explicitly forbids duplicate publications and fails ## Publish an Android library To publish an Android library, you need to provide additional configuration. +By default, no artifacts of an Android library are published. -By default, no artifacts of an Android library are published. To publish artifacts them, add the `androidLibrary {}` block -to the `shared/build.gradle.kts` file, and use the publication DSL as is usual for the `android {}` block. +> This section assumes that you are using the Android Gradle Library Plugin. +> For a guide on setting up the plugin, or on migrating from the legacy `com.android.library` plugin, +> see the [Set up the Android Gradle Library Plugin](https://developer.android.com/kotlin/multiplatform/plugin#migrate) +> page in the Android documentation. +> +{style="note"} + +To publish artifacts, add the `androidLibrary {}` block +to the `shared/build.gradle.kts` file, and configure the publication using the KMP DSL. For example: ```kotlin @@ -161,7 +169,8 @@ kotlin { compileSdk = libs.versions.android.compileSdk.get().toInt() minSdk = libs.versions.android.minSdk.get().toInt() - // Enables Java compilation support + // Enables Java compilation support. + // This improves build times when Java compilation is not needed withJava() compilations.configureEach { @@ -175,37 +184,6 @@ kotlin { } ``` -The example works for Android libraries without [product flavors](https://developer.android.com/build/build-variants#product-flavors). -For a library with product flavors, the variant names also contain the flavors, like `fooBarDebug` or `fooBarRelease`. - -The default publishing setup is as follows: -* If the published variants have the same build type (for example, all of them are `release` or`debug`), - they will be compatible with any consumer build type. -* If the published variants have different build types, then only the release variants will be compatible - with consumer build types that are not among the published variants. All other variants (such as `debug`) - will only match the same build type on the consumer side, unless the consumer project specifies the - [matching fallbacks](https://developer.android.com/reference/tools/gradle-api/4.2/com/android/build/api/dsl/BuildType). - -If you want to make every published Android variant compatible with only the same build type used by the library consumer, -set this Gradle property: `kotlin.android.buildTypeAttribute.keep=true`. - -You can also publish variants grouped by the product flavor, so that the outputs of the different build types are placed -in a single module, with the build type becoming a classifier for the artifacts (the release build type is still published -with no classifier). This mode is disabled by default and can be enabled as follows in the `shared/build.gradle.kts` file: - -```kotlin -kotlin { - androidTarget { - publishLibraryVariantsGroupedByFlavor = true - } -} -``` - -> It is not recommended that you publish variants grouped by the product flavor in case they have different dependencies, -> as those will be merged into one dependency list. -> -{style="note"} - ## Disable sources publication By default, the Kotlin Multiplatform Gradle plugin publishes sources for all the specified targets. However, From 952d23ebddcf7a3c9d6ca61931907831d0cec406 Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Thu, 2 Oct 2025 12:09:53 +0200 Subject: [PATCH 4/6] update: mention test configuration migration as well --- .../multiplatform-publish-lib-setup.md | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index 87035c21..954dbd08 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -184,6 +184,43 @@ kotlin { } ``` +Note that the Android Gradle Library plugin doesn't support product flavors and build variants, streamlining configuration. +One of the consequences is that you need to opt in to create test source sets and configurations, for example: + +```kotlin +kotlin { + androidLibrary { + // ... + + // Opt in to enable and configure host-side (unit) tests + withHostTestBuilder {}.configure {} + + // Opt in to enable device tests, specifying the source set name + withDeviceTestBuilder { + sourceSetTreeName = "test" + } + + // ... + } +} +``` + +Before, running tests with a GitHub action, for example, required mentioning debug and release variants: + +```yaml +- target: testDebugUnitTest + os: ubuntu-latest +- target: testReleaseUnitTest + os: ubuntu-latest +``` + +With the Android Gradle Library plugin, you need to specify only the general target with the source set name: + +```yaml +- target: testAndroidHostTest + os: ubuntu-latest +``` + ## Disable sources publication By default, the Kotlin Multiplatform Gradle plugin publishes sources for all the specified targets. However, From 8ede33cbc03534a85f26b73649cf16c0d9b3a0f4 Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Mon, 6 Oct 2025 19:03:57 +0200 Subject: [PATCH 5/6] fix: tw review Co-authored-by: ElviraMustafina <57905309+ElviraMustafina@users.noreply.github.com> --- topics/development/multiplatform-publish-lib-setup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index 954dbd08..4046a6cf 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -144,7 +144,7 @@ However, you still need to use a Mac machine if: ### Duplicating publications To avoid duplicating publications in the repository, publish all artifacts from a single host. -Maven Central, for example, explicitly forbids duplicate publications and fails the process when they are created. +For example, Maven Central explicitly forbids duplicate publications and fails the process if they are created. ## Publish an Android library @@ -185,7 +185,7 @@ kotlin { ``` Note that the Android Gradle Library plugin doesn't support product flavors and build variants, streamlining configuration. -One of the consequences is that you need to opt in to create test source sets and configurations, for example: +As a result, you need to opt in to create test source sets and configurations. For example: ```kotlin kotlin { From 918b2a65114a4e1aab52245e230c15e75507b52c Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Mon, 6 Oct 2025 19:06:08 +0200 Subject: [PATCH 6/6] fix: tw review --- topics/development/multiplatform-publish-lib-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/development/multiplatform-publish-lib-setup.md b/topics/development/multiplatform-publish-lib-setup.md index 4046a6cf..94bdba38 100644 --- a/topics/development/multiplatform-publish-lib-setup.md +++ b/topics/development/multiplatform-publish-lib-setup.md @@ -205,7 +205,7 @@ kotlin { } ``` -Before, running tests with a GitHub action, for example, required mentioning debug and release variants: +Previously, running tests with a GitHub action, for example, required specifying debug and release variants separately: ```yaml - target: testDebugUnitTest