How to build OpenCV for android on Snow Leopard
posted on: 2011-02-21 21:30:37
I thought I would post up a tutorial of something that I have had to do recently and thats build OpenCV for android on Mac OS Snow Leopard.
First things first, if you haven't already realised the wanders of macports you will need to download and install it from here.
http://www.macports.org/Next thing to do is to install OpenCV.
sudo port selfupdate sudo port install opencv
Apparently if you encounter any errors whilst installing on a 64bit processor you may need to run add +universal. Although I am using 64bit with Snow Leopard I did not have to do this.
The next step is to install the crystalx version of the ndk. Not the one from android.com.
http://www.crystax.net/data/android-ndk-r4-darwin-x86-crystax-4.tar.bz2
Most of the documentation I have read has instructed to extract the ndk to home directory. So thats what I did. You can also rename the directory if you choose to, although I didn't.
Then whilst you have the terminal open in your home directory. You can checkout OpenCV using svn.
svn checkout https://code.ros.org/svn/opencv/trunk/opencv opencv
The next thing to do is to build the static opencv libraries for android. Warning: this may take an age.
cd opencv/android mkdir build cd build cmake .. make
The next stop is the android-jni directory.
cd ../android/android-jni cp sample.local.env.mk local.env.mk
Note: if you have renamed the ndk folder or stored it in another location you will need to edit the contents of this file to match.
Mine reads: ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
sh ./project_create.sh ant compile
You can then trying to build the CVCamera program
cd opencv/android/apps/CVCamera sh build.sh make sh project_create.sh ant debug
If you run into any problems at this stage (as I did). I got an error saying "Reference android.libraries.src not found". To remedy this you will need to add the following 2 lines to the sdk\tools\ant\lib_rules.xml file after the closing setup tag. Note: that this is your standard sdk and not the ndk.
<path id="android.libraries.src"><path refid="project.libraries.src" /></path>
<path id="android.libraries.jars"><path refid="project.libraries.jars" /></path>
If the build goes well the next thing to do is the plug in your favourite android device into your mac. And install it onto your device by running.
ant install
I hope that your install went as straight forward as mine.
