Skip to content

Commit

Permalink
#747 solution without cinterop
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex009 committed Dec 7, 2024
1 parent 55f4849 commit 7ed538c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
24 changes: 12 additions & 12 deletions resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ kotlin {
}

// setup bundle searcher for apple
targets
.withType<KotlinNativeTarget>()
.matching { it.konanTarget.family.isAppleFamily }
.configureEach {
compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME) {
val appleNative by cinterops.creating {
defFile(project.file("src/appleMain/def/appleNative.def"))

includeDirs("$projectDir/src/appleMain/objective-c")
}
}
}
// targets
// .withType<KotlinNativeTarget>()
// .matching { it.konanTarget.family.isAppleFamily }
// .configureEach {
// compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME) {
// val appleNative by cinterops.creating {
// defFile(project.file("src/appleMain/def/appleNative.def"))
//
// includeDirs("$projectDir/src/appleMain/objective-c")
// }
// }
// }
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources.utils

import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.ObjCClass
import platform.Foundation.NSBundle
import platform.darwin.NSObject

@OptIn(BetaInteropApi::class)
@ExportObjCClass
internal object MRBundleAnchor : NSObject() {

fun getBundle(): NSBundle {
val anchor: ObjCClass = requireNotNull(MRBundleAnchor.`class`()) {
"can't get class of $MRBundleAnchor"
}
return NSBundle.bundleForClass(anchor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package dev.icerock.moko.resources.utils

import dev.icerock.moko.resources.apple.native.ResourcesBundleAnchor
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSBundle
import platform.Foundation.NSDirectoryEnumerator
import platform.Foundation.NSFileManager
Expand All @@ -18,11 +16,7 @@ fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle {
// external directory, not inside app directory (NSBundle.main). for example in case of
// SwiftUI preview - app directory empty, but dynamic framework with resources will be in
// different directory (DerivedData)
@OptIn(ExperimentalForeignApi::class)
val rootBundle: NSBundle = requireNotNull(ResourcesBundleAnchor.getResourcesBundle()) {
"root NSBundle can't be found"
}
val bundlePath: String = rootBundle.bundlePath
val bundlePath: String = MRBundleAnchor.getBundle().bundlePath

val enumerator: NSDirectoryEnumerator = requireNotNull(
NSFileManager.defaultManager.enumeratorAtPath(bundlePath)
Expand Down

0 comments on commit 7ed538c

Please sign in to comment.