From db0c3990c09a5fe99b32fee9de62a4f70c510f23 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 28 Aug 2020 12:37:28 +0700 Subject: [PATCH 1/4] #97 fix bundle search in static frameworks (new bundle search logic) --- .../moko/resources/utils/NSBundleExt.kt | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt index 1adaf213..dfb14190 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt @@ -5,20 +5,35 @@ package dev.icerock.moko.resources.utils import platform.Foundation.NSBundle +import platform.Foundation.NSDirectoryEnumerator +import platform.Foundation.NSFileManager +import platform.Foundation.NSURL +import platform.Foundation.pathExtension fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle { // try get already loaded bundle NSBundle.bundleWithIdentifier(identifier)?.let { return it } - // try load from app framework - NSBundle.mainBundle - .pathsForResourcesOfType(ext = "framework", inDirectory = "Frameworks") - .filterIsInstance() - .mapNotNull { NSBundle.bundleWithPath(it) } - .flatMap { it.pathsForResourcesOfType(ext = "bundle", inDirectory = null) } - .filterIsInstance() - // load each loadable bundle to correct load by identifier later - .forEach { NSBundle.bundleWithPath(it)?.bundleIdentifier } + val bundlePath: String = NSBundle.mainBundle.bundlePath + val enumerator: NSDirectoryEnumerator = requireNotNull(NSFileManager.defaultManager.enumeratorAtPath(bundlePath)) + while (true) { + val relativePath: String = enumerator.nextObject() as? String ?: break + val url = NSURL(fileURLWithPath = relativePath) + if (url.pathExtension == "bundle") { + val fullPath = "$bundlePath/$relativePath" + val loadedIdentifier: String? = NSBundle.bundleWithPath(fullPath)?.bundleIdentifier + if(isBundleSearchLogEnabled) { + println("moko-resources auto-load bundle with identifier $loadedIdentifier at path $fullPath") + } + } + } - return NSBundle.bundleWithIdentifier(identifier)!! + val resultBundle = NSBundle.bundleWithIdentifier(identifier) + if (resultBundle == null) { + throw IllegalArgumentException("bundle with identifier $identifier not found") + } + + return resultBundle } + +var isBundleSearchLogEnabled = false From 70f05a39beb9055442391604bd0037b0b80e9e80 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 28 Aug 2020 12:38:13 +0700 Subject: [PATCH 2/4] #97 fix bundle search with cocoapods gradle plugin usage --- .../gradle/generator/ios/IosMRGenerator.kt | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt index 70b33344..9052d3e2 100644 --- a/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt +++ b/gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/ios/IosMRGenerator.kt @@ -132,27 +132,27 @@ class IosMRGenerator( private fun setupFrameworkResources() { val kotlinNativeTarget = compilation.target as KotlinNativeTarget - val frameworkBinaries: List = kotlinNativeTarget.binaries - .filterIsInstance() - .filter { it.compilation == compilation } - - frameworkBinaries.forEach { framework -> - val linkTask = framework.linkTask - - linkTask.doLast { - linkTask.libraries - .plus(linkTask.intermediateLibrary.get()) - .filter { it.extension == "klib" } - .forEach { - project.logger.info("copy resources from $it") - val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path) - val klib = KotlinLibraryLayoutImpl(klibKonan) - val layout = klib.extractingToTemp - - File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) - } + kotlinNativeTarget.binaries + .matching { it is Framework && it.compilation == compilation } + .configureEach { + val framework = this as Framework + + val linkTask = framework.linkTask + + linkTask.doLast { + linkTask.libraries + .plus(linkTask.intermediateLibrary.get()) + .filter { it.extension == "klib" } + .forEach { + project.logger.info("copy resources from $it") + val klibKonan = org.jetbrains.kotlin.konan.file.File(it.path) + val klib = KotlinLibraryLayoutImpl(klibKonan) + val layout = klib.extractingToTemp + + File(layout.resourcesDir.path).copyRecursively(framework.outputFile, overwrite = true) + } + } } - } } companion object { From 16677d05e4aba44dd8ccf3387463050230d96b2a Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 28 Aug 2020 12:38:22 +0700 Subject: [PATCH 3/4] up version --- README.md | 9 +++++---- buildSrc/src/main/kotlin/Versions.kt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5e60adcf..74d251b4 100755 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on - 0.10.0 - 0.10.1 - 0.11.0 + - 0.11.1 ## Installation root build.gradle @@ -57,7 +58,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:resources-generator:0.11.0" + classpath "dev.icerock.moko:resources-generator:0.11.1" } } @@ -74,12 +75,12 @@ project build.gradle apply plugin: "dev.icerock.mobile.multiplatform-resources" dependencies { - commonMainApi("dev.icerock.moko:resources:0.11.0") + commonMainApi("dev.icerock.moko:resources:0.11.1") } multiplatformResources { - multiplatformResourcesPackage = "org.example.library" - iosBaseLocalizationRegion = "en" //optional, default "en" + multiplatformResourcesPackage = "org.example.library" // required + iosBaseLocalizationRegion = "en" // optional, default "en" multiplatformResourcesSourceSet = "commonClientMain" // optional, default "commonMain" } ``` diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 61285b66..c8425f75 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -12,7 +12,7 @@ object Versions { const val kotlin = "1.3.72" const val detekt = "1.7.4" - private const val mokoResources = "0.11.0" + private const val mokoResources = "0.11.1" object Plugins { const val android = "3.6.2" From e5bd0f2f8d0691ef98cb88fdc70be7d4cd68f042 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 28 Aug 2020 14:33:45 +0700 Subject: [PATCH 4/4] #97 fix format --- .../kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt index dfb14190..847bedb5 100644 --- a/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt +++ b/resources/src/iosMain/kotlin/dev/icerock/moko/resources/utils/NSBundleExt.kt @@ -22,7 +22,7 @@ fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle { if (url.pathExtension == "bundle") { val fullPath = "$bundlePath/$relativePath" val loadedIdentifier: String? = NSBundle.bundleWithPath(fullPath)?.bundleIdentifier - if(isBundleSearchLogEnabled) { + if (isBundleSearchLogEnabled) { println("moko-resources auto-load bundle with identifier $loadedIdentifier at path $fullPath") } }