Skip to content

Commit e7ad860

Browse files
authored
Merge pull request #867 from icerockdev/develop
Release 0.26.1
2 parents a158c03 + 3e9ae31 commit e7ad860

23 files changed

Lines changed: 528 additions & 14 deletions

File tree

.github/compilation-check-source.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,24 @@ jobs:
353353

354354
- *publish_test_report
355355
- *upload_reports
356+
357+
check-gradle-agp-9-sample:
358+
runs-on: ${{ matrix.os }}
359+
strategy:
360+
matrix:
361+
<<: *runner_matrix
362+
needs: build-library
363+
364+
steps:
365+
- *checkout
366+
- *setup_jdk
367+
- *setup_gradle
368+
- *cache_konan
369+
- *download_maven
370+
371+
- name: Sample - gradle-agp-9-sample
372+
run: cd samples/gradle-agp-9-sample && ./local-check.sh
373+
shell: bash
374+
375+
- *publish_test_report
376+
- *upload_reports

.github/workflows/compilation-check.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
with:
5757
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
5858
path: "**/build/reports/**/*"
59+
5960
check-sample-android-mpp-app:
6061
runs-on: ${{ matrix.os }}
6162
strategy:
@@ -102,6 +103,7 @@ jobs:
102103
with:
103104
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
104105
path: "**/build/reports/**/*"
106+
105107
check-sample-auto-manifest:
106108
runs-on: ${{ matrix.os }}
107109
strategy:
@@ -148,6 +150,7 @@ jobs:
148150
with:
149151
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
150152
path: "**/build/reports/**/*"
153+
151154
check-sample-compose-jvm-app:
152155
runs-on: ${{ matrix.os }}
153156
strategy:
@@ -194,6 +197,7 @@ jobs:
194197
with:
195198
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
196199
path: "**/build/reports/**/*"
200+
197201
check-sample-resources-gallery:
198202
runs-on: ${{ matrix.os }}
199203
strategy:
@@ -240,6 +244,7 @@ jobs:
240244
with:
241245
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
242246
path: "**/build/reports/**/*"
247+
243248
check-sample-default-hierarchy-resources-gallery-mobile:
244249
runs-on: ${{ matrix.os }}
245250
strategy:
@@ -286,6 +291,7 @@ jobs:
286291
with:
287292
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
288293
path: "**/build/reports/**/*"
294+
289295
check-sample-ios-static-xcframework:
290296
runs-on: macOS-latest
291297
needs: build-library
@@ -326,6 +332,7 @@ jobs:
326332
with:
327333
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
328334
path: "**/build/reports/**/*"
335+
329336
check-sample-ios-cocoapods-static-framework:
330337
runs-on: macOS-latest
331338
needs: build-library
@@ -366,6 +373,7 @@ jobs:
366373
with:
367374
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
368375
path: "**/build/reports/**/*"
376+
369377
check-sample-kotlin-ios-app:
370378
runs-on: macOS-latest
371379
needs: build-library
@@ -406,6 +414,7 @@ jobs:
406414
with:
407415
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
408416
path: "**/build/reports/**/*"
417+
409418
check-sample-compose-resources-gallery:
410419
runs-on: ${{ matrix.os }}
411420
strategy:
@@ -452,6 +461,7 @@ jobs:
452461
with:
453462
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
454463
path: "**/build/reports/**/*"
464+
455465
check-kotlin-2-sample:
456466
runs-on: ${{ matrix.os }}
457467
strategy:
@@ -498,6 +508,7 @@ jobs:
498508
with:
499509
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
500510
path: "**/build/reports/**/*"
511+
501512
check-kotlin-2-dynamic-sample:
502513
runs-on: ${{ matrix.os }}
503514
strategy:
@@ -544,6 +555,7 @@ jobs:
544555
with:
545556
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
546557
path: "**/build/reports/**/*"
558+
547559
check-kotlin-2-tests:
548560
runs-on: ${{ matrix.os }}
549561
strategy:
@@ -591,6 +603,7 @@ jobs:
591603
with:
592604
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
593605
path: "**/build/reports/**/*"
606+
594607
check-cm-resources-sample:
595608
runs-on: ${{ matrix.os }}
596609
strategy:
@@ -637,3 +650,50 @@ jobs:
637650
with:
638651
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
639652
path: "**/build/reports/**/*"
653+
654+
check-gradle-agp-9-sample:
655+
runs-on: ${{ matrix.os }}
656+
strategy:
657+
matrix:
658+
os:
659+
- macOS-latest
660+
- windows-latest
661+
- ubuntu-latest
662+
needs: build-library
663+
steps:
664+
- uses: actions/checkout@v4
665+
- name: Set up JDK 17
666+
uses: actions/setup-java@v4
667+
with:
668+
java-version: 17
669+
distribution: zulu
670+
- name: Setup Gradle
671+
uses: gradle/gradle-build-action@v3
672+
with:
673+
cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref !=
674+
'refs/heads/develop' }}
675+
- name: Cache .konan
676+
uses: actions/cache@v4
677+
with:
678+
path: ~/.konan
679+
key: ${{ matrix.os }}-konan-${{ hashFiles('**/*.gradle*', 'gradle/**/*') }}
680+
- name: Download maven artifacts
681+
uses: actions/download-artifact@v4
682+
with:
683+
name: maven
684+
path: ~/.m2/repository/dev/icerock
685+
- name: Sample - gradle-agp-9-sample
686+
run: cd samples/gradle-agp-9-sample && ./local-check.sh
687+
shell: bash
688+
- name: Publish Test Report
689+
uses: mikepenz/action-junit-report@v4
690+
if: ${{ always() }}
691+
with:
692+
report_paths: "**/build/test-results/**/TEST-*.xml"
693+
github_token: ${{ secrets.GITHUB_TOKEN }}
694+
- name: Archive reports
695+
uses: actions/upload-artifact@v4
696+
if: ${{ always() }}
697+
with:
698+
name: code-coverage-report-${{ github.job }}-${{ matrix.os }}
699+
path: "**/build/reports/**/*"

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ buildscript {
6565
}
6666
6767
dependencies {
68-
classpath "dev.icerock.moko:resources-generator:0.26.0"
68+
classpath "dev.icerock.moko:resources-generator:0.26.1"
6969
}
7070
}
7171
@@ -83,10 +83,10 @@ project build.gradle
8383
apply plugin: "dev.icerock.mobile.multiplatform-resources"
8484
8585
dependencies {
86-
commonMainApi("dev.icerock.moko:resources:0.26.0")
87-
commonMainApi("dev.icerock.moko:resources-compose:0.26.0") // for compose multiplatform
86+
commonMainApi("dev.icerock.moko:resources:0.26.1")
87+
commonMainApi("dev.icerock.moko:resources-compose:0.26.1") // for compose multiplatform
8888
89-
commonTestImplementation("dev.icerock.moko:resources-test:0.26.0")
89+
commonTestImplementation("dev.icerock.moko:resources-test:0.26.1")
9090
}
9191
9292
multiplatformResources {
@@ -133,7 +133,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui
133133

134134
```
135135
framework {
136-
export("dev.icerock.moko:resources:0.26.0")
136+
export("dev.icerock.moko:resources:0.26.1")
137137
export("dev.icerock.moko:graphics:0.10.0") // toUIColor here
138138
}
139139
```
@@ -149,6 +149,47 @@ If you have multiple gradle modules and resources stored not in module that comp
149149
```
150150
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).
151151

152+
#### Android Host Tests (Unit Tests)
153+
If you use the new Android Multiplatform Library plugin (`com.android.kotlin.multiplatform.library`),
154+
enabling Android resources for host tests (Unit tests) depends on your AGP version.
155+
This is required for moko-resources to access generated R classes during testing.
156+
157+
For AGP 8.8.0 and higher
158+
Use the native DSL directly inside the androidLibrary block:
159+
160+
```kotlin
161+
kotlin {
162+
androidLibrary {
163+
// ... base configuration (namespace, compileSdk, etc.)
164+
165+
withHostTest {
166+
isIncludeAndroidResources = true
167+
}
168+
169+
// OR if you use builder for advanced configuration:
170+
/*
171+
withHostTestBuilder {
172+
// your builder config
173+
}.configure {
174+
isIncludeAndroidResources = true
175+
}
176+
*/
177+
}
178+
}
179+
```
180+
For AGP 8.2.0 - 8.7.x
181+
The withHostTest DSL is not yet available.
182+
183+
As a workaround, enable Android resources using the legacy android block::
184+
185+
```kotlin
186+
android {
187+
testOptions {
188+
unitTests.isIncludeAndroidResources = true
189+
}
190+
}
191+
```
192+
152193
### Xcode setup
153194

154195
For correct work of plugin tasks you need disable `ENABLE_USER_SCRIPT_SANDBOXING` in .xcodeproj file:

gradle/moko.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
resourcesVersion = "0.26.0"
2+
resourcesVersion = "0.26.1"
33

44
[libraries]
55
resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" }

resources-generator/src/main/kotlin/dev/icerock/gradle/extra/mokoResourcesGenTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ private fun registerGenerateTask(
121121
"androidTest",
122122
"androidInstrumentedTest",
123123
"main",
124-
"test"
124+
"test",
125+
"androidHostTest",
126+
"androidDeviceTest"
125127
)
126128
}
127129
}

resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/android/SetupAndroidMultiplatformLibraryTargetSources.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package dev.icerock.gradle.generator.platform.android
77
import com.android.build.api.dsl.KotlinMultiplatformAndroidCompilation
88
import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget
99
import com.android.build.api.extension.impl.CurrentAndroidGradlePluginVersion
10+
import com.android.build.api.variant.Component
1011
import com.android.build.api.variant.KotlinMultiplatformAndroidComponentsExtension
1112
import com.android.build.api.variant.KotlinMultiplatformAndroidVariant
1213
import com.android.build.api.variant.Variant
@@ -101,11 +102,17 @@ private fun variantHandler(
101102
) {
102103
if (compilation !is KotlinMultiplatformAndroidCompilation) return
103104

104-
if (variant.name == compilation.componentName) {
105-
variant.sources.addKmpAndroidGeneratedSources(genTaskProvider)
105+
val allComponents: List<Component> = listOf(variant) + variant.nestedComponents
106106

107-
genTaskProvider.configure {
108-
it.androidSourceSetName.set(variant.name)
109-
}
107+
val matchingComponent: Component = allComponents.find { component ->
108+
component.name == compilation.componentName ||
109+
compilation.componentName.endsWith(component.name, ignoreCase = true) ||
110+
component.name == compilation.name
111+
} ?: return
112+
113+
variant.sources.addKmpAndroidGeneratedSources(genTaskProvider)
114+
115+
genTaskProvider.configure {
116+
it.androidSourceSetName.set(matchingComponent.name)
110117
}
111118
}

samples/gradle-agp-9-sample/gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ androidMultiplatfrom = { id = "com.android.kotlin.multiplatform.library", versio
2020
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
2121
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
2222
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
23-
multiplatformResources = { id = "dev.icerock.mobile.multiplatform-resources", version = "0.26.0" }
23+
multiplatformResources = { id = "dev.icerock.mobile.multiplatform-resources", version = "0.26.1" }

samples/gradle-agp-9-sample/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ dependencyResolutionManagement {
2626

2727
rootProject.name = "gradle9_sample"
2828
include(":androidApp")
29-
include(":shared")
29+
include(":shared")
30+
include(":shared:test-utils")

samples/gradle-agp-9-sample/shared/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ kotlin {
99
namespace = "com.gradle9sample.android.library"
1010
compileSdk = 36
1111
minSdk = 26
12+
13+
withHostTest {
14+
isIncludeAndroidResources = true
15+
}
16+
17+
withDeviceTest { }
1218
}
1319

1420
listOf(
@@ -29,6 +35,8 @@ kotlin {
2935
}
3036
commonTest.dependencies {
3137
implementation(libs.kotlin.test)
38+
implementation(moko.resourcesTest)
39+
implementation(project(":shared:test-utils"))
3240
}
3341
}
3442

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<resources>
3+
<plural name="test.plural">
4+
<item quantity="zero">zero</item>
5+
<item quantity="one">one</item>
6+
<item quantity="two">two</item>
7+
<item quantity="other">other</item>
8+
</plural>
9+
<plural name="test.plural.intformat">
10+
<item quantity="zero">%.2d zero</item>
11+
<item quantity="one">%.2d one</item>
12+
<item quantity="two">%.2d two</item>
13+
<item quantity="other">%.2d other</item>
14+
</plural>
15+
<plural name="test.plural.stringformat">
16+
<item quantity="zero">zero %%</item>
17+
<item quantity="one">%s one</item>
18+
<item quantity="two">%s two</item>
19+
<item quantity="other">%s other</item>
20+
</plural>
21+
<!-- Verify that we can use the 'plurals' element. -->
22+
<plurals name="test.plural.interop">
23+
<item quantity="zero">plurals-interop: zero</item>
24+
<item quantity="one">plurals-interop: one</item>
25+
<item quantity="two">plurals-interop: two</item>
26+
<item quantity="other">plurals-interop: other</item>
27+
</plurals>
28+
<plural name="test.plural.fallback">
29+
<item quantity="one">one</item>
30+
<item quantity="other">other</item>
31+
</plural>
32+
</resources>

0 commit comments

Comments
 (0)