Skip to content

Commit 876daec

Browse files
authored
Merge pull request #104 from icerockdev/develop
Release 0.11.1
2 parents deb51bc + 979a23e commit 876daec

4 files changed

Lines changed: 51 additions & 35 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on
4747
- 0.10.0
4848
- 0.10.1
4949
- 0.11.0
50+
- 0.11.1
5051

5152
## Installation
5253
root build.gradle
@@ -57,7 +58,7 @@ buildscript {
5758
}
5859
5960
dependencies {
60-
classpath "dev.icerock.moko:resources-generator:0.11.0"
61+
classpath "dev.icerock.moko:resources-generator:0.11.1"
6162
}
6263
}
6364
@@ -74,12 +75,12 @@ project build.gradle
7475
apply plugin: "dev.icerock.mobile.multiplatform-resources"
7576
7677
dependencies {
77-
commonMainApi("dev.icerock.moko:resources:0.11.0")
78+
commonMainApi("dev.icerock.moko:resources:0.11.1")
7879
}
7980
8081
multiplatformResources {
81-
multiplatformResourcesPackage = "org.example.library"
82-
iosBaseLocalizationRegion = "en" //optional, default "en"
82+
multiplatformResourcesPackage = "org.example.library" // required
83+
iosBaseLocalizationRegion = "en" // optional, default "en"
8384
multiplatformResourcesSourceSet = "commonClientMain" // optional, default "commonMain"
8485
}
8586
```

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Versions {
1212
const val kotlin = "1.3.72"
1313
const val detekt = "1.7.4"
1414

15-
private const val mokoResources = "0.11.0"
15+
private const val mokoResources = "0.11.1"
1616

1717
object Plugins {
1818
const val android = "3.6.2"

gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,27 @@ class IosMRGenerator(
132132
private fun setupFrameworkResources() {
133133
val kotlinNativeTarget = compilation.target as KotlinNativeTarget
134134

135-
val frameworkBinaries: List<Framework> = kotlinNativeTarget.binaries
136-
.filterIsInstance<Framework>()
137-
.filter { it.compilation == compilation }
138-
139-
frameworkBinaries.forEach { framework ->
140-
val linkTask = framework.linkTask
141-
142-
linkTask.doLast {
143-
linkTask.libraries
144-
.plus(linkTask.intermediateLibrary.get())
145-
.filter { it.extension == "klib" }
146-
.forEach {
147-
project.logger.info("copy resources from $it")
148-
val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path)
149-
val klib = KotlinLibraryLayoutImpl(klibKonan)
150-
val layout = klib.extractingToTemp
151-
152-
File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true)
153-
}
135+
kotlinNativeTarget.binaries
136+
.matching { it is Framework && it.compilation == compilation }
137+
.configureEach {
138+
val framework = this as Framework
139+
140+
val linkTask = framework.linkTask
141+
142+
linkTask.doLast {
143+
linkTask.libraries
144+
.plus(linkTask.intermediateLibrary.get())
145+
.filter { it.extension == "klib" }
146+
.forEach {
147+
project.logger.info("copy resources from $it")
148+
val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path)
149+
val klib = KotlinLibraryLayoutImpl(klibKonan)
150+
val layout = klib.extractingToTemp
151+
152+
File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true)
153+
}
154+
}
154155
}
155-
}
156156
}
157157

158158
companion object {

resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,35 @@
55
package dev.icerock.moko.resources.utils
66

77
import platform.Foundation.NSBundle
8+
import platform.Foundation.NSDirectoryEnumerator
9+
import platform.Foundation.NSFileManager
10+
import platform.Foundation.NSURL
11+
import platform.Foundation.pathExtension
812

913
fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle {
1014
// try get already loaded bundle
1115
NSBundle.bundleWithIdentifier(identifier)?.let { return it }
1216

13-
// try load from app framework
14-
NSBundle.mainBundle
15-
.pathsForResourcesOfType(ext = "framework", inDirectory = "Frameworks")
16-
.filterIsInstance<String>()
17-
.mapNotNull { NSBundle.bundleWithPath(it) }
18-
.flatMap { it.pathsForResourcesOfType(ext = "bundle", inDirectory = null) }
19-
.filterIsInstance<String>()
20-
// load each loadable bundle to correct load by identifier later
21-
.forEach { NSBundle.bundleWithPath(it)?.bundleIdentifier }
17+
val bundlePath: String = NSBundle.mainBundle.bundlePath
18+
val enumerator: NSDirectoryEnumerator = requireNotNull(NSFileManager.defaultManager.enumeratorAtPath(bundlePath))
19+
while (true) {
20+
val relativePath: String = enumerator.nextObject() as? String ?: break
21+
val url = NSURL(fileURLWithPath = relativePath)
22+
if (url.pathExtension == "bundle") {
23+
val fullPath = "$bundlePath/$relativePath"
24+
val loadedIdentifier: String? = NSBundle.bundleWithPath(fullPath)?.bundleIdentifier
25+
if (isBundleSearchLogEnabled) {
26+
println("moko-resources auto-load bundle with identifier $loadedIdentifier at path $fullPath")
27+
}
28+
}
29+
}
2230

23-
return NSBundle.bundleWithIdentifier(identifier)!!
31+
val resultBundle = NSBundle.bundleWithIdentifier(identifier)
32+
if (resultBundle == null) {
33+
throw IllegalArgumentException("bundle with identifier $identifier not found")
34+
}
35+
36+
return resultBundle
2437
}
38+
39+
var isBundleSearchLogEnabled = false

0 commit comments

Comments
 (0)