Просмотр исходного кода

created docker build environment to generate the android library, updated the readme and gitignore accordingly

Michael Goldberger 10 лет назад
Родитель
Сommit
bc5cf03b1c
4 измененных файлов с 171 добавлено и 23 удалено
  1. 1 0
      .gitignore
  2. 84 0
      AndroidLibrary/Dockerfile
  3. 47 23
      AndroidLibrary/README.md
  4. 39 0
      AndroidLibrary/make.bash

+ 1 - 0
.gitignore

@@ -8,6 +8,7 @@ psiphon.boltdb
 # Exclude compiled tunnel core binaries
 ConsoleClient/ConsoleClient
 ConsoleClient/bin
+AndroidLibrary/psi.aar
 
 # Compiled Object files, Static and Dynamic libs (Shared Objects)
 *.o

+ 84 - 0
AndroidLibrary/Dockerfile

@@ -0,0 +1,84 @@
+# Dockerfile to build an image with the local version of psiphon-tunnel-core.
+#
+# See README.md for usage instructions.
+
+FROM ubuntu:latest
+
+# Install system-level dependencies.
+ENV DEBIAN_FRONTEND=noninteractive
+RUN apt-get update -y && apt-get install -y --no-install-recommends \
+    build-essential \
+    ca-certificates \
+    curl \
+    git \
+    openjdk-7-jdk \
+    pkg-config \
+  && apt-get clean \
+  && rm -rf /var/lib/apt/lists/*
+
+# Install Go and Go Mobile.
+ENV GOVERSION=go1.5.3 GOROOT=/usr/local/go GOPATH=/go PATH=$PATH:/usr/local/go/bin:/go/bin CGO_ENABLED=1
+
+RUN curl -L https://storage.googleapis.com/golang/$GOVERSION.linux-amd64.tar.gz -o /tmp/go.tar.gz \
+  && tar -C /usr/local -xzf /tmp/go.tar.gz \
+  && rm /tmp/go.tar.gz \
+  && echo $GOVERSION > $GOROOT/VERSION \
+  && go get -v golang.org/x/mobile/cmd/gomobile \
+  && gomobile init -v
+
+# Setup Android Environment.
+ENV ANDROID_NDK_ROOT=/android-ndk ANDROID_HOME=/android-sdk-linux
+
+# Setup Android NDK
+RUN cd /tmp \
+  && curl -L http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin -o /tmp/android-ndk.bin \
+  && chmod a+x /tmp/android-ndk.bin \
+  && /tmp/android-ndk.bin \
+  && rm /tmp/android-ndk.bin \
+  && ln -s $(find /tmp -type d -name 'android-ndk-*') /android-ndk
+
+# Setup Android SDK.
+RUN curl -L http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz -o /tmp/android-sdk.tgz \
+  && tar -C / -xzf /tmp/android-sdk.tgz \
+  && rm /tmp/android-sdk.tgz \
+  && (while true; do echo 'y'; sleep 2; done) | $ANDROID_HOME/tools/android update sdk --no-ui
+
+# Setup OpenSSL libray.
+ENV OPENSSL_VERSION=1.0.1p
+ENV PKG_CONFIG_PATH=/tmp/openssl/openssl-$OPENSSL_VERSION
+ENV CGO_CFLAGS="-I $PKG_CONFIG_PATH/include" CGO_LDFLAGS="-L $PKG_CONFIG_PATH -lssl -lcrypto"
+
+RUN mkdir -p /tmp/openssl \
+  && curl -L https://github.com/Psiphon-Labs/psiphon-tunnel-core/raw/master/openssl/openssl-$OPENSSL_VERSION.tar.gz -o /tmp/openssl.tar.gz \
+  && tar -C /tmp/openssl -xzf /tmp/openssl.tar.gz \
+  && rm /tmp/openssl.tar.gz \
+  && curl -L https://github.com/Psiphon-Labs/psiphon-tunnel-core/raw/master/openssl/setenv-android.sh -o /tmp/setenv-android.sh \
+  && /bin/bash -c "\
+    source /tmp/setenv-android.sh \
+    && cd /tmp/openssl/openssl-$OPENSSL_VERSION \
+    && perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org \
+    && ./config \
+      no-shared \
+      no-ssl2 \
+      no-ssl3 \
+      no-comp \
+      no-hw \
+      no-md2 \
+      no-md4 \
+      no-rc2 \
+      no-rc5 \
+      no-krb5 \
+      no-ripemd160 \
+      no-idea \
+      no-gost \
+      no-camellia \
+      no-seed \
+      no-3des \
+      no-heartbeats \
+      --openssldir=./ssl \
+    && perl -pi -e 's/-O3/-Os -mfloat-abi=softfp/g' Makefile \
+    && make depend \
+    && make all"
+
+
+WORKDIR $GOPATH/src

+ 47 - 23
AndroidLibrary/README.md

@@ -1,36 +1,60 @@
-Psiphon Library for Android README
-================================================================================
+##Psiphon Android Library README
 
-Overview
---------------------------------------------------------------------------------
+###Overview
 
 Psiphon Library for Android enables you to easily embed Psiphon in your Android
 app. The Psiphon Library for Android is implemented in Go and follows the standard
 conventions for using a Go library in an Android app.
 
-Status
---------------------------------------------------------------------------------
+###Building with Docker
 
-* Pre-release
+Note that you may need to use `sudo docker` below, depending on your OS.
 
-Building From Source
---------------------------------------------------------------------------------
+#####Create the build image:
 
-Follow Go Android documentation:
-* [gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
-* Requires Go 1.5 or later.
-* Build command: `gomobile bind -target=android github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi`
-  * Record build version info, as described [here](https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/master/README.md#setup), by passing a `-ldflags` argument to `gomobile bind`.
-* Output: `psi.aar`
+  1. Run the command: `docker build --no-cache=true -t psiandroid .` (this may take some time to complete)
+  2. Once completed, verify that you see an image named `psiandroid` when running: `docker images`
 
-Using
---------------------------------------------------------------------------------
+#####Run the build:
 
-1. Build `psi.aar` from source or use the [binary release](https://github.com/Psiphon-Labs/psiphon-tunnel-core/releases)
-1. Add `psi.aar` to your Android Studio project as described in the [gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
-1. Example usage in [TunneledWebView sample app](../SampleApps/TunneledWebView/README.md)
+  *Ensure that the command below is run from within the `AndroidLibrary` directory*
 
-Limitations
---------------------------------------------------------------------------------
+  ```bash
+  cd .. && \
+    docker run \
+    --rm \
+    -v $(pwd):/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core \
+    psiandroid \
+    /bin/bash -c 'source /tmp/setenv-android.sh && cd /go/src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary && ./make.bash' \
+  ; cd -
+  ```
+When that command completes, the compiled `.aar` file (suitable for use in an Android Studio project) will be located in the current directory (it will likely be owned by root, so be sure to `chown` to an appropriate user).
 
-* Only supports one concurrent instance of Psiphon.
+###Building without Docker (from source)
+
+#####Prerequisites:
+
+ - The `build-essential` package (on Debian based systems - or its equivalent for your platform)
+ - Go 1.5 or later
+ - Full JDK
+ - Android NDK
+ - Android SDK
+ - OpenSSL (tested against the version [here](../openssl))
+  - Follow its [README](../openssl/README.md) to prepare the environment before you follow the steps below
+
+#####Steps:
+
+ 1. Follow Go Android documentation ([gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile))
+ - Build command: `gomobile bind -target=android github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi`
+  - Record build version info, as described [here](../README.md#setup), by passing a `-ldflags` argument to `gomobile bind`.
+  - Output: `psi.aar`
+
+###Using the Library
+
+ 1. Build `psi.aar` from via the docker container, from source, or use the [binary release](https://github.com/Psiphon-Labs/psiphon-tunnel-core/releases)
+ 2. Add `psi.aar` to your Android Studio project as described in the [gomobile documentation](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
+ 3. Example usage in [TunneledWebView sample app](../SampleApps/TunneledWebView/README.md)
+
+#####Limitations
+
+ - Only supports one concurrent instance of Psiphon.

+ 39 - 0
AndroidLibrary/make.bash

@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+set -e
+
+if [ ! -f make.bash ]; then
+  echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary"
+  exit 1
+fi
+
+GOOS=arm go get -d -v github.com/Psiphon-Inc/openssl
+GOOS=arm go get -d -v ./...
+if [ $? != 0 ]; then
+  echo "..'go get' failed, exiting"
+  exit $?
+fi
+
+BUILDDATE=$(date --iso-8601=seconds)
+BUILDREPO=$(git config --get remote.origin.url)
+BUILDREV=$(git rev-parse --short HEAD)
+
+LDFLAGS="\
+-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate=$BUILDDATE \
+-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo=$BUILDREPO \
+-X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev=$BUILDREV \
+"
+
+echo "Variables for ldflags:"
+echo " Build date: ${BUILDDATE}"
+echo " Build repo: ${BUILDREPO}"
+echo " Build revision: ${BUILDREV}"
+echo ""
+
+gomobile bind -v -ldflags="$LDFLAGS" github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi
+if [ $? != 0 ]; then
+  echo "..'gomobile bind' failed, exiting"
+  exit $?
+fi
+
+echo "Done"