How to change Install Dir when Building OpenCV 3.1.0 on Ubuntu 18.04 for Android NDK18rc and ARMEABI-7?

asked 2018-10-05 22:53:48 -0600

qamaruddin gravatar image

updated 2018-10-06 00:06:30 -0600

I am trying for over one week to compile OpenCV 3.1.0 for Android with NDK r18 on Ubuntu 18.04.

I have used the following command:

cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
  -DANDROID_NDK="/home/qamaruddin/Downloads/android-ndk-r18-linux-x86_64/android-ndk-r18/" \
  -DCMAKE_TOOLCHAIN_FILE="/home/qamaruddin/Downloads/android-ndk-r18-linux-x86_64/android-ndk-r18/build/cmake/android.toolchain.cmake" \
  -DANDROID_NATIVE_API_LEVEL=19 \
  -DANDROID_ABI="armeabi-v7a" \
  -DWITH_CUDA=OFF \
  -DWITH_MATLAB=OFF \
  -DBUILD_ANDROID_EXAMPLES=OFF \
  -DBUILD_DOCS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DBUILD_TESTS=OFF \
  -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
  -DCMAKE_C_COMPILER=/usr/bin/clang \
  -DOPENCV_EXTRA_MODULES_PATH="/opt/opencv_contrib/modules/"  \
  -DCMAKE_INSTALL_PREFIX:PATH="/home/mig-ocv/ocv-android-310/" \
  -DEXECUTABLE_OUTPUT_PATH:PATH="/home/mig-ocv/ocv-android-310/" \
  -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="/home/mig-ocv/ocv-android-310/" \
  -DCMAKE_BUILD_TYPE=Release \
  /opt/opencv

Follwed by make & make install/strip.

I have tried different versions of OpenCV 3 such as 3.1.0, 3.4.3, and 3.4.0. I have also tried NDKr15c, NDKr17c, and NDKr18c.

I have tried the following variations:

  1. Change NDK version
  2. Change OpenCV 3 version
  3. Install using python script located at opencv/platforms/androind/setup.py
  4. Build using CMAKE
  5. Use Ninja for CMAKE, but this gives the error: "ninja: error: loading 'build/build.global.ninja': No such file or directory"
  6. Install without Ninja with CMAKE

At the moment, using the above-posted command for CMAKE builds successfully, but I can't change the target install dir since it always builds into /usr/local/ and when I inspect the target directory it does not have the familiar OpenCV for Android structure which is:

1- etc 2- java 3- native --> jni --> include

I wonder what is wrong in my process that makes it so difficult to build OpenCV 3 from source for Android with OpenCV Contrib.

Note that $ANDROID_HOME is set to the android SDKs directory on my system and $ANDROID_NDK is also set.

I have seen all duplicate questions on StackOverflow and other forums, but none seems to work in my case.

When I try to build with Ninja with this command:

cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
  -DANDROID_NDK="$HOME/Downloads/android-ndk-r17b/" \
  -DCMAKE_TOOLCHAIN_FILE="$HOME/Downloads/android-ndk-r17b/build/cmake/android.toolchain.cmake" \
  -DANDROID_NATIVE_API_LEVEL=21 \
  -DANDROID_ABI="armeabi-v7a" \
  -DWITH_CUDA=OFF \
  -DWITH_MATLAB=OFF \
  -DBUILD_ANDROID_EXAMPLES=OFF \
  -DBUILD_DOCS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DBUILD_TESTS=OFF \
  -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
  -DCMAKE_C_COMPILER=/usr/bin/clang \
  -DOPENCV_EXTRA_MODULES_PATH="$HOME/ocv/opencv_contrib/modules/"  \
  -DCMAKE_INSTALL_PREFIX:PATH="$HOME/agusta/ocv-android-310/" \
  -DEXECUTABLE_OUTPUT_PATH:PATH="$HOME/agusta/ocv-android-310/" \
  -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="$HOME/agusta/ocv-android-310/" \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
  $HOME/ocv/opencv

I get:

CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):


The OLD behavior for policy CMP0022 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Deprecation Warning at CMakeLists.txt:77 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances ...
(more)
edit retag flag offensive close merge delete

Comments

  • please use current 3.4 branch, don't try with outdated 3.1.0
  • CMAKE_INSTALL_PREFIX is the install location
  • you're trying to use your system's compilers, that won't work
  • please use the python buildscript from here (needs ninja, too)
berak gravatar imageberak ( 2018-10-06 02:37:23 -0600 )edit

Thanks for feedback, but it give me this error with OC3.4.3 and NDKr17c:

CMake Error at /home/qamaruddin/Downloads/android-ndk-r17c-linux-x86_64/android-ndk-r17c/build/cmake/android.toolchain.cmake:312 (message): Invalid Android ABI: armeabi. (armeabi is no longer supported. Use armeabi-v7a.)

qamaruddin gravatar imageqamaruddin ( 2018-10-06 11:03:38 -0600 )edit

i'm not using any of it, but what if you just believe the message ?

berak gravatar imageberak ( 2018-10-06 11:25:12 -0600 )edit