Skip to content

Commit

Permalink
Update initBridge function to be callable through reflection from Ski…
Browse files Browse the repository at this point in the history
…pFoundation
  • Loading branch information
marcprux committed Nov 27, 2024
1 parent 5bb3aac commit aeea82a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Sources/SkipAndroidBridge/AndroidBridgeBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() }

Expand Down
19 changes: 12 additions & 7 deletions Sources/SkipAndroidBridgeKt/AndroidBridgeKt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down

0 comments on commit aeea82a

Please sign in to comment.