Since I am familiar with Ubuntu Linux, I followed the tutorial using Ubuntu 14.04 64 desktop to build and test Torch7 for Android.
Refer the readme file for Torch7 for Android and the official Torch7 getting started.
The Torch7 project is easy to build following the official guide but the torch-android project is poorly maintained and not well documented, so I wrote this document as a note.
- Ubuntu 12.04 64(Ubuntu 14.04 64)
- Android NDK(r9c or r10d, I am using r10d and successfully get the android demo in the end)
- Android SDK(install at least one sdk platform, I am uisng api 19)
- Prebuilt torch7
- Add NDK and SDK to path
Follow the getting stared documentation of Torch.
curl -sk https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh
On Linux
source ~/.bashrc
On OSX
source ~/.profile
luarocks list
th
- Using the development system as we install the Torch7
- Torch7 is successfully installed following the prior document
- Install ipython using
sudo apt-get install ipython
if it is not installed
- clone the torch-android repo:
git clone https://github.com/soumith/torch-android ~/Projects/torch-android
- Add SDK, NDK path in Ubuntu: i.e,
export PATH=/opt/android-sdk-linux/tools/:/opt/android-sdk-linux/platform-tools/
,export PATH=~/bin:/opt/android-sdk-linux_x86/tools/:/opt/android-ndk-rxy
, refer to setting up the android development environment - export ANDROID_NDK to your ndk root, i.e,
export ANDROID_NDK=~/ndk
- goto torch-android repo root and run
sh build.sh
- move static libraries to
torch-android/lib
, runfind . -name "*.a" | xargs cp -t lib
- copy the
libgomp.a
totorch-android/lib
, i.e,cp ~/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/libgomp.a lib/
. You need to goto the ndk installation and find thelibgomp.a
then copy it totorch-android/lib
. See the issue 4 - Now we have built the torch-android environment and we can proceed to build the demo
- Make sure you have gone through the prior setting ups correctly
- Goto the android-demo directory of the
torch-android
repo - Update the project settings using
android update project -p . -t 1
, you can get a list of targets usingandroid list target
and select one of the target as the parameter for the-t
of the previous command - Make sure you have android sdk and android ndk in path
- run
sh build.sh
in the demo directory to make the android demo and run on your connected device