Skip to content

Commit

Permalink
Edit Java bindins to allow loading/extracting shared provider libs on…
Browse files Browse the repository at this point in the history
… Android
  • Loading branch information
adrianlizarraga committed Dec 19, 2024
1 parent 058e7bb commit 4172575
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions java/src/main/java/ai/onnxruntime/OnnxRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ static synchronized void init() throws IOException {
// the ONNX Runtime native library will load it
extractProviderLibrary(ONNXRUNTIME_LIBRARY_SHARED_NAME);

load(ONNXRUNTIME_LIBRARY_NAME);
load(ONNXRUNTIME_JNI_LIBRARY_NAME);
if (isAndroid()) {
// On Android, we only need to load onnxruntime4j_jni with System.loadLibrary
System.loadLibrary(ONNXRUNTIME_JNI_LIBRARY_NAME);
} else {
load(ONNXRUNTIME_LIBRARY_NAME);
load(ONNXRUNTIME_JNI_LIBRARY_NAME);
}

ortApiHandle = initialiseAPIBase(ORT_API_VERSION_14);
if (ortApiHandle == 0L) {
throw new IllegalStateException(
Expand Down Expand Up @@ -273,10 +279,6 @@ static boolean extractQNN() {
* @return True if the library is ready for loading by ORT's native code, false otherwise.
*/
static synchronized boolean extractProviderLibrary(String libraryName) {
// Android does not need to extract library and it has no shared provider library
if (isAndroid()) {
return false;
}
// Check if we've already extracted or check this provider, and it's ready
if (extractedSharedProviders.contains(libraryName)) {
return true;
Expand Down Expand Up @@ -323,12 +325,6 @@ static boolean isAndroid() {
* @throws IOException If the file failed to read or write.
*/
private static void load(String library) throws IOException {
// On Android, we simply use System.loadLibrary
if (isAndroid()) {
System.loadLibrary("onnxruntime4j_jni");
return;
}

// 1) The user may skip loading of this library:
String skip = System.getProperty("onnxruntime.native." + library + ".skip");
if (Boolean.TRUE.toString().equalsIgnoreCase(skip)) {
Expand Down

0 comments on commit 4172575

Please sign in to comment.