I’m extremely interested in using the Structure Sensor with Android as well. I have to agree with padmanabhavs and Dylan that the instructions for Android are rather sparse. I’ve put together a more detailed set of instructions for folks to use (see below). Please note that these instructions currently only go up to the end of the GitHub steps and not all the way to a working application. Once I’ve progressed further, I’ll post additional steps and example code.
These instructions assume you are on a Linux operating system (preferably Ubuntu) as working with the Android Native Development Kit (NDK) is much easier on Linux than on Windows. I am working off of an Ubuntu 12.04 LTS (64 bit) install, but these instructions should work for most Ubuntu installations. (The Release Notes for Open NI 2 state that you must use “Ubuntu 12.04 (32/64/arm) and above”). I am also assuming that you know how to use the terminal (command prompt for Windows users).
(Note: What is the Native Development Kit? The NDK is designed to let you develop Android apps with C and C++ code in addition to Java. This allows apps to run much faster (nearly everything is precompiled) and allows developers to reuse code created in C/C++ for other programs (like the Open NI 2 libraries). It should be pointed out that the apps do still require some Java coding as the entry/exit points of the app must be done in Java. Also, there is no way to directly access the Android RGB cameras from the C/C++ side of the program. Instead, each frame must be collected in Java then passed to the C/C++ methods. Structure data on the other hand is only accessible on the C/C++ side of the program as Open NI 2 is strictly native code. I would definitely recommend exploring the demos that come with the NDK before doing any development with the Structure Sensor if you’ve never used the NDK before.)
(Optional yet recommended first step) Create an Android development folder that you can put all of your development programs and downloads into. Example: /home/NAMEOFUSER/AndroidDev)
Install the latest Android ADT Bundle from: http://developer.android.com/sdk/index.html . Make sure to get the version that fits your system (x86 vs x86_64). This will provide all of the required SDK items and an Eclipse work environment. Installation consists of downloading a zip file, extracting the contents, and then putting the extracted folder in your dev folder.
Once the ADT Bundle is ready, launch Eclipse (your dev environment) (extracted-adt-bundle-folder/eclipse/eclipse). You should get a popup that asks you to set your workspace folder (generally /home/NAMEOFUSER/workspace). This will contain your Android projects once you start developing (code, dependencies, etc.).
(MANDATORY STEP!!!) Once this is done, you need to open the Android SDK Manager (Eclipse task bar at the top of the program -> Window -> Android SDK Manager). Here you need to download the SDK Platforms for any Android OSes you plan to develop for. The SDK Platform is what allows you to actually create any apps for Android. (I’d also recommend grabbing the Samples for SDK as they will provide sample code showing how to use the various internal sensors, OpenGL, the camera, various GUI items, and plenty more.) While the most recent version of the Android SDK should already be installed, you will need to get the version of the SDK that was supported at the time the Android NDK r8d came out (the only version of the Native Development Kit we can use with Structure). Based on the NDK release notes (https://developer.android.com/tools/sdk/ndk/index.html), I believe this would be API version 14.
Note: You will need to build all of your apps at the API 14 (Android 4.0) level. Any phones running Android 3.2 or earlier cannot run Structure apps!
Download the zip file containing the Occipital branch of OpenNI 2: https://github.com/occipital/OpenNI2 . Extract and put it in your Dev Folder.
Install all of the Linux Building Prerequisites as directed by the OpenNI 2 readme: https://github.com/occipital/OpenNI2/blob/master/README.md . Not sure if not all of these are necessary (GraphViz?), but might as well do it anyways just in case. Plus, you’re now partially prepped for Linux development.
Download the Linux version of the Android NDK r8d: http://dl.google.com/android/ndk/android-ndk-r8d-linux-x86.tar.bz2 . Extract and put it in your Dev Folder.
Define NDK_ROOT to point to the path of your NDK r8d folder. The terminal command is: export NDK_ROOT="/home/NAMEOFUSER/REMAININGPATHTODEVFOLDER/android-ndk-r8d" . That first / before the home is important! It creates a global path. If you don’t include the / , the environment variable becomes a path that starts in whatever folder is currently using the variable (Bad idea…).
Create the Android OpenNI 2 packages. Go to your “DEVFOLDER/OpenNI2-master/Packaging” folder. Then run “python ReleaseVersion.py android” in terminal. This will create “the installer” in the Packaging/Final folder. This appears to be more release notes, a changes document, and a .tar containing some .ini, .so, and executable files. Another folder (Packaging/AndroidBuild) has also been created that contains multiple folders that are generally used in Android NDK development (jni and obj) filled with precompiled files. Once I figure out how to actually use these for development purposes, I’ll post additional information.
7.1) Potential errors that may occur during step 7 if you’re using a 64 bit version of Ubuntu. Keep in mind that the NDK r8d was only provided in a x86 variety.
Problem: /prebuilt/linux-x86/bin/make: not found
Solution: sudo apt-get install libgcc1:i386
Problem: error while loading shared libraries: libz.so.1
Solution: sudo apt-get install lib32z1
Problem: error while loading shared libraries: libstdc++.so.6
Solution: sudo apt-get install lib32stdc++6
In case someone else knows what to do with this information before I figure it out - some information from the compiled release notes:
- On Android, only native support (and samples) is currently provided. Please note that as bionic (Android linker) does not support the rpath option, the samples cannot start as is. To solve this, do one of the following:
- Copy OpenNI libraries (libOpenNI2.so, libPS1080.so and libOniFile.so) to /system/lib (requires root)
- or -
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH before starting the native executeable