从源代码构建OpenCV4Android不会输出libopencv_java.so

从源代码构建OpenCV4Android不会输出libopencv_java.so,android,opencv,Android,Opencv,我正试图按照上的教程从源代码构建适用于Android的OpenCV 3.2.0。这是因为最终我想定制构建,但现在我只满足于自己构建它 根据本教程,我正在运行以下命令,这些命令似乎已成功完成: export ANDROID_NDK=~/my-android-ndk export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain cd opencv/platforms sh ./scripts/cmake_android_arm.sh cd bu

我正试图按照上的教程从源代码构建适用于Android的OpenCV 3.2.0。这是因为最终我想定制构建,但现在我只满足于自己构建它

根据本教程,我正在运行以下命令,这些命令似乎已成功完成:

export ANDROID_NDK=~/my-android-ndk
export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
cd opencv/platforms
sh ./scripts/cmake_android_arm.sh
cd build_android_arm
make -j8
当我查看build\u android\u arm目录时,我看到了很多东西,包括我期望的所有.a文件。但是,似乎缺少一个文件:
libopencv_java.so
,这是openCV静态库管理器加载的实际库(我无法使用动态库管理器)。这个文件存在于Android示例中,手动复制到我的项目中确实有效。但我希望能够建立这个文件自己

我自己也尝试过使用各种CMake设置,但有数千种可能的选项组合,我不确定从何开始

我错过了什么

shell脚本的输出:

    CMake Deprecation Warning at /Applications/CMake.app/Contents/share/cmake-3.8/Modules/CMakeForceCompiler.cmake:83 (message):
      The CMAKE_FORCE_CXX_COMPILER macro is deprecated.  Instead just set
      CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
    Call Stack (most recent call first):
      /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/android/android.toolchain.cmake:1166 (CMAKE_FORCE_CXX_COMPILER)
      /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/build_android_arm/CMakeFiles/3.8.2/CMakeSystem.cmake:6 (include)
      /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/build_android_arm/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)


    -- Performing Test C_HAS_MFPU_NEON - Success
    -- Assume that non-module dependency is available: z (for module opencv_core)
    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-15-puzzle will not be build
    Call Stack (most recent call first):
      samples/android/15-puzzle/CMakeLists.txt:3 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-face-detection will not be build
    Call Stack (most recent call first):
      samples/android/face-detection/CMakeLists.txt:9 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-image-manipulations will not be build
    Call Stack (most recent call first):
      samples/android/image-manipulations/CMakeLists.txt:3 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-camera-calibration will not be build
    Call Stack (most recent call first):
      samples/android/camera-calibration/CMakeLists.txt:3 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-color-blob-detection will not be build
    Call Stack (most recent call first):
      samples/android/color-blob-detection/CMakeLists.txt:3 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-tutorial-1-camerapreview will not be build
    Call Stack (most recent call first):
      samples/android/tutorial-1-camerapreview/CMakeLists.txt:3 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-tutorial-2-mixedprocessing will not be build
    Call Stack (most recent call first):
      samples/android/tutorial-2-mixedprocessing/CMakeLists.txt:9 (add_android_project)


    CMake Warning at cmake/OpenCVDetectAndroidSDK.cmake:205 (message):
      Can not find any SDK target compatible with: 9 11

                           The project example-tutorial-3-cameracontrol will not be build
    Call Stack (most recent call first):
      samples/android/tutorial-3-cameracontrol/CMakeLists.txt:3 (add_android_project)


    -- Sample example-tutorial-4-opencl is disabled, because ANDROID_OPENCL_SDK is not specified
    -- 
    -- General configuration for OpenCV 3.2.0 =====================================
    --   Version control:               unknown
    -- 
    --   Platform:
    --     Timestamp:                   2017-06-16T18:53:59Z
    --     Host:                        Darwin 16.6.0 x86_64
    --     Target:                      Android 1 armv7-a
    --     CMake:                       3.8.2
    --     CMake generator:             Unix Makefiles
    --     CMake build tool:            /usr/bin/make
    --     Configuration:               Release
    -- 
    --   C/C++:
    --     Built as dynamic libs?:      NO
    --     C++ Compiler:                /Users/me/AndroidStudioProjects/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++  (ver 4.9)
    --     C++ flags (Release):         -fexceptions -frtti -fpic -Wno-psabi --sysroot=/Users/me/AndroidStudioProjects/android-ndk-r12b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG  -DNDEBUG
    --     C++ flags (Debug):           -fexceptions -frtti -fpic -Wno-psabi --sysroot=/Users/me/AndroidStudioProjects/android-ndk-r12b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG  -O0 -DDEBUG -D_DEBUG
    --     C Compiler:                  /Users/me/AndroidStudioProjects/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
    --     C flags (Release):           -fexceptions -fpic -Wno-psabi --sysroot=/Users/me/AndroidStudioProjects/android-ndk-r12b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG  -DNDEBUG
    --     C flags (Debug):             -fexceptions -fpic -Wno-psabi --sysroot=/Users/me/AndroidStudioProjects/android-ndk-r12b/platforms/android-9/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -mfp16-format=ieee -fvisibility=hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG  -O0 -DDEBUG -D_DEBUG
    --     Linker flags (Release):      -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now 
    --     Linker flags (Debug):        -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now 
    --     ccache:                      NO
    --     Precompiled headers:         NO
    --     Extra dependencies:          z dl m log
    --     3rdparty dependencies:       libjpeg libwebp libpng libtiff libjasper IlmImf tegra_hal
    -- 
    --   OpenCV modules:
    --     To be built:                 core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab
    --     Disabled:                    world
    --     Disabled by dependency:      -
    --     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 viz
    -- 
    --   Android: 
    --     Android ABI:                 armeabi-v7a
    --     STL type:                    gnustl_static
    --     Native API level:            android-9
    --     SDK target:                  android_sdk_target_status-NOTFOUND
    --     Android NDK:                 /Users/me/AndroidStudioProjects/android-ndk-r12b (toolchain: arm-linux-androideabi-4.9)
    --     android tool:                NO
    --     Google Play manager:         NO
    --     Android examples:            NO
    -- 
    --   GUI: 
    --     GTK+:                        NO
    --     GThread :                    NO
    --     GtkGlExt:                    NO
    --     OpenGL support:              NO
    --     VTK support:                 NO
    -- 
    --   Media I/O: 
    --     ZLib:                        z (ver 1.2.3)
    --     JPEG:                        build (ver 90)
    --     WEBP:                        build (ver 0.3.1)
    --     PNG:                         build (ver 1.6.24)
    --     TIFF:                        build (ver 42 - 4.0.2)
    --     JPEG 2000:                   build (ver 1.900.1)
    --     OpenEXR:                     build (ver 1.7.1)
    --     GDAL:                        NO
    --     GDCM:                        NO
    -- 
    --   Video I/O:
    -- 
    --   Parallel framework:            pthreads
    -- 
    --   Other third-party libraries:
    --     Use IPP:                     NO
    --     Use Eigen:                   NO
    --     Use Cuda:                    NO
    --     Use OpenCL:                  NO
    --     Use OpenVX:                  NO
    --     Use custom HAL:              YES (carotene (ver 0.0.1))
    -- 
    --   Python 2:
    --     Interpreter:                 /usr/bin/python2.7 (ver 2.7.10)
    -- 
    --   Python 3:
    --     Interpreter:                 /usr/local/bin/python3 (ver 3.6.1)
    -- 
    --   Python (for build):            /usr/bin/python2.7
    -- 
    --   Java:
    --     ant:                         NO
    --     Java wrappers:               NO
    --     Java tests:                  NO
    -- 
    --   Matlab:                        NO
    -- 
    --   Documentation:
    --     Doxygen:                     NO
    -- 
    --   Tests and samples:
    --     Tests:                       YES
    --     Performance tests:           YES
    --     C/C++ Examples:              NO
    -- 
    --   Install path:                  /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/build_android_arm/install
    -- 
    --   cvconfig.h is in:              /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/build_android_arm
    -- -----------------------------------------------------------------
    -- 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/me/AndroidStudioProjects/opencv-3.2.0/platforms/build_android_arm

使用
scripts/cmake\u android\u arm.sh
构建OpenCV时,
CMakeLists.txt
中定义的默认行为是构建所有模块的静态库,这就是为什么在运行
.sh
脚本后,您会得到
.a
文件,但是如果您想要构建共享库(
.so
)文件,然后,您需要使用上的标志-DBUILD\u FAT\u JAVA\u LIB=ON强制cmake

您需要将
脚本/cmake_android_arm.sh
编辑为:

#!/bin/sh
cd `dirname $0`/..

mkdir -p build_android_arm
cd build_android_arm

cmake -DBUILD_FAT_JAVA_LIB=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake $@ ../..
多亏了来自我的提示,我发现了遗漏的步骤:

  • 我没有ANT可执行文件,所以我从
  • CMAKE仍然没有拾取ANT可执行文件,因此我手动编辑了标记ANT_可执行文件,将其作为指向该文件的文件路径,例如
    /Users/me/apache-ANT-1.10.1/bin/ANT
    。我在配置之后但在生成CMAKE之前执行了此操作
  • 我不确定是否需要,但为了更好地衡量,我还手动设置了以下参数:

    BUILD_FAT_JAVA_LIB: true (thanks ZdaR)
    BUILD_opencv_java: true
    JAVA_AWT_INCLUDE_PATH: /myJDKlocation/Contents/Home/include
    JAVA_AWT_LIBRARY: /myJDKlocation/Contents/Home/include/jawt.h
    JAVA_INCLUDE_PATH: /myJDKlocation/Contents/Home/include
    JAVA_INCLUDE_PATH2: /myJDKlocation/Contents/Home/include/darwin
    JAVA_JVM_LIBRARY: /myJDKlocation/Contents/Home/include/jni.h
    ANT_EXECUTABLE: /Users/me/apache-ant-1.10.1/bin/ant
    
  • generate
    的输出现在略有不同:

       Java:
          ant:                         /Users/me/apache-ant-1.10.1/bin/ant (ver 1.10.1)
          Java wrappers:               YES
          Java tests:                  NO
    

    现在,当我
    generate
    make
    makeinstall
    时,我可以在
    lib
    目录中看到
    libopencv\u java3.so
    文件。快乐的日子

    我认为这可能是关键,但遗憾的是构建输出没有变化。我在我的问题中添加了一些额外的输出,以防有什么线索?我用OpenCV 3.1.0在我的机器上运行了相同的脚本,它工作得很好运行脚本后你运行了
    make-j8
    吗?是的,之后大约20分钟的行,如
    [0%]构建C对象第三方/libpng/CMakeFiles/libpng.dir/png.C.o
    hmmmm好的,编译成功执行了吗?看起来,make在100%后退出,没有错误