Merge pull request #93 from dec1/master

android build scripts
diff --git a/android/do.sh b/android/do.sh
new file mode 100755
index 0000000..c4641c9
--- /dev/null
+++ b/android/do.sh
@@ -0,0 +1,63 @@
+
+# Author: Declan Moran
+# www.silverglint.com 
+# Thanks to damaex (https://github.com/damaex), for significant contributions
+
+ANDROID_NDK_ROOT=/home/android/android-ndk-r19c
+
+INSTALL_DIR=install
+BUILD_DIR=build
+START_DIR=$(pwd)
+
+rm -rf $INSTALL_DIR
+rm -rf $BUILD_DIR
+mkdir -p $BUILD_DIR #"${ANDROID_TARGET_PLATFORM}"
+
+#--------------------------------------------------------------------
+build_it()
+{
+    # builds either a static or shared lib depending on parm passed (ON or OFF)
+    want_shared=$1
+
+	cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
+		-DCMAKE_INSTALL_PREFIX:PATH=../../${INSTALL_DIR}/${ANDROID_TARGET_PLATFORM} \
+		-DANDROID_ABI=${ANDROID_TARGET_PLATFORM} \
+		-DENABLE_OPENSSL:BOOL=OFF \
+		-DENABLE_COMMONCRYPTO:BOOL=OFF \
+		-DENABLE_GNUTLS:BOOL=OFF \
+		-DENABLE_MBEDTLS:BOOL=OFF \
+		-DENABLE_OPENSSL:BOOL=OFF \
+		-DENABLE_WINDOWS_CRYPTO:BOOL=OFF \
+		-DBUILD_TOOLS:BOOL=OFF \
+		-DBUILD_REGRESS:BOOL=OFF \
+		-DBUILD_EXAMPLES:BOOL=OFF \
+		-DBUILD_SHARED_LIBS:BOOL=$want_shared \
+		-DBUILD_DOC:BOOL=OFF \
+		-DANDROID_TOOLCHAIN=clang  cmake -H.. -B$BUILD_DIR/${ANDROID_TARGET_PLATFORM}
+		   	
+        #run make with all system threads and install
+        cd $BUILD_DIR/${ANDROID_TARGET_PLATFORM}
+        make install -j$(nproc --all)
+        cd $START_DIR
+    }
+
+#--------------------------------------------------------------------
+for ANDROID_TARGET_PLATFORM in armeabi-v7a arm64-v8a x86 x86_64
+do
+	echo "Building libzip for ${ANDROID_TARGET_PLATFORM}" 
+	
+	build_it ON
+	build_it OFF
+	
+	if [ $? -ne 0 ]; then
+		echo "Error executing: cmake"
+		exit 1
+	fi
+
+	
+	if [ $? -ne 0 ]; then
+		echo "Error executing make install for platform: ${ANDROID_TARGET_PLATFORM}"
+		exit 1
+    fi
+    
+done    
diff --git a/android/docker/Dockerfile b/android/docker/Dockerfile
new file mode 100644
index 0000000..2e726e4
--- /dev/null
+++ b/android/docker/Dockerfile
@@ -0,0 +1,122 @@
+# Version: 1.0
+
+# Dockerfile for building libzip for android
+# https://github.com/dec1/libzip.git
+# creates docker container with all tools, libraries and sources required to build libzip for android.
+
+# Author: Declan Moran
+# www.silverglint.com
+
+
+# Usage: 
+#---------
+# download the libzip repository
+# > git clone https://github.com/dec1/libzip.git
+# > cd libzip
+#
+# build docker image "my_img_zip" from the dockerfile in "docker" dir
+# > docker build -t my_img_zip ./android/docker
+#
+# run docker container "my_ctr_zip" from this image, mounting the current dir. (Need to pass absolute host paths to mount volume- hence "pwd")
+# > docker run  -v $(pwd):/home/docker-share/libzip -it --entrypoint=/bin/bash --name my_ctr_zip my_img_zip
+#
+# Now inside docker container
+# $ cd /home/docker-share/libzip/android
+#
+# Modify ./do.sh (on host), to match the boost and android ndk versions/paths in the "Configure here" section below
+# Build from running docker container. 
+# $./do.sh
+#
+# "./build" dir contains required build, but owned by root. chown to your username/group
+# > sudo chown -R <userid>:<groupid> ./build
+# > sudo chown -R <userid>:<groupid> ./install
+#
+# Exit container, when build is finsihed.
+# $ exit
+# 
+
+
+
+
+FROM ubuntu:18.04
+ 
+ 
+## --------------------------------------------------------------------
+##              Configure here
+# ---------------------------------------------------------------------
+# ---------------------------------------------------------------------
+# Here you can speciofy exactly what android ndk (and sdk) version you want to use.
+
+
+
+# (2) Android SDK
+# https://developer.android.com/studio#downloads
+ARG SDK_URL_BASE=https://dl.google.com/android/repository
+ARG SDK_FILE=sdk-tools-linux-4333796.zip
+
+# the sdk plaform to use 
+# https://developer.android.com/guide/topics/manifest/uses-sdk-element
+ARG ANDROID_SDK_PLATFORM_VERS="platforms;android-28"
+
+
+
+# (3) Android NDK
+# https://developer.android.com/ndk/downloads
+ARG NDK_URL_BASE=https://dl.google.com/android/repository
+ARG NDK_FILE=android-ndk-r19c-linux-x86_64.zip
+# ---------------------------------------------------------------------
+## --------------------------------------------------------------------
+
+RUN apt-get update
+RUN apt-get -y dist-upgrade
+
+
+# for downloading archives
+RUN apt-get -y install wget
+
+# for unzipping downloaded android archives
+RUN apt-get -y install zip 
+RUN apt-get -y install cmake
+
+RUN apt-get -y install lib32z1
+
+
+# need this this to install some (32 bit) prerequisites for android builds 
+RUN dpkg --add-architecture i386
+RUN apt-get update
+RUN apt-get -y dist-upgrade
+RUN apt-get install -y  libc6:i386 libncurses5:i386 libstdc++6:i386 libbz2-1.0:i386
+
+
+# need c compiler to set up create boost build system (before building boost with it and android toolchain)
+RUN apt-get -y install build-essential 
+RUN apt-get -y install libc6-dev-i386
+RUN apt-get -y install clang
+
+RUN apt-get -y install openjdk-8-jdk
+#--------------------------------------
+
+ARG ANDROID_HOME=/home/android
+WORKDIR ${ANDROID_HOME}
+
+
+# SDK
+# ----
+# download android sdk command line tools
+RUN wget ${SDK_URL_BASE}/$SDK_FILE
+RUN unzip $SDK_FILE 
+
+ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
+
+
+RUN yes | sdkmanager --licenses
+
+RUN sdkmanager "platform-tools" $ANDROID_SDK_PLATFORM_VERS
+#RUN sdkmanager "platform-tools" "platforms;android-28" 
+
+
+# NDK
+# ----
+RUN wget ${NDK_URL_BASE}/$NDK_FILE
+RUN unzip $NDK_FILE 
+
diff --git a/android/readme.txt b/android/readme.txt
new file mode 100644
index 0000000..aa69fbd
--- /dev/null
+++ b/android/readme.txt
@@ -0,0 +1,10 @@
+
+Cross compile libzip for android.
+--------------------------------
+Modify "do.sh" as appropriate if you need to specify a different ndk dir or wish to specify different build parameters
+
+Prerequisites for the development machine - see docker/Dockerfile
+
+You can either set you host machine up with these prerequisites or simply use docker (in which case you need not install anything on your host machine except docker itself).
+
+See "Usage" in docker/Dockerfile for detailed instructions.