Skip to content

Commit

Permalink
(multi-os-engine/multi-os-engine#153) Fix framework load on simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Dec 25, 2021
1 parent 9177193 commit 81673f2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/moe/natj/general/NatJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static NativeRuntime getOrCreateInstanceOfRuntimeClass(
*/
private static final ConcurrentHashMap<Class<?>, Class<? extends NativeRuntime>> CLASS_RUNTIME_CACHE =
new ConcurrentHashMap<Class<?>, Class<? extends NativeRuntime>>();

/**
* Determines the runtime of the class by looking for a {@link Runtime}
* annotation of the class or its ascendants and interfaces.
Expand All @@ -335,7 +335,7 @@ private static Class<? extends NativeRuntime> getRuntimeClass(Class<?> type) {
}
return nativeRuntime;
}

/**
* Determines the runtime of the class by looking for a {@link Runtime}
* annotation of the class or its ascendants and interfaces.
Expand Down Expand Up @@ -480,6 +480,7 @@ protected static String lookUpLibrary(String name, boolean load) {
for (String path : new String[] {
"/System/Library/Frameworks/" + name + ".framework"
}) {
String exec_path = path + "/" + name;
File file = new File(path);
if (file.exists() && file.isDirectory()) {
/* Framework bundle was found.
Expand All @@ -491,14 +492,22 @@ protected static String lookUpLibrary(String name, boolean load) {
* separate framework executable on file system but we can load it
* by name.
*/
String exec_path = path + "/" + name;
resolvedLibraries.put(name, exec_path);
if (load) {
boolean res = loadFramework(exec_path);
if (!res) throw new RuntimeException(
"Cannot load executable file from system framework " + path );
}
return exec_path;
} else if (load) {
// On ios simulator the framework path is dynamic based on the location of the Xcode,
// so we cannot reliably determine if the framework exists, and we have to just try
// loading the framework and if it succeeded then we assume it exist.
boolean res = loadFramework(exec_path);
if (res) {
resolvedLibraries.put(name, exec_path);
return exec_path;
}
}
}
} else if (isDalvik()) {
Expand Down

0 comments on commit 81673f2

Please sign in to comment.