Android 编译 opencv

参考:

  1. https://www.sisik.eu/blog/android/ndk/opencv-without-java
  2. https://www.jianshu.com/p/288ca9327b32
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=/home/jiahang/Android/Sdk/ndk/android-ndk-r20b/build/cmake/android.toolchain.cmake \
-DANDROID_NDK=/home/jiahang/Android/Sdk/ndk/android-ndk-r20b \
-DANDROID_NATIVE_API_LEVEL=android-21 \
-DBUILD_JAVA=OFF \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_ANDROID_PROJECTS=OFF \
-DANDROID_STL=c++_shared \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX:PATH=/home/jiahang/Desktop/absolute/opencv/android_build/out \
-DANDROID_ABI=arm64-v8a

上面的不好用,再试下面的:

/home/jiahang/Android/Sdk/cmake/3.10.2.4988404/bin/cmake \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DCMAKE_TOOLCHAIN_FILE="/home/jiahang/Android/Sdk/ndk/android-ndk-r20b/build/cmake/android.toolchain.cmake" \
-DANDROID_SDK_ROOT="/home/jiahang/Android/Sdk" \
-DANDROID_NDK="/home/jiahang/Android/Sdk/ndk/android-ndk-r20b" \
-DANDROID_NATIVE_API_LEVEL=android-21 \
-DANDROID_ABI="arm64-v8a" \
-D WITH_CUDA=OFF \
-D WITH_MATLAB=OFF \
-D BUILD_ANDROID_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX="android_opencv" \
..
make -j12

发现sdk有问题:
解决:
在opencv_android中建立local.properties文件,写入:

sdk.dir = /home/jiahang/Android/Sdk

发现NDK有问题:
解决:
配置环境变量:

sudo vim ~/.bashrc

末尾写入:

export ANDROID_NDK_HOME=/home/jiahang/Android/Sdk/ndk/android-ndk-r20b

然后:

source ~/.bashrc

最后

make install
posted @ 2019-12-13 11:10  jiahangok  阅读(1010)  评论(0编辑  收藏  举报