The official documentation has moved to http://docs.couchdb.org — The transition is not 100% complete, but http://docs.couchdb.org should be seen as having the latest info. In some cases, the wiki still has some more or older info on certain topics inside CouchDB.

You need to be added to the ContributorsGroup to edit the wiki. But don't worry! Just email any Mailing List or grab us on IRC and let us know your user name.

THESE INSTRUCTIONS ARE OUTDATED

Please see https://github.com/couchbase/Android-Couchbase-SourceBuild for up-to-date instructions

Installing CouchDB on Android (from source)

Update February 27th, 2011

Below are updated instructions that produce a build that is better organized for Android, somewhat more lightweight in the final product and slightly more straightforward to understand (and with support for replications over a SSH reverse proxy!). This build requires updates to the Android installer that have not yet been pushed upstream so please don't expect this to work out-of-the-box. -- MattAdams

Caveats

Credits

A lot of the credit should go to Aaron Miller for doing the original port upon which these instructions are based. I would also like to thank Wes and Chris C. Coulson from #jsapi and Dale Harvey, davisp and rnewson from #couchdb. Thanks to everyone else who helped, too.

Overview & Instructions

The following build instructions are intended for Android 2.2.2 and were run on Debian Squeeze. The "scripts" below were run with Bash from a single directory that I called android-build.

I used Java 1.5.0.22 to build Android from source. You will also need an SDK (I used r08).

See couch-android-launcher and libcouch-android for the end-user Android application that will use the package produced by this build.

Supporting these builds are a number of helper scripts and patches: AndroidEnv, AndroidAgcc, AndroidCouchPatch, AndroidMozillaPatch, AndroidOtpPatch, AndroidReleasePatch

Step 1: Build Android from Source

cd ~/software/android/sdk/sources

repo init -b froyo
repo sync

source build/envsetup.sh

export JAVA_HOME=$HOME/software/jdk1.5.0_22
export ANDROID_JAVA_HOME=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH

lunch
make -s

Step 2: Build cURL

VERSION=7.20.0

[[ -f curl-$VERSION.tar.bz2 ]] || wget http://curl.haxx.se/download/curl-$VERSION.tar.bz2

rm -rf curl-$VERSION
tar jxf curl-$VERSION.tar.bz2
cd curl-$VERSION

# See AndroidEnv in Installing_on_Android wiki topic
source $HOME/software/android/scripts/env
ANDROID_SDK=$HOME/software/android/sdk

CPPFLAGS="-I$ANDROID_SDK/sources/external/openssl/include -I$ANDROID_SDK/sources/external/zlib" \
CC=agcc \
./configure \
--disable-shared \
--without-random \
--host=arm-linux
--disable-tftp \
--disable-sspi \
--disable-ipv6 \
--disable-ldaps \
--disable-ldap \
--disable-telnet \
--disable-pop3 \
--disable-ftp \
--with-ssl=$ANDROID_SDK/sources/external/openssl \
--disable-imap \
--disable-smtp \
--disable-pop3 \
--disable-rtsp \
--disable-ares \
--without-ca-bundle \
--disable-warnings \
--disable-manual \
--without-nss \
--with-zlib=$ANDROID_SDK/sources/external/zlib

make -s

Step 3: Build Mozilla NSPR & Spidermonkey

The following instructions are based on the Fennec instructions for building JS/NSPR only. We used their Android NDK package for the builds.

Retrieve mozilla-current

HGREV=bb9089ae2322

[[ -f mozilla-central-$HGREV.tar.bz2 ]] || wget http://hg.mozilla.org/mozilla-central/archive/$HGREV.tar.bz2
    
rm -rf mozilla-central mozilla-central-$HGREV
tar -jxf mozilla-central-$HGREV.tar.bz2
ln -s mozilla-central-$HGREV mozilla-central

cd mozilla-central

# Use of __android_log_print and __android_log_write requires liblog.so from our
# toolchain.  However, llog also has a dependency on libstdc++.so which our toolchain
# DOES NOT have so we need to substitute for something less Androidy (apologies).
patch -p1 < ../mozilla-central.patch

NSPR

NSPR isn't technically required but it is heavily integrated into current versions of Spidermonkey and future versions will almost certainly require it.

Also, NSPR will compile against current NDKs but I choose to use the recommended one (ndk-r4c-0moz3) for the sake of consistency. The next step (Spidermonkey) requires the specified NDK version.

source $HOME/software/android/scripts/env
ANDROID_NDK=$HOME/software/android/android-ndk-r4c

cd mozilla-central/nsprpub

./configure \
--target=arm-android-eabi \
--with-android-ndk=$ANDROID_NDK \
--with-android-platform=$ANDROID_NDK/build/platforms/android-8/arch-arm \
--enable-strip

make -s

# Remove shared libraries so that Couch is built with the static ones
rm dist/lib/*so

Spidermonkey

Be aware that Spidermonkey will not build against Android NDK r5 (we haven't checked this issue recently, it may have changed).

ANDROID_NDK=$HOME/software/android/android-ndk-r4c

cd mozilla-central/js/src
autoconf2.13

./configure \
--target=arm-android-eabi \
--with-android-ndk=$ANDROID_NDK \
--with-android-sdk=$ANDROID_NDK/build/platforms/android-8 \
--with-android-version=8 \
--disable-tests \
--disable-shared \
--enable-static \
--enable-strip \
--enable-endian=little \
--with-arm-kuser \
--enable-threadsafe \
--with-nspr-cflags=-I$(pwd)/../../nsprpub/dist/include/nspr \
--with-nspr-libs="-L$(pwd)/../../nsprpub/dist/lib -lnspr4 -lplc4 -lplds4" 

make -s

##
# Remove the shared lib to force Couch to link statically
# (this isn't working due to Android toolchain difficulties)
#
#rm libmozjs.so
#mv libjs_static.a libmozjs.a

You should add --enable-debug and --disable-optimizations for development builds or when running the Futon test suite for the first time (assertions matter).

Step 4: Build Erlang/OTP

An updated port of Erlang that will work on Android would be greatly appreciated! I know there has been some work on this by the Erlang folks but I am not aware of the location of the build instructions, source code or patches.

rm -rf otp
rm -rf otp_rel
git clone git://github.com/apage43/otp.git
cd otp
git checkout origin/android

## 
# 1) Add back in support for the "beam" binary
# 2) Our default autoconf is 2.67 and we need to switch back to 2.59
#    for this operation
# 3) Environment differences between Android and UNIX (bin/sh)
#
patch -p1 < ../otp.patch

source $HOME/software/android/scripts/env
export ANDROID_SDK=$HOME/software/android/sdk
export ANDROID_SYS_ROOT=$ANDROID_SDK/sources

./otp_build autoconf
./otp_build configure --xcomp-conf=xcomp/erl-xcomp-android.conf
./otp_build boot -a
./otp_build release -a $(pwd)/../otp_rel

Step 5: Compile Couch

rm -rf couchdb
rm -rf /sdcard/*
git clone git://github.com/apache/couchdb.git
cd couchdb
git checkout 1.0.2

##
# 1) Android Build Support from https://github.com/apage43/couchdb/tree/0.11.x-android
# 2) Mozilla JS compatibility by chrisccoulson from jsapi@irc.mozilla.org
# 3) Fixes for Android by matt.adams-couch@radicaldynamic.com
#
patch -p1 < ../couchdb.patch

./bootstrap

source $HOME/software/android/scripts/env
ANDROID_SDK=$HOME/software/android/sdk

ERL=$(pwd)/../otp/bootstrap/bin/erl \
ERLC=$(pwd)/../otp/bootstrap/bin/erlc \
CC=agcc \
./configure \
--host=arm-eabi \
--prefix=/sdcard/Android/data/com.your.namespace/couchdb \
--with-android=$ANDROID_SDK/sources \
--with-android-curl=$(pwd)/../curl-7.20.0 \
--with-erlang=$(pwd)/../otp_rel/usr/include \
--with-js-include=$(pwd)/../mozilla-central/js/src/dist/include \
--with-js-lib="$(pwd)/../mozilla-central/js/src"

make -s
make install

Step 6: Package for use on Android

if [ -z "$1" ]; then
    echo "Give me a release number bub!"
    exit 1
fi

DATE=$(date +"%Y-%m-%d_%H-%M-%S")
RELEASE="release-$DATE"

mkdir -p $RELEASE/data/data/com.your.namespace

##
# Configure and package Erlang/OTP
#

cp -Rdp otp_rel otp_rel.package

cd otp_rel.package

./Install -cross -sasl /data/data/com.your.namespace/erlang
rm Install

# Necessary?
chmod -x erts-5.7.5/bin/start_erl.src erts-5.7.5/bin/start.src

# Remove unnecessary files
rm -rf erts-5.7.5/doc erts-5.7.5/include erts-5.7.5/man erts-5.7.5/src misc releases usr

# Pare lib directory
libs_to_keep="crypto-1.6.4 erts-5.7.5 inets-5.3 kernel-2.13.5 public_key-0.5 sasl-2.1.9 ssl-3.10.8 stdlib-1.16.5 xmerl-1.2.4"

cd lib
mkdir backuplib

for i in $libs_to_keep
do
    mv $i backuplib/
done

mv backuplib ../
rm -rf *

mv ../backuplib/* .
rmdir ../backuplib

# Remove vestigal files
find . -depth -name src -type d -exec rm -rf {} \;
find . -depth -name examples -type d -exec rm -rf {} \;
find . -depth -name include -type d -exec rm -rf {} \;

cd ../..

##
# Finally move things into place
#

cp -Rdp /sdcard $RELEASE/sdcard
mv otp_rel.package $RELEASE/sdcard/Android/data/com.your.namespace/erlang

# We need the shared lib because our toolchain does not support the static lib (libstdc++ stuff)
cp mozilla-central/js/src/libmozjs.so $RELEASE/sdcard/Android/data/com.your.namespace/couchdb/lib/couchdb/bin

###
# 1) DNS fixes from apage43's couchdb-android.s3.amazonaws.com/dns-fix.tgz
# 2) Create couchjs_wrapper script (because we can't link to libmozjs.a and so need LD_LIBRARY_PATH set)
# 3) Update #!/bin/sh in data/data/com.your.namespace/erlang/lib/couch-1.0.1/priv/couchspawnkillable
# 4) Reflect new locations and the Android environment
#
rm release
ln -s $RELEASE release
patch -p0 < release.patch

chmod +x $RELEASE/sdcard/Android/data/com.your.namespace/couchdb/bin/couchjs_wrapper

# Build ICU for whatever version of Android was compiled in ~/software/android/sdk/sources
source $HOME/software/android/scripts/env

agcc \
-shared \
-o $RELEASE/sdcard/Android/data/com.your.namespace/couchdb/lib/couchdb/couch_icu_driver.so couchdb/src/couchdb/priv/.libs/libcouch_icu_driver.a \
-licuuc \
-licudata \
-licui18n \
-L$HOME/projects/couch/android-build/otp_rel/erts-5.7.5/bin \
-lbeam

##
# Remove vestigal files from Couch directory
# (Futon is in www)
#
cd $RELEASE/sdcard/Android/data/com.your.namespace/couchdb
rm -rf share/couchdb/www share/doc share/man
cd ../../../../../..

##
# Archive the release
#
cd $RELEASE
# filecount. is used so we can present a progress-based indicator during install
touch filecount.$(find | wc -l)
tar -czf ../release-$1.tgz filecount.* data sdcard
cd ..

Installing_on_Android (last edited 2011-11-23 14:30:11 by 62)