11![ moko-resources] ( img/logo.png )
22[ ![ GitHub license] ( https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat )] ( http://www.apache.org/licenses/LICENSE-2.0 ) [ ![ Download] ( https://img.shields.io/maven-central/v/dev.icerock.moko/resources ) ] ( https://repo1.maven.org/maven2/dev/icerock/moko/resources ) ![ kotlin-version] ( https://kotlin-version.aws.icerock.dev/kotlin-version?group=dev.icerock.moko&name=resources )
33![ badge] [ badge-android ]
4- ![ badge] [ badge-iosx64 ]
5- ![ badge] [ badge-iosarm64 ]
6- ![ badge] [ badge-macos64 ]
4+ ![ badge] [ badge-iosX64 ]
5+ ![ badge] [ badge-iosArm64 ]
6+ ![ badge] [ badge-iosSimulatorArm64 ]
7+ ![ badge] [ badge-macosArm64 ]
8+ ![ badge] [ badge-macosX64 ]
79![ badge] [ badge-jvm ]
810
911# Mobile Kotlin resources
@@ -25,7 +27,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on
2527- ** Colors** with light/dark mode support;
2628- ** StringDesc** for lifecycle-aware access to resources and unified localization on both platforms;
2729- ** Static** iOS frameworks support;
28- - ** FatFrameworkWithResourcesTask ** Gradle task .
30+ - ** Fat and XC ** frameworks support .
2931
3032## Requirements
3133- Gradle version 6.8.3+
@@ -41,7 +43,7 @@ buildscript {
4143 }
4244
4345 dependencies {
44- classpath "dev.icerock.moko:resources-generator:0.17.4 "
46+ classpath "dev.icerock.moko:resources-generator:0.18.0 "
4547 }
4648}
4749
@@ -58,11 +60,16 @@ project build.gradle
5860apply plugin: "dev.icerock.mobile.multiplatform-resources"
5961
6062dependencies {
61- commonMainApi("dev.icerock.moko:resources:0.17.4")
63+ commonMainApi("dev.icerock.moko:resources:0.18.0")
64+ androidMainApi("dev.icerock.moko:resources-compose:0.18.0")
65+ jvmMainApi("dev.icerock.moko:resources-compose:0.18.0")
66+ commonTestImplementation("dev.icerock.moko:resources-test:0.18.0")
6267}
6368
6469multiplatformResources {
6570 multiplatformResourcesPackage = "org.example.library" // required
71+ multiplatformResourcesClassName = "SharedRes" // optional, default MR
72+ multiplatformResourcesVisibility = MRVisibility.Internal // optional, default Public
6673 iosBaseLocalizationRegion = "en" // optional, default "en"
6774 multiplatformResourcesSourceSet = "commonClientMain" // optional, default "commonMain"
6875}
@@ -447,36 +454,6 @@ framework {
447454}
448455```
449456
450- ### Gradle task for creating Fat Framework with resources
451-
452- If you want to create Fat Framework for iOS with all resources from KMP Gradle module you should use
453- extended Gradle task ` FatFrameworkWithResourcesTask ` . There is example of
454- ` FatFrameworkWithResourcesTask ` task using for the ` mpp-library ` module of the Sample. In the end
455- of the ` sample/mpp-library/build.gradle.kts ` file:
456-
457- ``` kotlin
458- tasks.register(" debugFatFramework" , dev.icerock.gradle.tasks.FatFrameworkWithResourcesTask ::class ) {
459- baseName = " multiplatform"
460-
461- val targets = mapOf (
462- " iosX64" to kotlin.targets.getByName< org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget > (" iosX64" ),
463- " iosArm64" to kotlin.targets.getByName< org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget > (" iosArm64" )
464- )
465-
466- from(
467- targets.toList().map {
468- it.second.binaries.getFramework(" MultiPlatformLibrary" , org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType .DEBUG )
469- }
470- )
471- }
472- ```
473-
474- Then just launch task:
475-
476- ``` shell script
477- ./gradlew :sample:mpp-library:debugFatFramework
478- ```
479-
480457### Example 10 - plain file resource access
481458The first step is a create a resource file ` test.txt ` for example, in ` commonMain/resources/MR/files `
482459After gradle sync we can get file by id ` MR.files.test `
@@ -492,6 +469,28 @@ val text = MR.files.test.readText()
492469```
493470If you want to read files not as text, add your own implementation to expect/actual FileResource
494471
472+ ### Example 11 - assets access
473+
474+ Assets allow you save directories hierarchy (in files structure is plain).
475+ Locate files to ` commonMain/resources/MR/assets ` and access to it by ` MR.assets.* `
476+
477+ ### Creating Fat Framework with resources
478+
479+ Just use ` FatFrameworkTask ` [ from kotlin plugin] ( https://kotlinlang.org/docs/mpp-build-native-binaries.html#build-universal-frameworks ) .
480+
481+ ### Creating XCFramework with resources
482+
483+ Just use ` XCFramework ` [ from kotlin plugin] ( https://kotlinlang.org/docs/mpp-build-native-binaries.html#build-xcframeworks ) .
484+
485+ But if you use ** static frameworks** required additional setup - add to Xcode build phase (at end):
486+ ``` bash
487+ " $SRCROOT /../gradlew" -p " $SRCROOT /../" :shared:copyResourcesMPLReleaseXCFrameworkToApp \
488+ -Pmoko.resources.BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR \
489+ -Pmoko.resources.CONTENTS_FOLDER_PATH=$CONTENTS_FOLDER_PATH
490+ ```
491+
492+ Details you can check in sample TestStaticXCFramework in ios-app. In this sample used mpp-hierarhical kotlin module with XCFramework.
493+
495494## Samples
496495Please see more examples in the [ sample directory] ( sample ) .
497496
0 commit comments