[Android] Building the OpenCV v2.4.x Library for Android

OpenCV_Logo_with_text

0. Build Environment
Mac OSX v10.11.6
Android NDK r12b
CMake 3.0.2
OpenCV 2.4.9

1. Build Instructions
1) Open a new Terminal window and use the following command to add the NDK path to your environment variables. I’m using android-ndk-r12b here:

export ANDROID_NDK=~/my-android-ndk

For example, here’s my path:

export ANDROID_NDK=~/android-ndk-r12b/

2) Go to your OpenCV source directory (I’m using version 2.4.9), then navigate to platform/scripts:

cd platforms/scripts/

Run the script:

sh cmake_android_arm.sh 

P.S. If you want to build with NEON acceleration enabled, use the script below:
cmake_android_arm_neon.sh

If you see the following output:

-- Configuring done
-- Generating done

That means CMake successfully generated the Makefile project.

3) Build OpenCV:
Navigate to the platforms/build_android_arm directory:

cd ../build_android_arm/

Then just run make:

make

Once the build is complete, you’ll find the compiled libraries in the platforms/build_android_arm/lib/armeabi-v7a directory.

This method is useful if you’ve modified the OpenCV source code or want to use a different version of the NDK. If you just need the standard OpenCV Android SDK, you can download the prebuilt version directly from the official site:
https://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.9/OpenCV-2.4.9-android-sdk.zip/download

Common Issues:
1) Error: Specified Android native API level ‘android-8’ is not supported by your NDK/toolchain.
Replace the contents of platforms/android/android.toolchain.cmake with the version at the link below (the latest version from the OpenCV 2.4.x branch):
https://github.com/opencv/opencv/blob/2.4/platforms/android/android.toolchain.cmake

Add a Comment

Your email address will not be published. Required fields are marked *