CROSS COMPILING PYTHON PROGRAMS FOR ANDROID
Specifically, compiling OONI for armv7 AOS.
Active questions should be underlined until answered.
Please pick a colour for your name, and list yourself here:
isis abel
Please keep your colour when answering someone else's questions.
OONI
OONI is described here.
Our main git repository is here: https://gitweb.torproject.org/ooni-probe.git And individual project members currently use github for their personal and development branches, which shouldn't ever be pulled from unless you really know what you're doing or have talked to that developer.
OONI documentation is here.
Our necessary libraries and such are in a pip (in Debian python-pip) requirements.txt file, in the top level of our repo. I believe many of these dependency libraries will need to be cross-compiled as well. Some of these things, so far as I can recall, have already been compiled for Android, specifically, I think Twisted was already done, last I checked, but I do not remember which version.
Setting up your Android toolchain, the Android SDK, & Android NDK (if you don't already have them)
see https://code.google.com/p/python-for-android/wiki/CrossCompilingPython
Useful ~/.bashrc.android
I use this when doing NDK stuff, the python-for-android link defines ANDROID_NDK_TOOLCHAIN_ROOT which seems to be a copy of the toolchain in a new location, this .bashrc.android does not take that into account. In my ~/src/android, android-ndk is a symlink to the current NDK folder (which atm is android-ndk-r8b).
file: $HOME/.bashrc.android
export NDK_BASE=$HOME/src/android/android-ndk
export NDK_ROOT=$NDK_BASE
export SDK_BASE=$HOME/src/android/android-sdk
export SDK_ROOT=$SDK_BASE
export SDK_TOOLS=${SDK_BASE}/tools
export SDK_PLATFORM_TOOLS=${SDK_BASE}/platform-tools
export PATH="${PATH}:${NDK_BASE}:${NDK_TOOLCHAIN_BASE}/bin:${SDK_TOOLS}:${SDK_PLATFORM_TOOLS}"
The relevant bits of mine are:
## ANDROID DEV
#######################
export NDKROOT=$ISIS/code/android/android-ndk-r7 ## Android NDK
## Add export path for Android SDK platform-tools and tools:
export PATH=$PATH:$ISIS/code/android/android-sdk-linux/tools
export PATH=$PATH:$ISIS/code/android/android-sdk-linux/platform-tools
## Export paths for common toolchains for android NDK
## Leave these commented out unless you're specifically cross-compiling for ArmV7:
#export PATH=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/
#export PATH=$PATH:$NDKROOT:$NDKROOT/tools:/usr/local/bin:/usr/bin:/bin"
#export ARCH="armeabi"
#export CFLAGS="-DANDROID -mandroid -fomit-frame-pointer --sysroot $NDKROOT/platforms/android-5/arch-arm"
#export CXXFLAGS = "$CFLAGS"
#export AR="arm-linux-androideabi-ar"
#export LD="arm-linux-androideabi-ld"
#export CC="arm-linux-androideabi-gcc $CFLAGS"
#export CXX="arm-linux-androideabi-g++ $CXXFLAGS"
#export RANLIB="arm-linux-androideabi-ranlib"
#export STRIP="arm-linux-androideabi-strip --strip-unneeded"
#export HPY=/usr/bin/python2.7
#export HPGEN=$ISIS/code/android/python-compiled-for-host
#export MAKE="make -j4 HOSTPYTHON=$HPY HOSTPGEN=$HPGEN CROSS_COMPILE=arm-eabi- CROSS_COMPILE_TARGET=yes"
Patching Python due to Android OS's lack of support for $LOCALE
There is a good article on this here. Specifically, we'll need this patch. OONI's code doesn't use locale anywhere yet, though, of our current dependencies, sphinx, docutils, & twisted.mail and twisted.conch, use locale settings. We don't use twisted.mail or twisted.conch, and sphinx and docutils are merely for generating OONI's documentation, which isn't necessary to do on android.