diff --git a/java/src/main/java/ai/onnxruntime/OnnxRuntime.java b/java/src/main/java/ai/onnxruntime/OnnxRuntime.java index 01bf33f8d36e5..0830ed5b7db39 100644 --- a/java/src/main/java/ai/onnxruntime/OnnxRuntime.java +++ b/java/src/main/java/ai/onnxruntime/OnnxRuntime.java @@ -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( @@ -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; @@ -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)) {