c++ - java.lang.UnsatisfiedLinkError: dlopen failed 64-bit instead of 32-bit while .so should be built in x86 -
i trying use jni in android studio, added jni function under sample native-lib.cpp created android studio default (after adding c++ support)
however, facing error
java.lang.unsatisfiedlinkerror: no implementation found boolean com.example.user.project.tracker.istracking_0(boolean) (tried java_com_example_user_project_tracker_istracking_10 , java_com_example_user_project_tracker_istracking_10__z)
i tried add mainactivity
static { system.loadlibrary("tracker"); }
but exception
java.lang.unsatisfiedlinkerror: dlopen failed: "/data/app/com.example.user.project/lib/x86/libtracker.so" 64-bit instead of 32-bit
i can see library has been built successfully, track message shows when build
build tracker x86 [1/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/fhog.cpp.o [2/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/tracker.cpp.o [3/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/ctracker.cpp.o [4/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/native-lib.cpp.o [5/5] linking cxx shared library ../../../../build/intermediates/cmake/debug/obj/x86/libtracker.so build tracker mips [1/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/tracker.cpp.o [2/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/fhog.cpp.o [3/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/ctracker.cpp.o [4/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/native-lib.cpp.o [5/5] linking cxx shared library ../../../../build/intermediates/cmake/debug/obj/mips/libtracker.so build tracker x86_64 [1/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/tracker.cpp.o [2/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/fhog.cpp.o [3/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/ctracker.cpp.o [4/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/native-lib.cpp.o [5/5] linking cxx shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libtracker.so build tracker armeabi [1/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/tracker.cpp.o [2/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/fhog.cpp.o [3/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/ctracker.cpp.o [4/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/native-lib.cpp.o [5/5] linking cxx shared library ../../../../build/intermediates/cmake/debug/obj/armeabi/libtracker.so build tracker armeabi-v7a [1/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/tracker.cpp.o [2/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/fhog.cpp.o [3/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/ctracker.cpp.o [4/5] building cxx object cmakefiles/tracker.dir/src/main/cpp/native-lib.cpp.o [5/5] linking cxx shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libtracker.so
this cmakelists
set (pathtoopencv /home/user/opencv-android-sdk3.2) set (pathtoproject /home/user/androidstudioprojects/project) cmake_minimum_required(version 3.4.1) set(cmake_verbose_makefile on) include_directories(${pathtoopencv}/sdk/native/jni/include) file(glob_recurse cppfiles "src/main/cpp/*.cpp") add_library(lib_opencv shared imported) add_library(tracker shared ${cppfiles}) set_target_properties(lib_opencv properties imported_location ${pathtoproject}/app/src/main/jnilibs/${android_abi}/libopencv_java3.so) find_library( log-lib log ) target_link_libraries( tracker ${log-lib} lib_opencv )
this native-lib.cpp
#include <jni.h> #include <string> extern "c" jniexport jboolean jnicall java_com_example_user_project_tracker_istracking_10 (jnienv *env, jboolean boolean) { printf("\n c-boolean: %d ", boolean); if (boolean == jni_true) { printf("true"); } else { printf("false"); } boolean = false; return boolean; };
so reason android studio cannot find method .so library, , appear java.lang.unsatisfiedlinkerror? also, don't why x86 library 64bit instead of 32bit.
thanks
update
just double check android log, think not load tracker library properly. think 64 bits error major problem. update issue title
java.lang.unsatisfiedlinkerror: dlopen failed: "/data/app/com.example.user.project/lib/x86/libtracker.so" 64-bit instead of 32-bit
in build.gradle have set abifilter, , avd x86 device
apply plugin: 'com.android.application'
android { compilesdkversion 26 buildtoolsversion "26.0.1" defaultconfig { applicationid "com.example.user.project" minsdkversion 23 targetsdkversion 26 versioncode 1 versionname "1.0" testinstrumentationrunner "android.support.test.runner.androidjunitrunner" externalnativebuild { cmake { cppflags "" } } } sourcesets.main { jnilibs.srcdir 'src/main/jnilibs' jni.srcdirs = [] } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } externalnativebuild { cmake { path "cmakelists.txt" } } defaultconfig { ndk { abifilters "armeabi", "armeabi-v7a", "x86", "x86_64", "mips" } } } // call regular ndk-build(.cmd) script app directory dependencies { compile filetree(include: ['*.jar'], dir: 'libs') androidtestcompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testcompile 'junit:junit:4.12' compile project(':opencvlibrary320') }
here caused problem:
sourcesets.main { jnilibs.srcdir 'src/main/jnilibs' jni.srcdirs = [] }
these definitions not coexist safely externalnativebuild.
essentially, in new android studio jni.srcdirs not relevant. finds c/++ files use analyzing cmake or ndk-build logs. when use externalnativebuild, copies binaries finds in jnilibs final apk. somehow wrong version of libtracker.so got stuck in src/main/jnilibs/x86 directory. important remember build or rebuild won't remove/update binaries there.
Comments
Post a Comment