Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/compilation-check-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 60 additions & 0 deletions .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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/**/*"
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ buildscript {
}

dependencies {
classpath "dev.icerock.moko:resources-generator:0.25.2"
classpath "dev.icerock.moko:resources-generator:0.26.1"
}
}

Expand All @@ -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.1")
commonMainApi("dev.icerock.moko:resources-compose:0.26.1") // for compose multiplatform

commonTestImplementation("dev.icerock.moko:resources-test:0.25.2")
commonTestImplementation("dev.icerock.moko:resources-test:0.26.1")
}

multiplatformResources {
Expand Down Expand Up @@ -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.1")
export("dev.icerock.moko:graphics:0.10.0") // toUIColor here
}
```
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gradle/moko.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
resourcesVersion = "0.26.0"
resourcesVersion = "0.26.1"

[libraries]
resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private fun registerGenerateTask(
"androidTest",
"androidInstrumentedTest",
"main",
"test"
"test",
"androidHostTest",
"androidDeviceTest"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.KotlinMultiplatformAndroidComponentsExtension
import com.android.build.api.variant.KotlinMultiplatformAndroidVariant
import com.android.build.api.variant.Variant
Expand Down Expand Up @@ -101,11 +102,17 @@ private fun variantHandler(
) {
if (compilation !is KotlinMultiplatformAndroidCompilation) return

if (variant.name == compilation.componentName) {
variant.sources.addKmpAndroidGeneratedSources(genTaskProvider)
val allComponents: List<Component> = 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)
}
}
2 changes: 1 addition & 1 deletion samples/gradle-agp-9-sample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
3 changes: 2 additions & 1 deletion samples/gradle-agp-9-sample/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ dependencyResolutionManagement {

rootProject.name = "gradle9_sample"
include(":androidApp")
include(":shared")
include(":shared")
include(":shared:test-utils")
8 changes: 8 additions & 0 deletions samples/gradle-agp-9-sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ kotlin {
namespace = "com.gradle9sample.android.library"
compileSdk = 36
minSdk = 26

withHostTest {
isIncludeAndroidResources = true
}

withDeviceTest { }
}

listOf(
Expand All @@ -29,6 +35,8 @@ kotlin {
}
commonTest.dependencies {
implementation(libs.kotlin.test)
implementation(moko.resourcesTest)
implementation(project(":shared:test-utils"))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<plural name="test.plural">
<item quantity="zero">zero</item>
<item quantity="one">one</item>
<item quantity="two">two</item>
<item quantity="other">other</item>
</plural>
<plural name="test.plural.intformat">
<item quantity="zero">%.2d zero</item>
<item quantity="one">%.2d one</item>
<item quantity="two">%.2d two</item>
<item quantity="other">%.2d other</item>
</plural>
<plural name="test.plural.stringformat">
<item quantity="zero">zero %%</item>
<item quantity="one">%s one</item>
<item quantity="two">%s two</item>
<item quantity="other">%s other</item>
</plural>
<!-- Verify that we can use the 'plurals' element. -->
<plurals name="test.plural.interop">
<item quantity="zero">plurals-interop: zero</item>
<item quantity="one">plurals-interop: one</item>
<item quantity="two">plurals-interop: two</item>
<item quantity="other">plurals-interop: other</item>
</plurals>
<plural name="test.plural.fallback">
<item quantity="one">one</item>
<item quantity="other">other</item>
</plural>
</resources>
Loading
Loading