导入"预建库"在Android-Studio(NDK支持)

时间:2017-04-01 01:12:49

标签: android android-studio android-ndk cmake shared-libraries

您好我在Android Studio中制作Android应用程序(版本2.3 - NDK支持)

我在导入库(dlib)时遇到问题

我从https://github.com/tzutalin/dlib-android下载了源代码并构建了它

  1. 我将.so文件(libandroid_dlib.so)复制到app / src / main / JniLibs / armeabi-v7a文件夹

  2. 我更改了CMakeLists.txt设置

  3. 我从MainActivity.java文件中加载了库
  4. 我的代码没有错误但是当我像上面那样导入dlib时,我的应用程序无法正常工作!

    是否错过了一步?非常感谢你提前

    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
                           )
    

0 个答案:

没有答案