1

Hi I'm making a android app in Android Studio (ver 2.3 - NDK SUPPORT)

I have a problem with importing library (dlib)

I downloaded source code from https://github.com/tzutalin/dlib-android and built it

  1. I copied .so file(libandroid_dlib.so) to app/src/main/JniLibs/armeabi-v7a folder

  2. I changed a CMakeLists.txt settings

  3. I loaded library from MainActivity.java file

My code has no errors but when I import dlib like above, my app doesn't work anything !

Is there a missed step? THANK YOU SO MUCH IN ADVANCE

MainActivity.java

static {
    System.loadLibrary("opencv_java3");
    System.loadLibrary("android_dlib");
    System.loadLibrary("imported-lib");
    System.loadLibrary("native-lib");
}

CMakeLists.txt

set(pathOPENCV /Users/gicheonkang/OpenCV-android-sdk)
set(pathPROJECT /Users/gicheonkang/AndroidStudioProjects/HelloWorld)
set(pathLIBOPENCV_JAVA ${pathPROJECT}/app/src/main/JniLibs/${ANDROID_ABI}/libopencv_java3.so)

set(pathDLIB /Users/gicheonkang/dlib)
set(pathLIBDLIB ${pathPROJECT}/app/src/main/JniLibs/${ANDROID_ABI}/libandroid_dlib.so)


cmake_minimum_required(VERSION 3.4.1)

# CMAKE settings
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")


# include *.cpp and *.h file
file(GLOB Library_SOURCES_FACEANALYSER  src/main/cpp/FaceAnalyser/*.cpp)
file(GLOB Library_HEADERS_FACEANALYSER   src/main/cpp/FaceAnalyser/*.h)


include_directories(${pathOPENCV}/sdk/native/jni/include)
include_directories(${pathDLIB}/dlib)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             # Associated headers in the same location as their source
             # file are automatically included.
             src/main/cpp/native-lib.cpp )


add_library( lib_opencv SHARED IMPORTED )
add_library( dlib SHARED IMPORTED )
add_library( imported-lib SHARED ${Library_SOURCES_FACEANALYSER} ${Library_HEADERS_FACEANALYSER})


set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathLIBOPENCV_JAVA})
set_target_properties( dlib PROPERTIES IMPORTED_LOCATION ${pathLIBDLIB})
set_target_properties( imported-lib PROPERTIES LINKER_LANGUAGE CXX )



find_library( log-lib log )
find_library( android-lib android)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                      imported-lib

                      # Links the target library to the log library
                      # included in the NDK.
                      lib_opencv

                      #here is the problem
                      #dlib
                      )

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                       ${android-lib}
                       #imported-lib
                       lib_opencv


                       #here is the problem!!!!!!
                       #dlib
                       )
kang chon
  • 21
  • 3
  • it might help - https://stackoverflow.com/questions/40162157/how-to-add-prebuilt-so-library-in-android-studio-2-2 – Debu Oct 10 '17 at 13:43

0 Answers0