Skip to content

Commit

Permalink
Merge pull request #342 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.20.0
  • Loading branch information
Alex009 authored May 14, 2022
2 parents a4a0454 + 187cd86 commit a67e503
Show file tree
Hide file tree
Showing 19 changed files with 788 additions and 29 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko:resources-generator:0.19.1"
classpath "dev.icerock.moko:resources-generator:0.20.0"
}
}
Expand All @@ -63,10 +63,10 @@ project build.gradle
apply plugin: "dev.icerock.mobile.multiplatform-resources"
dependencies {
commonMainApi("dev.icerock.moko:resources:0.19.1")
androidMainApi("dev.icerock.moko:resources-compose:0.19.1")
jvmMainApi("dev.icerock.moko:resources-compose:0.19.1")
commonTestImplementation("dev.icerock.moko:resources-test:0.19.1")
commonMainApi("dev.icerock.moko:resources:0.20.0")
androidMainApi("dev.icerock.moko:resources-compose:0.20.0")
jvmMainApi("dev.icerock.moko:resources-compose:0.20.0")
commonTestImplementation("dev.icerock.moko:resources-test:0.20.0")
}
multiplatformResources {
Expand Down Expand Up @@ -135,6 +135,18 @@ you also need to pass extra properties:
-Pkotlin.native.cocoapods.configuration=$CONFIGURATION
```

### iOS executable
When you use `executable` kotlin target you should add custom build phase to xcode, after kotlin
compilation:
```shell
"$SRCROOT/../gradlew" -p "$SRCROOT/../" :shared:copyResourcesDebugExecutableIosSimulatorArm64 \
-Pmoko.resources.BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR \
-Pmoko.resources.CONTENTS_FOLDER_PATH=$CONTENTS_FOLDER_PATH
```
`copyResourcesDebugExecutableIosSimulatorArm64` should be configured depends on target.

Configured sample you can see in `sample/ios-app` - `TestKotlinApp` target

## Usage
### Example 1 - simple localization string
The first step is a create a file `strings.xml` in `commonMain/resources/MR/base` with the following content:
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ robolectricVersion = "4.7.3"
mokoGraphicsVersion = "0.9.0"
mokoParcelizeVersion = "0.8.0"
mokoTestVersion = "0.5.0"
mokoResourcesVersion = "0.19.1"
mokoMultiplatformPluginVersion = "0.13.0"
mokoResourcesVersion = "0.20.0"
mokoMultiplatformPluginVersion = "0.14.1"

[libraries]
# kotlinx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.TypeSpec
import dev.icerock.gradle.MultiplatformResourcesPluginExtension
import dev.icerock.gradle.generator.MRGenerator
import dev.icerock.gradle.tasks.CopyExecutableResourcesToApp
import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppEntryPointTask
import dev.icerock.gradle.tasks.CopyFrameworkResourcesToAppTask
import dev.icerock.gradle.utils.calculateResourcesHash
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
Expand Down Expand Up @@ -90,6 +93,7 @@ class AppleMRGenerator(
)

override fun apply(generationTask: Task, project: Project) {
createCopyResourcesToAppTask(project)
setupKLibResources(generationTask)
setupFrameworkResources()
setupTestsResources()
Expand Down Expand Up @@ -183,7 +187,6 @@ class AppleMRGenerator(
linkTask.doLast(object : Action<Task> {
override fun execute(task: Task) {
task as KotlinNativeLink

copyKlibsResourcesIntoFramework(task)
}
})
Expand Down Expand Up @@ -234,14 +237,37 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram
target = outputDir,
overwrite = true
)
} catch (exc: kotlin.io.NoSuchFileException) {
} catch (exc: NoSuchFileException) {
project.logger.info("resources in $inputFile not found")
} catch (exc: java.nio.file.NoSuchFileException) {
project.logger.info("resources in $inputFile not found (empty lib)")
}
}
}

private fun createCopyResourcesToAppTask(project: Project) {
project.tasks.withType<KotlinNativeLink>()
.matching { linkTask -> linkTask.binary is AbstractExecutable }
.all { linkTask ->
val copyTaskName = linkTask.name.replace("link", "copyResources")

if (linkTask.project.tasks.any { it.name == copyTaskName }) return@all

project.files(linkTask.intermediateLibrary)

val copyResources = linkTask.project.tasks
.create(copyTaskName, CopyExecutableResourcesToApp::class) {
val libraries = linkTask.libraries
.plus(project.files(linkTask.intermediateLibrary))
.filter { library -> library.extension == "klib" }
.filter(File::exists)

it.libraries = libraries
}
copyResources.dependsOn(linkTask)
}
}

private fun createCopyFrameworkResourcesTask(linkTask: KotlinNativeLink) {
val framework = linkTask.binary as Framework
val project = linkTask.project
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.gradle.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl
import java.io.File
import java.io.FileFilter

open class CopyExecutableResourcesToApp : DefaultTask() {
@get:Internal
lateinit var libraries: FileCollection

@TaskAction
fun copyResources() {
val buildProductsDir =
File(project.property("moko.resources.BUILT_PRODUCTS_DIR") as String)
val contentsFolderPath =
project.property("moko.resources.CONTENTS_FOLDER_PATH") as String

val outputDir = File(buildProductsDir, contentsFolderPath)

libraries
.filter { it.extension == "klib" }
.filter { it.exists() }
.forEach { inputFile ->
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path)
val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default")
val layout = klib.extractingToTemp

// extracting bundles
layout
.resourcesDir
.absolutePath
.let(::File)
.listFiles(FileFilter { it.extension == "bundle" })
// copying bundles to app
?.forEach {
logger.info("${it.absolutePath} copying to $outputDir")
it.copyRecursively(target = File(outputDir, it.name), overwrite = true)
}
}
}
}
4 changes: 2 additions & 2 deletions sample/ios-app/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
mpp_hierarhical: 8ea2466bf26a2cf59d466e44ab634b755c435f07
MultiPlatformLibrary: b3a7ad5042414b79af4b469037a116eae383fb08
MultiPlatformLibrary: 2a9f43df7bd018c32611a2087c1e2ef74847394c

PODFILE CHECKSUM: f0c3cdabcc5ee37fe65b6ecd54b1f04017dbea93

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions sample/ios-app/TestKotlinApp/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
32 changes: 32 additions & 0 deletions sample/ios-app/TestKotlinApp/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
5 changes: 5 additions & 0 deletions sample/ios-app/TestKotlinApp/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
48 changes: 48 additions & 0 deletions sample/ios-app/TestKotlinApp/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Label View Controller-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController storyboardIdentifier="LabelViewController" id="Y6W-OH-hqX" customClass="LabelViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="placeholder" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="URo-7E-cdm">
<rect key="frame" x="162" y="438" width="90" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="URo-7E-cdm" firstAttribute="centerY" secondItem="5EZ-qb-Rvc" secondAttribute="centerY" id="gSB-4w-5Ns"/>
<constraint firstItem="URo-7E-cdm" firstAttribute="centerX" secondItem="5EZ-qb-Rvc" secondAttribute="centerX" id="kod-pK-1V5"/>
</constraints>
</view>
<connections>
<outlet property="resourcesLabel" destination="URo-7E-cdm" id="rPX-AH-rma"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="21.739130434782609" y="93.75"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Loading

0 comments on commit a67e503

Please sign in to comment.