Skip to content

Commit a132e24

Browse files
committed
Try loading JNI symbol from global namespace when the dynamic library cannot be loaded
1 parent eacb84c commit a132e24

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Sources/SwiftJavaJNICore/VirtualMachine/JavaVirtualMachine.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private func symbol<T>(_ handle: DylibType, _ name: String) -> T? {
414414
#else
415415
private typealias DylibType = UnsafeMutableRawPointer
416416

417-
private func symbol<T>(_ handle: DylibType, _ name: String) -> T? {
417+
private func symbol<T>(_ handle: DylibType?, _ name: String) -> T? {
418418
guard let result = dlsym(handle, name) else {
419419
return nil
420420
}
@@ -459,13 +459,15 @@ func systemJavaHome() -> String? {
459459
}
460460

461461
/// Located the shared library that includes the `JNI_GetCreatedJavaVMs` and `JNI_CreateJavaVM` entry points to the `JNINativeInterface` function table
462-
private func loadLibJava() throws -> DylibType {
462+
private func loadLibJava() throws -> DylibType? {
463463
#if os(Android)
464464
for libname in ["libart.so", "libdvm.so", "libnativehelper.so"] {
465465
if let lib = dlopen(libname, RTLD_NOW) {
466466
return lib
467467
}
468468
}
469+
// fall back to the global space (https://github.com/swiftlang/swift-java/issues/419)
470+
return nil
469471
#endif
470472

471473
guard let javaHome = systemJavaHome() else {

0 commit comments

Comments
 (0)