From aeea82aef6616bd60e6a9078dcfd6caa77c861cf Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 27 Nov 2024 18:29:44 -0500 Subject: [PATCH] Update initBridge function to be callable through reflection from SkipFoundation --- .../AndroidBridgeBootstrap.swift | 4 ++-- .../SkipAndroidBridgeKt/AndroidBridgeKt.swift | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/SkipAndroidBridge/AndroidBridgeBootstrap.swift b/Sources/SkipAndroidBridge/AndroidBridgeBootstrap.swift index 6a93ddc..044170e 100644 --- a/Sources/SkipAndroidBridge/AndroidBridgeBootstrap.swift +++ b/Sources/SkipAndroidBridge/AndroidBridgeBootstrap.swift @@ -55,7 +55,7 @@ public class AndroidBridgeBootstrap { } } -private func bootstrapTimezone() { +private func bootstrapTimezone() throws { // Until https://github.com/swiftlang/swift-foundation/pull/1053 gets merged tzset() var t = time(nil) @@ -94,7 +94,7 @@ private func bootstrapSSLCertificates(fromCertficateFolders certsFolders: [Strin let cacheFolder = FileManager.default.temporaryDirectory let generatedCacertsURL = cacheFolder.appendingPathComponent("cacerts-\(UUID().uuidString).pem") - FileManager.default.createFile(atPath: generatedCacertsURL.path, contents: nil) + _ = FileManager.default.createFile(atPath: generatedCacertsURL.path, contents: nil) let fs = try FileHandle(forWritingTo: generatedCacertsURL) defer { try? fs.close() } diff --git a/Sources/SkipAndroidBridgeKt/AndroidBridgeKt.swift b/Sources/SkipAndroidBridgeKt/AndroidBridgeKt.swift index 5d8baf8..33314a4 100644 --- a/Sources/SkipAndroidBridgeKt/AndroidBridgeKt.swift +++ b/Sources/SkipAndroidBridgeKt/AndroidBridgeKt.swift @@ -17,14 +17,19 @@ fileprivate let logger: Logger = Logger(subsystem: "SkipAndroidBridge", category /// just involves loading the specific library and calling the Swift `AndroidBridgeBootstrap.initAndroidBridge()`, /// which will, in turn, perform all the Foundation-level setup. public class AndroidBridge { - /// This is called at app initialization time, typically from the `Main.kt` + /// This is called at app initialization time by reflection from the `Main.kt` /// - /// It will look like: `skip.android.bridge.kt.AndroidBridge.initBridge(this, "AppDroidModel")` - public static func initBridge(app: android.app.Application, _ libraryName: String) throws { - let context = app.applicationContext - ProcessInfo.launch(context) - logger.debug("loading library: \(libraryName)") - try System.loadLibrary(libraryName) + /// It will look like: `skip.android.bridge.kt.AndroidBridge.initBridge("AppDroidModel")` + public static func initBridge(_ libraryNames: String) throws { + for libraryName in libraryNames.split(separator: ",") { + do { + logger.debug("loading library: \(libraryName)") + try System.loadLibrary(libraryName) + } catch { + android.util.Log.e("SkipBridge", "error loading bridge library: \(libraryName)", error as? ErrorException) + } + } + try AndroidBridgeBootstrap.initAndroidBridge() } }