Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Building JNI for OpenCV in Android

Bear with me - this is a long description, but I wanted to include all details. I'm trying use android NDK and JNI for building OpenCV Android apps.

I'm following this tutorial to get everything installed: http://www.stanford.edu/class/ee368/Android/Tutorial-2-OpenCV-for-Android-Setup-Macintosh-API8.pdf

The following installed just fine:

/usr/bin/g++
/usr/local/bin/swig
/usr/bin/cmake
/usr/bin/make
/Developer/pcre-8.32/

Contents of my .bashrc file:

export  NDK=/Users/Me/Code/Android/android-ndk-r4-crystax
export  SDK=/Users/Me/Code/Android/adt-bundle-mac-x86_64-20130219/
export  OPCV=/Users/Me/Code/OpenCV/opencv
export  PATH=$NDK:$SDK/tools:$SDK/platform-tools:$PATH
export NDK_ROOT=$NDK

Making OpenCV libraries went just fine.

Due to complaint in using make, I had to make a small edit in /Users/Me/Code/OpenCV/opencv/android/android-jni/local.env.mk which looked like so:

#ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
ANDROID_NDK_ROOT=/Users/Me/Code/Android/android-ndk-r4-crystax

Then upon trying again to make in the android-jni, directory, disaster struck:

/Users/Me/Code/Android/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
SharedLibrary  : libandroid-opencv.so
/Users/Me/Code/Android/android-ndk-r4-crystax/build/prebuilt/darwin-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -lopencv_calib3d
collect2: ld returned 1 exit status
make[1]: *** [/Users/Me/Code/OpenCV/opencv/android/android-jni/obj/local/armeabi/libandroid-opencv.so] Error 1
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2

I thought perhaps this was a pkg-config error, but that appears to be set up as well, though in my old install of OpenCV. Below is the output of pkg-config --cflags --libs opencv:

-I/usr/include/opencv  /usr/lib/libopencv_calib3d.dylib /usr/lib/libopencv_contrib.dylib /usr/lib/libopencv_core.dylib /usr/lib/libopencv_features2d.dylib /usr/lib/libopencv_flann.dylib /usr/lib/libopencv_gpu.dylib /usr/lib/libopencv_highgui.dylib /usr/lib/libopencv_imgproc.dylib /usr/lib/libopencv_legacy.dylib /usr/lib/libopencv_ml.dylib /usr/lib/libopencv_nonfree.dylib /usr/lib/libopencv_objdetect.dylib /usr/lib/libopencv_photo.dylib /usr/lib/libopencv_stitching.dylib /usr/lib/libopencv_ts.dylib /usr/lib/libopencv_video.dylib /usr/lib/libopencv_videostab.dylib

The install built by this particular tutorial has placed an opencv.pc file at this location:

/Users/Me/Code/OpenCV/opencv/build/unix-install

BUT Running the below and trying make again doesn't fix the problem:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Users/Me/Code/OpenCV/opencv/build/unix-install

Any ideas on how I can complete this build?

Building JNI for OpenCV in Android

Bear with me - this is a long description, but I wanted to include all details. I'm trying use android NDK and JNI for building OpenCV Android apps.apps. I've also tried posting on SO with no avail.

I'm following this tutorial to get everything installed: http://www.stanford.edu/class/ee368/Android/Tutorial-2-OpenCV-for-Android-Setup-Macintosh-API8.pdf

The following installed just fine:

/usr/bin/g++
/usr/local/bin/swig
/usr/bin/cmake
/usr/bin/make
/Developer/pcre-8.32/

Contents of my .bashrc file:

export  NDK=/Users/Me/Code/Android/android-ndk-r4-crystax
export  SDK=/Users/Me/Code/Android/adt-bundle-mac-x86_64-20130219/
export  OPCV=/Users/Me/Code/OpenCV/opencv
export  PATH=$NDK:$SDK/tools:$SDK/platform-tools:$PATH
export NDK_ROOT=$NDK

Making OpenCV libraries went just fine.

Due to complaint in using make, I had to make a small edit in /Users/Me/Code/OpenCV/opencv/android/android-jni/local.env.mk which looked like so:

#ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
ANDROID_NDK_ROOT=/Users/Me/Code/Android/android-ndk-r4-crystax

Then upon trying again to make in the android-jni, directory, disaster struck:

/Users/Me/Code/Android/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
SharedLibrary  : libandroid-opencv.so
/Users/Me/Code/Android/android-ndk-r4-crystax/build/prebuilt/darwin-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -lopencv_calib3d
collect2: ld returned 1 exit status
make[1]: *** [/Users/Me/Code/OpenCV/opencv/android/android-jni/obj/local/armeabi/libandroid-opencv.so] Error 1
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2

I thought perhaps this was a pkg-config error, but that appears to be set up as well, though in my old install of OpenCV. Below is the output of pkg-config --cflags --libs opencv:

-I/usr/include/opencv  /usr/lib/libopencv_calib3d.dylib /usr/lib/libopencv_contrib.dylib /usr/lib/libopencv_core.dylib /usr/lib/libopencv_features2d.dylib /usr/lib/libopencv_flann.dylib /usr/lib/libopencv_gpu.dylib /usr/lib/libopencv_highgui.dylib /usr/lib/libopencv_imgproc.dylib /usr/lib/libopencv_legacy.dylib /usr/lib/libopencv_ml.dylib /usr/lib/libopencv_nonfree.dylib /usr/lib/libopencv_objdetect.dylib /usr/lib/libopencv_photo.dylib /usr/lib/libopencv_stitching.dylib /usr/lib/libopencv_ts.dylib /usr/lib/libopencv_video.dylib /usr/lib/libopencv_videostab.dylib

The install built by this particular tutorial has placed an opencv.pc file at this location:

/Users/Me/Code/OpenCV/opencv/build/unix-install

BUT Running the below and trying make again doesn't fix the problem:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Users/Me/Code/OpenCV/opencv/build/unix-install

Any ideas on how I can complete this build?