[solved][android] Couldn't find native library tvm4j_runtime_packed

Hi,
I am trying to deploy on android, the app cannot find the tvm4j library:

2654 05-29 16:56:32.487 25059 25074 W System.err: creating java tvm context...
2655 05-29 16:56:32.488 25059 25074 W System.err: loading compiled functions...
2656 05-29 16:56:32.488 25059 25074 W System.err: /data/user/0/ml.dmlc.tvm.android.androidcamerademo/cache/tvm4j_demo_4274620982317633484/deploy_lib_opencl.so
2657 05-29 16:56:32.488 25059 25074 W System.err: Try loading tvm4j from native path.
2658 05-29 16:56:32.489 25059 25074 W System.err: Try loading tvm4j-linux-x86_64 from native path.
2659 05-29 16:56:32.489 25059 25074 W System.err: [WARN] TVM native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH), or specifying by Java cmd option -Dj     ava.library.path=[lib path].
2660 05-29 16:56:32.490 25059 25074 W System.err: Attempting to load libtvm4j.so
2661 05-29 16:56:32.491 25059 25074 W System.err: [WARN] Couldn't find native library tvm4j.
2662 05-29 16:56:32.491 25059 25074 W System.err: java.lang.UnsatisfiedLinkError: Couldn't find the resource libtvm4j.so (@ /lib/native/libtvm4j.so)
2663 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.NativeLibraryLoader.extractResourceFileToTempDir(NativeLibraryLoader.java:127)
2664 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:87)
2665 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Base.<clinit>(Base.java:73)
2666 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Function.listGlobalFuncNames(Function.java:52)
2667 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Function.getFunction(Function.java:38)
2668 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Module.getApi(Module.java:41)
2669 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Module.load(Module.java:140)
2670 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.Module.load(Module.java:146)
2671 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.android.androidcamerademo.Camera2BasicFragment$LoadModelAsyncTask.doInBackground(Camera2BasicFragment.java:752)
2672 05-29 16:56:32.491 25059 25074 W System.err:    at ml.dmlc.tvm.android.androidcamerademo.Camera2BasicFragment$LoadModelAsyncTask.doInBackground(Camera2BasicFragment.java:672)
2673 05-29 16:56:32.491 25059 25074 W System.err:    at android.os.AsyncTask$2.call(AsyncTask.java:333)
2674 05-29 16:56:32.491 25059 25074 W System.err:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2675 05-29 16:56:32.491 25059 25074 W System.err:    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2676 05-29 16:56:32.491 25059 25074 W System.err:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2677 05-29 16:56:32.491 25059 25074 W System.err:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2678 05-29 16:56:32.491 25059 25074 W System.err:    at java.lang.Thread.run(Thread.java:764)
2679 05-29 16:56:32.491 25059 25074 W System.err: Try to load tvm4j (runtime packed version) ...
2680 05-29 16:56:32.492 25059 25074 W System.err: [ERROR] Couldn't find native library tvm4j_runtime_packed.

The app throws an error on loading the tvm4j runtime packed version, however it is present in the libs folder of the app and under the right architecture, I can also grep it in the apk.

1 Like

I found it by printing the stacktrace at the error catch when loading tvm4j_runtime_packed (it should be in the code to prevent error misinterpretation in my opinion, as it is for the loading of tvm4j_runtime), it couldn’t find libGLES_mali.so, that has something to do with OpenCL.
I set temporarily USE_OPENCL=1 as I don’t need it, it solves the problem.
I guess providing libGLES_mali.so (pulled from the device, or obtained from the ndk) in the libs folder of the application can be a workaround.