Unfortunately on arm64-v8a the application crashes with the following error
java.lang.UnsatisfiedLinkError: dlopen failed: library "libpytorch_jni_lite.so" not found: needed by /data/data/com.example.testlib/code_cache/.overlay/base.apk/lib/arm64-v8a/libtestlib.so in namespace classloader-namespace
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
at java.lang.System.loadLibrary(System.java:1664)
at com.example.testlib.MainActivity.<clinit>(MainActivity.java:14)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3956)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
It seems that libtorch_jni_lite.so is not found. Can someone please help me to understand better how to solve?
Thanks
Hey @erict, would you mind sharing what modification you have made based on the tutorial? @Linbin may be able to help with that once we get more info about the issue.
Hi @guangy10,
following i am reporting what i have changed. Basically I refactor the example with a more simpler one and update the library with libtorch 1.9.0.
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project("testlib")
set(LIB_TR /media/aistudios/44c62318-a7de-4fb6-a3e2-01aba49489c5/Develop/Official/DockerContainer/Android/Develop/testLib/pytorch_android_lite-1.9.0.aar)
#link_directories(${LIB_TR})
add_library(
testlib
SHARED
native-lib.cpp)
add_library( imported-pytorch
SHARED
IMPORTED )
set_target_properties(
imported-pytorch
PROPERTIES IMPORTED_LOCATION
${LIB_TR}/jni/${ANDROID_ABI}/libpytorch_jni_lite.so )
add_library( imported-jni
SHARED
IMPORTED )
set_target_properties( # Specifies the target library.
imported-jni
PROPERTIES IMPORTED_LOCATION
${LIB_TR}/jni/${ANDROID_ABI}/libfbjni.so )
find_library( # Sets the name of the path variable.
log-lib
log)
target_include_directories(testlib PUBLIC ${LIB_TR}/headers )
target_link_libraries(
testlib
imported-pytorch
# Links the target library to the log library
# included in the NDK.
${log-lib})
As i reported this code is working on x86 but it is crashing on arm64-v8a device. I have followed the tutorial to extract libtorch_jni_lite.so from the aar archive.
If you have any idea on how i can fix this, please let me know. Thanks