Differences between revisions 25 and 26
Revision 25 as of 2011-11-23 14:30:11
Size: 13204
Editor: 62
Comment: add ContributorGroup link
Revision 26 as of 2018-12-17 19:03:36
Size: 0
Editor: JoanTouzet
Comment: Migrated to https://github.com/couchbase/Android-Couchbase-SourceBuild
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:


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 ==

 * Please note that the following instructions for Android produce a build that mostly works but is not entirely bug free. Any help tracking down and resolving problems with this procedure and the resulting build would be greatly appreciated.

 * This build passes all of the Futon Test Suite with the exception of the "stats" test which fails with {{{Assertion failed: We managed to force a all_dbs_active error.}}} Please help me to figure out why this is happening. A log of the failed test is available at http://friendpaste.com/5qtv7sGK4qpMmuC8HVc9U6_393637376332/raw.

 * As alluded to below, I was unable to get Couch to agree to link with the static Spidermonkey library. This is due to the fact that C++ support in more recent official releases of the Google SDK/NDK is lacking. It would be preferable to link statically because it would remove the need for a separate file ({{{libmozjs.so}}}) and thus one less thing to go wrong (there are several workarounds below & in related patches for the fact that we need to worry about dynamic linking with regards to the default couch query server, {{{couchjs}}}).

 * Pay close attention to the instructions:
   * You will need to replace {{{com.your.namespace}}} with something appropriate for your project throughout the instructions below and in the related patches.
   * Due to Android's preferences for where files "should be placed" you will need to update several paths below related to {{{com.your.namespace}}}.
   * Also, '''if you are not producing an official build of Couch, be sure use a port other than''' {{{5984}}} '''to avoid clobbering the official builds'''.

 * Once installed you will probably want to interact with Futon on Android from your workstation. Run {{{$ adb forward tcp:5985 tcp:5984}}} and point your web browser to {{{http://localhost:5985}}} to access Couch. Note that some of the test suite expects to be run from {{{:5984}}} and will fail when accessed through this configuration (although we only noticed this when building Couch 1.0.1 -- the problem appears to have disappeared in Couch 1.0.2). To run the complete set of tests you will need to stop your local Couch instance (if any) and set the forward up on {{{:5984}}} on both ends. You will also need to stop {{{www}}} from being removed from the build (we got rid of Futon to save space -- at this point it is only useful to developers anyway).

== Credits ==

A lot of the credit should go to [[https://github.com/apage43|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 to [[http://source.android.com/source/download.html|build Android from source]]. You will also [[http://developer.android.com/sdk/index.html|need an SDK]] (I used r08).

See [[https://github.com/couchone/couch-android-launcher|couch-android-launcher]] and [[https://github.com/couchone/libcouch-android|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 PATH=$JAVA_HOME/bin:$PATH

make -s

=== Step 2: Build cURL ===


[[ -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

CPPFLAGS="-I$ANDROID_SDK/sources/external/openssl/include -I$ANDROID_SDK/sources/external/zlib" \
CC=agcc \
./configure \
--disable-shared \
--without-random \
--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 \

make -s

=== Step 3: Build Mozilla NSPR & Spidermonkey ===

The following instructions are based on the Fennec instructions [[https://wiki.mozilla.org/Mobile/Fennec/Android#JS.2FNSPR_only|for building JS/NSPR only]]. We used [[http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2|their Android NDK package]] for the builds.

==== Retrieve mozilla-current ====


[[ -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

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 \

make -s

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

==== Spidermonkey ====

Be aware that Spidermonkey '''[[https://bugzilla.mozilla.org/show_bug.cgi?id=617115|will not]]''' build against Android NDK r5 (we haven't checked this issue recently, it may have changed).


cd mozilla-central/js/src

./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

./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


source $HOME/software/android/scripts/env

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 \

make -s
make install

=== Step 6: Package for use on Android ===

#!/bin/bash -x

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

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

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
    mv $i backuplib/

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 \

# 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
# 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 ..