瀏覽代碼

Merge pull request #42 from adam-p/master

Create Docker image for building Android Go library
Rod Hynes 11 年之前
父節點
當前提交
763b74474a

+ 14 - 0
.gitignore

@@ -27,3 +27,17 @@ _testmain.go
 *.exe
 *.exe
 *.test
 *.test
 *.prof
 *.prof
+
+# Mac OS X clutter
+*.DS_Store
+
+# Windows clutter
+Thumbs.db
+
+# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
+.idea/workspace.xml
+.idea/tasks.xml
+
+# Ignore gradle files
+.gradle/
+build/

+ 1 - 3
AndroidApp/.idea/misc.xml

@@ -3,8 +3,6 @@
   <component name="EntryPointsManager">
   <component name="EntryPointsManager">
     <entry_points version="2.0" />
     <entry_points version="2.0" />
   </component>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
-    <output url="file://$PROJECT_DIR$/build/classes" />
-  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK" />
 </project>
 </project>
 
 

+ 1 - 1
AndroidApp/AndroidApp.iml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
   <component name="FacetManager">
     <facet type="java-gradle" name="Java-Gradle">
     <facet type="java-gradle" name="Java-Gradle">
       <configuration>
       <configuration>

+ 1 - 1
AndroidApp/app/app.iml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidApp" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
   <component name="FacetManager">
     <facet type="android-gradle" name="Android-Gradle">
     <facet type="android-gradle" name="Android-Gradle">
       <configuration>
       <configuration>

+ 1 - 1
AndroidApp/app/build.gradle

@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
 
 
 android {
 android {
     compileSdkVersion 21
     compileSdkVersion 21
-    buildToolsVersion "20.0.0"
+    buildToolsVersion "21.1.2"
 
 
     defaultConfig {
     defaultConfig {
         applicationId "ca.psiphon.psibot"
         applicationId "ca.psiphon.psibot"

+ 16 - 0
AndroidApp/make.bash

@@ -0,0 +1,16 @@
+#!/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/AndroidApp'
+  exit 1
+fi
+
+ANDROID_APP=$PWD
+
+# Build library
+(cd ../AndroidLibrary && ./make.bash)
+mkdir -p app/src/main/jniLibs/armeabi-v7a && cp -f ../AndroidLibrary/libs/armeabi-v7a/libgojni.so app/src/main/jniLibs/armeabi-v7a
+
+gradle clean build

+ 66 - 0
AndroidLibrary/Dockerfile

@@ -0,0 +1,66 @@
+# Dockerfile to build an image with the local version of psiphon-tunnel-core.
+#
+#  > docker build -t psigobuild $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidApp
+#  > docker run -it --rm -v $GOPATH/src:/src psigobuild
+
+FROM ubuntu:12.04
+
+# Install system-level dependencies.
+ENV DEBIAN_FRONTEND=noninteractive
+RUN echo "debconf shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections && \
+  echo "debconf shared/accepted-oracle-license-v1-1 seen true" | debconf-set-selections && \
+  apt-get update && \
+  apt-get -y install build-essential python-software-properties bzip2 unzip curl \
+    git subversion mercurial bzr \
+    libncurses5:i386 libstdc++6:i386 zlib1g:i386 && \
+  add-apt-repository ppa:webupd8team/java && \
+  apt-get update && \
+  apt-get -y install oracle-java7-installer
+
+# Install Ant.
+RUN echo "INSTALLING ANT" && \
+  curl -L https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz | tar xz -C /usr/local
+ENV ANT_HOME=/usr/local/apache-ant-1.9.4
+
+# Install Android SDK.
+ENV ANDROID_HOME=/usr/local/android-sdk-linux
+RUN echo "INSTALLING ANDROID SDK" && \
+  curl -L https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz | tar xz -C /usr/local && \
+  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter build-tools-21.1.2 && \
+  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter platform-tools && \
+  echo y | $ANDROID_HOME/tools/android update sdk --no-ui --all --filter android-21
+  
+# Install Android NDK.
+ENV NDK_ROOT=/usr/local/android-ndk-r10d
+RUN echo "INSTALLING ANDROID NDK" && \
+  wget https://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin && \
+  chmod a+x android-ndk-r10d-linux-x86_64.bin && ./android-ndk-r10d-linux-x86_64.bin && \
+  mv android-ndk-r10d /usr/local && \
+  $NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --arch=arm --install-dir=$NDK_ROOT --system=linux-x86_64
+
+# Install Gradle
+# : android-gradle compatibility
+#   http://tools.android.com/tech-docs/new-build-system/version-compatibility
+RUN echo "INSTALLING GRADLE" && \
+  curl -L https://services.gradle.org/distributions/gradle-2.2.1-all.zip -o /tmp/gradle-2.2.1-all.zip && \
+  unzip /tmp/gradle-2.2.1-all.zip -d /usr/local && rm /tmp/gradle-2.2.1-all.zip
+ENV GRADLE_HOME=/usr/local/gradle-2.2.1
+
+# Update PATH for the above.
+ENV PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$NDK_ROOT:$ANT_HOME/bin:$GRADLE_HOME/bin
+
+# Install Go.
+ENV GOROOT=/go \
+  GOPATH=/
+ENV PATH=$PATH:$GOROOT/bin
+RUN echo "INSTALLING GO" && \
+  curl -L https://github.com/golang/go/archive/master.zip -o /tmp/go.zip && \
+  unzip /tmp/go.zip && \
+  rm /tmp/go.zip && \
+  mv /go-master $GOROOT && \
+  echo devel > $GOROOT/VERSION && \
+  cd $GOROOT/src && \
+  ./all.bash && \
+  CC_FOR_TARGET=$NDK_ROOT/bin/arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 ./make.bash
+
+WORKDIR $GOPATH/src/golang.org/x/mobile

+ 21 - 0
AndroidLibrary/README.md

@@ -46,6 +46,27 @@ Follow Go Android documentation:
 * `$GOPATH/bin/gobind -lang=java github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi > java_psi/go/psi/Psi.java`
 * `$GOPATH/bin/gobind -lang=java github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary/psi > java_psi/go/psi/Psi.java`
 * In `/libpsi` `CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared"` and copy output file to `gojni.so`
 * In `/libpsi` `CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-shared"` and copy output file to `gojni.so`
 
 
+### Building with Docker
+
+Create the build image:
+
+```bash
+# While in the same directory as the Dockerfile...
+$ sudo docker build -t psibuild .
+# That will take a long time to complete.
+# After it's done, you'll have an image called "psibuild". Check with...
+$ sudo docker images
+```
+
+To do the build:
+
+```bash
+$ sudo docker run -v $GOPATH/src:/src psibuild /bin/bash -c 'cd /src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary && ./make.bash'
+```
+
+When that command completes, the compiled library will be located at `libs/armeabi-v7a/libgojni.so`.
+
+
 Using
 Using
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 
 

+ 16 - 0
AndroidLibrary/make.bash

@@ -0,0 +1,16 @@
+#!/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
+
+ANDROID_APP=$PWD
+
+CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
+  go build -a -v -ldflags="-shared" -o libgojni.so ./libpsi
+
+mkdir -p libs/armeabi-v7a
+mv -f libgojni.so libs/armeabi-v7a/libgojni.so