cjdelisle/cjdns — pull request #476 by lgierth (2014-03-15 00:25:25+00:00)
Title: Cross-compile for Android

This changeset introduces cross-compilation for Android. It uses the TUN device shipping with CyanogenMod and a few branded phones. If your phone doesn't have a TUN device at `/dev/tun`, you can use the [com.aed.tun.installer](https://play.google.com/store/apps/details?id=com.aed.tun.installer) app. One way or the other, your phone needs to be rooted. Although the next step could be the development of an app that controls the Cjdns process, and provides it with a TUN socket via the [VpnService](http://developer.android.com/reference/android/net/VpnService.html) API. Such an app would only require the VPN and network permissions.

There is one remaining problem: Hex and Process tests fail if this is compiled as-is. If I remove stack-protector from CFLAGS in [make.js](https://github.com/cjdelisle/cjdns/blob/master/node_build/make.js#L67-L69), the tests pass. However it does work :)

```
larsg: Pinging fc82:5b57:fb1c:5684:14e7:22f9:9fdb:108a
larsg: rtt min/avg/max/mdev = 69.389/242.966/384.987/130.760 ms
```

The installation is straight forward. Note that `CROSS=1` only prevents the test suite from being executed. You also might want to adjust the file permissions.

```
CC=arm-linux-androideabi-gcc CROSS=1 ./do
adb push cjdroute /data/local/
adb push cjdroute.conf /data/local/
adb shell "/data/local/cjdroute < /data/local/cjdroute.conf"
```

This assumes that you have an `arm-linux-androideabi-` GCC toolchain in `$PATH`. You can build one using the Android NDK's toolchain script. Note that `--platform=android-9` gets us `pthread_rwlock_t`, which is used by libuv.

```
/build/tools/make-standalone-toolchain.sh \
--platform=android-9 \
--toolchain=arm-linux-androideabi-4.8 \
--install-dir=//

export PATH=//bin:$PATH
```

A few more notes:

- ADB needs root permissions: Settings > Developer Options > Root Access > ADB or ADB and Apps
- the NDK used by myself is android-ndk-r9d-linux-x86_64
- tested on a Nexus 4, with freshly flashed CyanogenMod 11 M4