From a158c0358fed11e60c6a3ca94ad9dde105dad2f9 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Tue, 3 Feb 2026 17:44:49 +0700 Subject: [PATCH 1/7] Update version in readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 771da189..853f5a5c 100755 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:resources-generator:0.25.2" + classpath "dev.icerock.moko:resources-generator:0.26.0" } } @@ -83,10 +83,10 @@ project build.gradle apply plugin: "dev.icerock.mobile.multiplatform-resources" dependencies { - commonMainApi("dev.icerock.moko:resources:0.25.1") - commonMainApi("dev.icerock.moko:resources-compose:0.25.2") // for compose multiplatform + commonMainApi("dev.icerock.moko:resources:0.26.0") + commonMainApi("dev.icerock.moko:resources-compose:0.26.0") // for compose multiplatform - commonTestImplementation("dev.icerock.moko:resources-test:0.25.2") + commonTestImplementation("dev.icerock.moko:resources-test:0.26.0") } multiplatformResources { @@ -133,7 +133,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui ``` framework { - export("dev.icerock.moko:resources:0.25.1") + export("dev.icerock.moko:resources:0.26.0") export("dev.icerock.moko:graphics:0.10.0") // toUIColor here } ``` From c22dc9ffaeb45d60554c3c1c8689356ca9e9b760 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 16:46:31 +0700 Subject: [PATCH 2/7] #864 fixed android tests sourceSet configuration --- .../gradle/extra/mokoResourcesGenTask.kt | 4 +++- ...ndroidMultiplatformLibraryTargetSources.kt | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt index e3ff9f47..a2fb3cdf 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt @@ -121,7 +121,9 @@ private fun registerGenerateTask( "androidTest", "androidInstrumentedTest", "main", - "test" + "test", + "androidHostTest", + "androidDeviceTest" ) } } diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt index 2af559aa..d72fe6e7 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt @@ -7,6 +7,9 @@ package dev.icerock.gradle.generator.platform.android import com.android.build.api.dsl.KotlinMultiplatformAndroidCompilation import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget import com.android.build.api.extension.impl.CurrentAndroidGradlePluginVersion +import com.android.build.api.variant.Component +import com.android.build.api.variant.HasAndroidTest +import com.android.build.api.variant.HasUnitTest import com.android.build.api.variant.KotlinMultiplatformAndroidComponentsExtension import com.android.build.api.variant.KotlinMultiplatformAndroidVariant import com.android.build.api.variant.Variant @@ -101,11 +104,17 @@ private fun variantHandler( ) { if (compilation !is KotlinMultiplatformAndroidCompilation) return - if (variant.name == compilation.componentName) { - variant.sources.addKmpAndroidGeneratedSources(genTaskProvider) + val allComponents: List = listOf(variant) + variant.nestedComponents - genTaskProvider.configure { - it.androidSourceSetName.set(variant.name) - } + val matchingComponent: Component = allComponents.find { component -> + component.name == compilation.componentName || + compilation.componentName.endsWith(component.name, ignoreCase = true) || + component.name == compilation.name + } ?: return + + variant.sources.addKmpAndroidGeneratedSources(genTaskProvider) + + genTaskProvider.configure { + it.androidSourceSetName.set(matchingComponent.name) } } From d5686f85d4367c3b515d7be954da44da68017637 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 16:54:04 +0700 Subject: [PATCH 3/7] #864 added tests in new agp plugin sample --- .../gradle/libs.versions.toml | 2 +- .../gradle-agp-9-sample/settings.gradle.kts | 3 +- .../shared/build.gradle.kts | 8 +++ .../moko-resources/base/plurals-test.xml | 32 ++++++++++ .../moko-resources/ru/plurals-test.xml | 40 ++++++++++++ .../library/BaseStringResourceTests.kt | 39 ++++++++++++ .../icerock/library/PluralResourceEnTests.kt | 63 +++++++++++++++++++ .../icerock/library/PluralResourceRuTests.kt | 63 +++++++++++++++++++ .../icerock/library/StringResourceEnTests.kt | 18 ++++++ .../icerock/library/StringResourceRuTests.kt | 18 ++++++ .../shared/test-utils/build.gradle.kts | 53 ++++++++++++++++ .../src/androidMain/kotlin/BaseUnitTest.kt | 11 ++++ .../src/androidMain/kotlin/StringDescExt.kt | 12 ++++ .../src/commonMain/kotlin/BaseUnitTest.kt | 6 ++ .../src/commonMain/kotlin/StringDescExt.kt | 7 +++ .../src/iosMain/kotlin/BaseUnitTest.kt | 5 ++ .../src/iosMain/kotlin/StringDescExt.kt | 7 +++ 17 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/base/plurals-test.xml create mode 100644 samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/ru/plurals-test.xml create mode 100644 samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/BaseStringResourceTests.kt create mode 100644 samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt create mode 100644 samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt create mode 100644 samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceEnTests.kt create mode 100644 samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceRuTests.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/build.gradle.kts create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/BaseUnitTest.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/StringDescExt.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/BaseUnitTest.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/StringDescExt.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/BaseUnitTest.kt create mode 100644 samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/StringDescExt.kt diff --git a/samples/gradle-agp-9-sample/gradle/libs.versions.toml b/samples/gradle-agp-9-sample/gradle/libs.versions.toml index 1b1c37f5..e365d4e2 100644 --- a/samples/gradle-agp-9-sample/gradle/libs.versions.toml +++ b/samples/gradle-agp-9-sample/gradle/libs.versions.toml @@ -20,4 +20,4 @@ androidMultiplatfrom = { id = "com.android.kotlin.multiplatform.library", versio kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } -multiplatformResources = { id = "dev.icerock.mobile.multiplatform-resources", version = "0.26.0" } +multiplatformResources = { id = "dev.icerock.mobile.multiplatform-resources", version = "0.26.1" } diff --git a/samples/gradle-agp-9-sample/settings.gradle.kts b/samples/gradle-agp-9-sample/settings.gradle.kts index ba4e12e9..3177b601 100644 --- a/samples/gradle-agp-9-sample/settings.gradle.kts +++ b/samples/gradle-agp-9-sample/settings.gradle.kts @@ -26,4 +26,5 @@ dependencyResolutionManagement { rootProject.name = "gradle9_sample" include(":androidApp") -include(":shared") \ No newline at end of file +include(":shared") +include(":shared:test-utils") diff --git a/samples/gradle-agp-9-sample/shared/build.gradle.kts b/samples/gradle-agp-9-sample/shared/build.gradle.kts index 26e33a1e..0c95e26b 100644 --- a/samples/gradle-agp-9-sample/shared/build.gradle.kts +++ b/samples/gradle-agp-9-sample/shared/build.gradle.kts @@ -9,6 +9,12 @@ kotlin { namespace = "com.gradle9sample.android.library" compileSdk = 36 minSdk = 26 + + withHostTest { + isIncludeAndroidResources = true + } + + withDeviceTest { } } listOf( @@ -29,6 +35,8 @@ kotlin { } commonTest.dependencies { implementation(libs.kotlin.test) + implementation(moko.resourcesTest) + implementation(project(":shared:test-utils")) } } diff --git a/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/base/plurals-test.xml b/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/base/plurals-test.xml new file mode 100644 index 00000000..3443d601 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/base/plurals-test.xml @@ -0,0 +1,32 @@ + + + + zero + one + two + other + + + %.2d zero + %.2d one + %.2d two + %.2d other + + + zero %% + %s one + %s two + %s other + + + + plurals-interop: zero + plurals-interop: one + plurals-interop: two + plurals-interop: other + + + one + other + + diff --git a/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/ru/plurals-test.xml b/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/ru/plurals-test.xml new file mode 100644 index 00000000..69351a7d --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonMain/moko-resources/ru/plurals-test.xml @@ -0,0 +1,40 @@ + + + + ноль + один + два + несколько + много + другое + + + + plurals-interop: ноль + plurals-interop: один + plurals-interop: два + plurals-interop: несколько + plurals-interop: много + plurals-interop: другое + + + %.2d zero + %.2d one + %.2d few + %.2d many + %.2d two + %.2d other + + + zero %% + %s one + %s few + %s many + %s two + %s other + + + один + другое + + diff --git a/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/BaseStringResourceTests.kt b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/BaseStringResourceTests.kt new file mode 100644 index 00000000..19cad93c --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/BaseStringResourceTests.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerock.library + +import BaseUnitTest +import dev.icerock.moko.resources.desc.StringDesc +import getString +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import kotlin.test.BeforeTest +import kotlin.test.assertEquals + +abstract class BaseStringResourceTests( + private val locale: String +) : BaseUnitTest() { + + @BeforeTest + fun setup() { + StringDesc.localeType = StringDesc.LocaleType.Custom(locale) + } + + @OptIn(ExperimentalCoroutinesApi::class) + protected fun stringTest(expected: String, actual: StringDesc) = runTest { + assertEquals( + expected = expected, + actual = actual.getString() + ) + } + + @OptIn(ExperimentalCoroutinesApi::class) + protected fun pluralTest(expected: String, actual: StringDesc) = runTest { + assertEquals( + expected = expected, + actual = actual.getString() + ) + } +} diff --git a/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt new file mode 100644 index 00000000..371c2b70 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceEnTests.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerock.library + +import app.gradle9sample.library.MR +import dev.icerock.moko.resources.desc.desc +import kotlin.test.Ignore +import kotlin.test.Test + +class PluralResourceEnTests : BaseStringResourceTests("en") { + + @Ignore + @Test + fun checkSimplePlural0() = pluralTest( + expected = "zero", + actual = MR.plurals.test_plural.desc(0) + ) + + @Test + fun checkSimplePlural1() = pluralTest( + expected = "one", + actual = MR.plurals.test_plural.desc(1) + ) + + @Ignore + @Test + fun checkSimplePlural2() = pluralTest( + expected = "two", + actual = MR.plurals.test_plural.desc(2) + ) + + @Test + fun checkSimplePlural3() = pluralTest( + expected = "other", + actual = MR.plurals.test_plural.desc(3) + ) + + @Test + fun checkSimplePlural40() = pluralTest( + expected = "other", + actual = MR.plurals.test_plural.desc(40) + ) + + @Test + fun checkSimplePlural22() = pluralTest( + expected = "other", + actual = MR.plurals.test_plural.desc(22) + ) + + @Test + fun checkPluralFallback1() = pluralTest( + expected = "one", + actual = MR.plurals.test_plural_fallback.desc(1) + ) + + @Test + fun checkPluralFallback2() = pluralTest( + expected = "other", + actual = MR.plurals.test_plural_fallback.desc(2) + ) +} diff --git a/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt new file mode 100644 index 00000000..861a51ff --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/PluralResourceRuTests.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerock.library + +import app.gradle9sample.library.MR +import dev.icerock.moko.resources.desc.desc +import kotlin.test.Ignore +import kotlin.test.Test + +class PluralResourceRuTests : BaseStringResourceTests("ru") { + + @Ignore + @Test + fun checkSimplePlural0() = pluralTest( + expected = "ноль", + actual = MR.plurals.test_plural.desc(0) + ) + + @Test + fun checkSimplePlural1() = pluralTest( + expected = "один", + actual = MR.plurals.test_plural.desc(1) + ) + + @Ignore + @Test + fun checkSimplePlural2() = pluralTest( + expected = "два", + actual = MR.plurals.test_plural.desc(2) + ) + + @Test + fun checkSimplePlural3() = pluralTest( + expected = "несколько", + actual = MR.plurals.test_plural.desc(3) + ) + + @Test + fun checkSimplePlural40() = pluralTest( + expected = "много", + actual = MR.plurals.test_plural.desc(40) + ) + + @Test + fun checkSimplePlural22() = pluralTest( + expected = "несколько", + actual = MR.plurals.test_plural.desc(22) + ) + + @Test + fun checkPluralFallback1() = pluralTest( + expected = "один", + actual = MR.plurals.test_plural_fallback.desc(1) + ) + + @Test + fun checkPluralFallback2() = pluralTest( + expected = "другое", + actual = MR.plurals.test_plural_fallback.desc(2) + ) +} diff --git a/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceEnTests.kt b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceEnTests.kt new file mode 100644 index 00000000..9c430d65 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceEnTests.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerock.library + +import app.gradle9sample.library.MR +import dev.icerock.moko.resources.desc.desc +import kotlin.test.Test + +class StringResourceEnTests : BaseStringResourceTests("en") { + + @Test + fun checkSimpleString() = stringTest( + expected = "Second value for Test", + actual = MR.strings.test.desc() + ) +} diff --git a/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceRuTests.kt b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceRuTests.kt new file mode 100644 index 00000000..96011367 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/src/commonTest/kotlin/com/icerock/library/StringResourceRuTests.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.icerock.library + +import app.gradle9sample.library.MR +import dev.icerock.moko.resources.desc.desc +import kotlin.test.Test + +class StringResourceRuTests : BaseStringResourceTests("ru") { + + @Test + fun checkSimpleString() = stringTest( + expected = "Тестовая строка", + actual = MR.strings.test.desc() + ) +} diff --git a/samples/gradle-agp-9-sample/shared/test-utils/build.gradle.kts b/samples/gradle-agp-9-sample/shared/test-utils/build.gradle.kts new file mode 100644 index 00000000..d8c68683 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/build.gradle.kts @@ -0,0 +1,53 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("com.android.kotlin.multiplatform.library") + id("org.jetbrains.kotlin.multiplatform") +} + +// disable android lint for test utils (no need here) +tasks.matching { it.name.startsWith("lint") }.configureEach { enabled = false } + +kotlin { + applyDefaultHierarchyTemplate() + + androidLibrary { + namespace = "com.gradle9sample.library.testutils" + compileSdk = 36 + minSdk = 26 + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "shared" + isStatic = true + export(moko.resources) + } + } + + sourceSets { + val commonMain by getting { + dependencies { + api("org.jetbrains.kotlin:kotlin-test:2.2.10") + api("org.jetbrains.kotlin:kotlin-test-annotations-common:2.2.10") + api("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") + api(moko.resourcesTest) + } + } + + val androidMain by getting { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-junit:2.2.10") + api("androidx.test:core:1.5.0") + api("org.robolectric:robolectric:4.15.1") + api("junit:junit:4.13.2") + } + } + } +} diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/BaseUnitTest.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/BaseUnitTest.kt new file mode 100644 index 00000000..c8cd0f9b --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/BaseUnitTest.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = intArrayOf(33)) +public actual abstract class BaseUnitTest diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/StringDescExt.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/StringDescExt.kt new file mode 100644 index 00000000..c07fa39b --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/androidMain/kotlin/StringDescExt.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import dev.icerock.moko.resources.desc.StringDesc + +public actual suspend fun StringDesc.getString(): String { + val context: Context = ApplicationProvider.getApplicationContext() + return toString(context) +} diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/BaseUnitTest.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/BaseUnitTest.kt new file mode 100644 index 00000000..32fd007b --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/BaseUnitTest.kt @@ -0,0 +1,6 @@ +/* + * Copyright 2026 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +@Suppress("EmptyDefaultConstructor") +expect abstract class BaseUnitTest() diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/StringDescExt.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/StringDescExt.kt new file mode 100644 index 00000000..d5e7e1b7 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/commonMain/kotlin/StringDescExt.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2026 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import dev.icerock.moko.resources.desc.StringDesc + +expect suspend fun StringDesc.getString(): String diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/BaseUnitTest.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/BaseUnitTest.kt new file mode 100644 index 00000000..ceee100d --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/BaseUnitTest.kt @@ -0,0 +1,5 @@ +/* + * Copyright 2026 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +actual abstract class BaseUnitTest diff --git a/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/StringDescExt.kt b/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/StringDescExt.kt new file mode 100644 index 00000000..ca1d72a7 --- /dev/null +++ b/samples/gradle-agp-9-sample/shared/test-utils/src/iosMain/kotlin/StringDescExt.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2026 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import dev.icerock.moko.resources.desc.StringDesc + +actual suspend fun StringDesc.getString(): String = localized() From 5b599fe612b6d56e307e98175b6a617fe5812103 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 17:00:54 +0700 Subject: [PATCH 4/7] #864 updated check scripts --- .github/compilation-check-source.yml | 21 +++++++++ .github/workflows/compilation-check.yml | 60 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/.github/compilation-check-source.yml b/.github/compilation-check-source.yml index 0b2c6e82..96df0b9f 100644 --- a/.github/compilation-check-source.yml +++ b/.github/compilation-check-source.yml @@ -353,3 +353,24 @@ jobs: - *publish_test_report - *upload_reports + + check-gradle-agp-9-sample: + runs-on: ${{ matrix.os }} + strategy: + matrix: + <<: *runner_matrix + needs: build-library + + steps: + - *checkout + - *setup_jdk + - *setup_gradle + - *cache_konan + - *download_maven + + - name: Sample - gradle-agp-9-sample + run: cd samples/gradle-agp-9-sample && ./local-check.sh + shell: bash + + - *publish_test_report + - *upload_reports diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index 0332c927..deea4ed3 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -56,6 +56,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-android-mpp-app: runs-on: ${{ matrix.os }} strategy: @@ -102,6 +103,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-auto-manifest: runs-on: ${{ matrix.os }} strategy: @@ -148,6 +150,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-compose-jvm-app: runs-on: ${{ matrix.os }} strategy: @@ -194,6 +197,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-resources-gallery: runs-on: ${{ matrix.os }} strategy: @@ -240,6 +244,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-default-hierarchy-resources-gallery-mobile: runs-on: ${{ matrix.os }} strategy: @@ -286,6 +291,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-ios-static-xcframework: runs-on: macOS-latest needs: build-library @@ -326,6 +332,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-ios-cocoapods-static-framework: runs-on: macOS-latest needs: build-library @@ -366,6 +373,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-kotlin-ios-app: runs-on: macOS-latest needs: build-library @@ -406,6 +414,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-sample-compose-resources-gallery: runs-on: ${{ matrix.os }} strategy: @@ -452,6 +461,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-kotlin-2-sample: runs-on: ${{ matrix.os }} strategy: @@ -498,6 +508,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-kotlin-2-dynamic-sample: runs-on: ${{ matrix.os }} strategy: @@ -544,6 +555,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-kotlin-2-tests: runs-on: ${{ matrix.os }} strategy: @@ -591,6 +603,7 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + check-cm-resources-sample: runs-on: ${{ matrix.os }} strategy: @@ -637,3 +650,50 @@ jobs: with: name: code-coverage-report-${{ github.job }}-${{ matrix.os }} path: "**/build/reports/**/*" + + check-gradle-agp-9-sample: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - macOS-latest + - windows-latest + - ubuntu-latest + needs: build-library + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: zulu + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 + with: + cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != + 'refs/heads/develop' }} + - name: Cache .konan + uses: actions/cache@v4 + with: + path: ~/.konan + key: ${{ matrix.os }}-konan-${{ hashFiles('**/*.gradle*', 'gradle/**/*') }} + - name: Download maven artifacts + uses: actions/download-artifact@v4 + with: + name: maven + path: ~/.m2/repository/dev/icerock + - name: Sample - gradle-agp-9-sample + run: cd samples/gradle-agp-9-sample && ./local-check.sh + shell: bash + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: ${{ always() }} + with: + report_paths: "**/build/test-results/**/TEST-*.xml" + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Archive reports + uses: actions/upload-artifact@v4 + if: ${{ always() }} + with: + name: code-coverage-report-${{ github.job }}-${{ matrix.os }} + path: "**/build/reports/**/*" From 6a46049c08d32db4038e0570ecd2aeed9ee15477 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 17:01:22 +0700 Subject: [PATCH 5/7] #864 updated resources patch version --- gradle/moko.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/moko.versions.toml b/gradle/moko.versions.toml index 0e6ef849..316dfd97 100644 --- a/gradle/moko.versions.toml +++ b/gradle/moko.versions.toml @@ -1,5 +1,5 @@ [versions] -resourcesVersion = "0.26.0" +resourcesVersion = "0.26.1" [libraries] resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" } From 62ebb8db0b56930271204f5bfeff8b13f7da2649 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 17:07:39 +0700 Subject: [PATCH 6/7] #864 removed unused imports --- .../android/SetupAndroidMultiplatformLibraryTargetSources.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt index d72fe6e7..c5d071f2 100644 --- a/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt +++ b/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt @@ -8,8 +8,6 @@ import com.android.build.api.dsl.KotlinMultiplatformAndroidCompilation import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget import com.android.build.api.extension.impl.CurrentAndroidGradlePluginVersion import com.android.build.api.variant.Component -import com.android.build.api.variant.HasAndroidTest -import com.android.build.api.variant.HasUnitTest import com.android.build.api.variant.KotlinMultiplatformAndroidComponentsExtension import com.android.build.api.variant.KotlinMultiplatformAndroidVariant import com.android.build.api.variant.Variant From 3d0033447e08270d273c28b4ea6c15fab034a502 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 25 Feb 2026 17:48:36 +0700 Subject: [PATCH 7/7] #864 readme updated --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 853f5a5c..d28d3c4c 100755 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:resources-generator:0.26.0" + classpath "dev.icerock.moko:resources-generator:0.26.1" } } @@ -83,10 +83,10 @@ project build.gradle apply plugin: "dev.icerock.mobile.multiplatform-resources" dependencies { - commonMainApi("dev.icerock.moko:resources:0.26.0") - commonMainApi("dev.icerock.moko:resources-compose:0.26.0") // for compose multiplatform + commonMainApi("dev.icerock.moko:resources:0.26.1") + commonMainApi("dev.icerock.moko:resources-compose:0.26.1") // for compose multiplatform - commonTestImplementation("dev.icerock.moko:resources-test:0.26.0") + commonTestImplementation("dev.icerock.moko:resources-test:0.26.1") } multiplatformResources { @@ -133,7 +133,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui ``` framework { - export("dev.icerock.moko:resources:0.26.0") + export("dev.icerock.moko:resources:0.26.1") export("dev.icerock.moko:graphics:0.10.0") // toUIColor here } ``` @@ -149,6 +149,47 @@ If you have multiple gradle modules and resources stored not in module that comp ``` You should enable moko-resources gradle plugin in `resources` module, that contains resources, AND in `shared` module, that compiles into framework for iOS (same for jvm, JS, macos targets. Only android will works without this). +#### Android Host Tests (Unit Tests) +If you use the new Android Multiplatform Library plugin (`com.android.kotlin.multiplatform.library`), +enabling Android resources for host tests (Unit tests) depends on your AGP version. +This is required for moko-resources to access generated R classes during testing. + +For AGP 8.8.0 and higher +Use the native DSL directly inside the androidLibrary block: + +```kotlin +kotlin { + androidLibrary { + // ... base configuration (namespace, compileSdk, etc.) + + withHostTest { + isIncludeAndroidResources = true + } + + // OR if you use builder for advanced configuration: + /* + withHostTestBuilder { + // your builder config + }.configure { + isIncludeAndroidResources = true + } + */ + } +} +``` +For AGP 8.2.0 - 8.7.x +The withHostTest DSL is not yet available. + +As a workaround, enable Android resources using the legacy android block:: + +```kotlin +android { + testOptions { + unitTests.isIncludeAndroidResources = true + } +} +``` + ### Xcode setup For correct work of plugin tasks you need disable `ENABLE_USER_SCRIPT_SANDBOXING` in .xcodeproj file: