Skip to content

Commit

Permalink
Merge pull request #294 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.18.0
  • Loading branch information
Alex009 authored Jan 22, 2022
2 parents ec2d7fa + e88ab20 commit 29e481c
Show file tree
Hide file tree
Showing 102 changed files with 1,794 additions and 280 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
java-version: 11
- name: Plugin check
run: ./gradlew -p resources-generator build publishToMavenLocal
- name: detekt run
run: ./gradlew detekt
- name: check android only build
run: ./gradlew clean && ./gradlew assembleDebug
- name: check jvm only build
Expand Down
71 changes: 35 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
![moko-resources](img/logo.png)
[![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)
![badge][badge-android]
![badge][badge-iosx64]
![badge][badge-iosarm64]
![badge][badge-macos64]
![badge][badge-iosX64]
![badge][badge-iosArm64]
![badge][badge-iosSimulatorArm64]
![badge][badge-macosArm64]
![badge][badge-macosX64]
![badge][badge-jvm]

# Mobile Kotlin resources
Expand All @@ -25,7 +27,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on
- **Colors** with light/dark mode support;
- **StringDesc** for lifecycle-aware access to resources and unified localization on both platforms;
- **Static** iOS frameworks support;
- **FatFrameworkWithResourcesTask** Gradle task.
- **Fat and XC** frameworks support.

## Requirements
- Gradle version 6.8.3+
Expand All @@ -41,7 +43,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko:resources-generator:0.17.4"
classpath "dev.icerock.moko:resources-generator:0.18.0"
}
}
Expand All @@ -58,11 +60,16 @@ project build.gradle
apply plugin: "dev.icerock.mobile.multiplatform-resources"
dependencies {
commonMainApi("dev.icerock.moko:resources:0.17.4")
commonMainApi("dev.icerock.moko:resources:0.18.0")
androidMainApi("dev.icerock.moko:resources-compose:0.18.0")
jvmMainApi("dev.icerock.moko:resources-compose:0.18.0")
commonTestImplementation("dev.icerock.moko:resources-test:0.18.0")
}
multiplatformResources {
multiplatformResourcesPackage = "org.example.library" // required
multiplatformResourcesClassName = "SharedRes" // optional, default MR
multiplatformResourcesVisibility = MRVisibility.Internal // optional, default Public
iosBaseLocalizationRegion = "en" // optional, default "en"
multiplatformResourcesSourceSet = "commonClientMain" // optional, default "commonMain"
}
Expand Down Expand Up @@ -447,36 +454,6 @@ framework {
}
```

### Gradle task for creating Fat Framework with resources

If you want to create Fat Framework for iOS with all resources from KMP Gradle module you should use
extended Gradle task `FatFrameworkWithResourcesTask`. There is example of
`FatFrameworkWithResourcesTask` task using for the `mpp-library` module of the Sample. In the end
of the `sample/mpp-library/build.gradle.kts` file:

```kotlin
tasks.register("debugFatFramework", dev.icerock.gradle.tasks.FatFrameworkWithResourcesTask::class) {
baseName = "multiplatform"

val targets = mapOf(
"iosX64" to kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>("iosX64"),
"iosArm64" to kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>("iosArm64")
)

from(
targets.toList().map {
it.second.binaries.getFramework("MultiPlatformLibrary", org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG)
}
)
}
```

Then just launch task:

```shell script
./gradlew :sample:mpp-library:debugFatFramework
```

### Example 10 - plain file resource access
The first step is a create a resource file `test.txt` for example, in `commonMain/resources/MR/files`
After gradle sync we can get file by id `MR.files.test`
Expand All @@ -492,6 +469,28 @@ val text = MR.files.test.readText()
```
If you want to read files not as text, add your own implementation to expect/actual FileResource

### Example 11 - assets access

Assets allow you save directories hierarchy (in files structure is plain).
Locate files to `commonMain/resources/MR/assets` and access to it by `MR.assets.*`

### Creating Fat Framework with resources

Just use `FatFrameworkTask` [from kotlin plugin](https://kotlinlang.org/docs/mpp-build-native-binaries.html#build-universal-frameworks).

### Creating XCFramework with resources

Just use `XCFramework` [from kotlin plugin](https://kotlinlang.org/docs/mpp-build-native-binaries.html#build-xcframeworks).

But if you use **static frameworks** required additional setup - add to Xcode build phase (at end):
```bash
"$SRCROOT/../gradlew" -p "$SRCROOT/../" :shared:copyResourcesMPLReleaseXCFrameworkToApp \
-Pmoko.resources.BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR \
-Pmoko.resources.CONTENTS_FOLDER_PATH=$CONTENTS_FOLDER_PATH
```

Details you can check in sample TestStaticXCFramework in ios-app. In this sample used mpp-hierarhical kotlin module with XCFramework.

## Samples
Please see more examples in the [sample directory](sample).

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
}
dependencies {
classpath("dev.icerock.moko:resources-generator")
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0")
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.1")
classpath(":resources-build-logic")
}
}
Expand Down
26 changes: 17 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlinVersion = "1.5.31"
androidGradleVersion = "4.1.2"
kotlinVersion = "1.6.10"
androidGradleVersion = "7.0.4"

# kotlinx
kotlinxSerializationVersion = "1.2.1"
Expand All @@ -10,14 +10,18 @@ constraintLayoutVersion = "2.0.4"
androidAppCompatVersion = "1.2.0"

# android compose
composeVersion = "1.0.4"
composeVersion = "1.0.5"
composeActivityVersion = "1.3.1"

# jetbrains compose
composeJetbrainsVersion = "1.0.1"

# jvm
apacheCommonsTextVersion = "1.3"
kotlinPoetVersion = "1.6.0"
detektVersion = "1.15.0"
kotlinPoetVersion = "1.10.2"
detektVersion = "1.19.0"
icu4jVersion = "69.1"
commonsCodecVersion = "1.15"

# tests
espressoCoreVersion = "3.3.0"
Expand All @@ -28,10 +32,10 @@ testCoreVersion = "1.3.0"
robolectricVersion = "4.6"

# moko
mokoGraphicsVersion = "0.7.0"
mokoParcelizeVersion = "0.7.1"
mokoTestVersion = "0.4.1"
mokoResourcesVersion = "0.17.4"
mokoGraphicsVersion = "0.9.0"
mokoParcelizeVersion = "0.8.0"
mokoTestVersion = "0.5.0"
mokoResourcesVersion = "0.18.0"

[libraries]
# kotlinx
Expand All @@ -55,9 +59,13 @@ composeMaterial = { module = "androidx.compose.material:material", version.ref =
composeFoundation = { module = "androidx.compose.foundation:foundation", version.ref = "composeVersion" }
composeActivity = { module = "androidx.activity:activity-compose", version.ref = "composeActivityVersion" }

# jetbrains compose
composeGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "composeJetbrainsVersion" }

# jvm
kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoetVersion" }
apacheCommonsText = { module = "org.apache.commons:commons-text", version.ref = "apacheCommonsTextVersion" }
commonsCodec = { module = "commons-codec:commons-codec", version.ref = "commonsCodecVersion" }
icu4j = { module = "com.ibm.icu:icu4j", version.ref = "icu4jVersion" }

# tests
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions resources-build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ repositories {
}

dependencies {
api("dev.icerock:mobile-multiplatform:0.12.0")
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
api("com.android.tools.build:gradle:7.0.0")
api("dev.icerock:mobile-multiplatform:0.13.0")
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
api("com.android.tools.build:gradle:7.0.4")
api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.android.build.gradle.BaseExtension

configure<BaseExtension> {
compileSdkVersion(30)
compileSdkVersion(31)

defaultConfig {
minSdkVersion(16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kotlin {
val iosMain by getting {
dependsOn(appleMain)
}
val macosX64Main by getting {
val macosMain by getting {
dependsOn(appleMain)
}

Expand All @@ -27,7 +27,7 @@ kotlin {
val iosTest by getting {
dependsOn(appleTest)
}
val macosX64Test by getting {
val macosTest by getting {
dependsOn(appleTest)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,33 @@ kotlin {
jvm()
android()
ios()
iosSimulatorArm64()
macosX64()
}
macosArm64()

sourceSets {
val iosMain by getting
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)

val iosTest by getting
val iosSimulatorArm64Test by getting
iosSimulatorArm64Test.dependsOn(iosTest)

val commonMain by getting
val macosMain by creating
val macosArm64Main by getting
val macosX64Main by getting
macosArm64Main.dependsOn(macosMain)
macosX64Main.dependsOn(macosMain)
macosMain.dependsOn(commonMain)

tasks.withType(org.jetbrains.kotlin.gradle.tasks.CInteropProcess::class.java) {
settings.compilerOpts("-DNS_FORMAT_ARGUMENT(A)=")
val commonTest by getting
val macosTest by creating
val macosArm64Test by getting
val macosX64Test by getting
macosArm64Test.dependsOn(macosTest)
macosX64Test.dependsOn(macosTest)
macosTest.dependsOn(commonTest)
}
}
15 changes: 14 additions & 1 deletion resources-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
*/

plugins {
id("com.android.library")
id("android-base-convention")
id("org.jetbrains.kotlin.multiplatform")
id("detekt-convention")
id("org.jetbrains.compose")
id("javadoc-stub-convention")
id("multiplatform-android-publish-convention")
id("publication-convention")
id("dev.icerock.mobile.multiplatform.android-manifest")
}

java {
Expand All @@ -17,11 +21,20 @@ java {
}

kotlin {
android()
jvm()
sourceSets {
named("jvmMain") {
commonMain {
dependencies {
api(projects.resources)
implementation(compose.runtime)
implementation(compose.foundation)
}
}

named("jvmMain") {
dependencies {
api(compose.desktop.common)
implementation(compose.desktop.currentOs)
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources-compose/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="dev.icerock.moko.resources.compose" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import dev.icerock.moko.resources.PluralsResource
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Plural
import dev.icerock.moko.resources.desc.PluralFormatted
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
import dev.icerock.moko.resources.desc.StringDesc

@Composable
actual fun stringResource(resource: StringResource): String =
StringDesc.Resource(resource).toString(LocalContext.current)

@Composable
actual fun stringResource(resource: StringResource, vararg args: Any): String =
StringDesc.ResourceFormatted(resource, args).toString(LocalContext.current)

@Composable
actual fun stringResource(resource: PluralsResource, quantity: Int): String =
StringDesc.Plural(resource, quantity).toString(LocalContext.current)

@Composable
actual fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String =
StringDesc.PluralFormatted(resource, quantity, args).toString(LocalContext.current)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/
package dev.icerock.moko.resources.compose

import androidx.compose.runtime.Composable
import dev.icerock.moko.resources.PluralsResource
import dev.icerock.moko.resources.StringResource

@Composable
expect fun stringResource(resource: StringResource): String

@Composable
expect fun stringResource(resource: StringResource, vararg args: Any): String

@Composable
expect fun stringResource(resource: PluralsResource, quantity: Int): String

@Composable
expect fun stringResource(resource: PluralsResource, quantity: Int, vararg args: Any): String
Loading

0 comments on commit 29e481c

Please sign in to comment.