From 9f4bb9923b3f575fef1470388393e39941a3cf24 Mon Sep 17 00:00:00 2001 From: Lode Hoste Date: Wed, 20 Aug 2014 23:58:28 +0200 Subject: [PATCH] Prepare building environment for F-Droid. --- .gitignore | 11 +++ .gitmodules | 3 + README.md | 27 ++++-- build-native.sh | 19 ---- build-syncthing.sh | 86 +++++++++++++++++++ build.gradle | 32 +++++-- .../src/github.com/syncthing/syncthing | 1 + gradle/wrapper/build.xml | 3 + gradle/wrapper/gradle-wrapper.properties | 6 ++ 9 files changed, 157 insertions(+), 31 deletions(-) create mode 100644 .gitmodules delete mode 100755 build-native.sh create mode 100755 build-syncthing.sh create mode 160000 ext/syncthing/src/github.com/syncthing/syncthing create mode 100644 gradle/wrapper/build.xml create mode 100644 gradle/wrapper/gradle-wrapper.properties diff --git a/.gitignore b/.gitignore index d91778ea..692f544a 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,14 @@ proguard/ *.ipr *.iws .idea/ + +# Gradle wrapper +gradle/wrapper/gradle/ +gradle/wrapper/gradlew* + +# Syncthing native dependencies +ext/syncthing/pkg/ +ext/syncthing/src/code.google.com/ +ext/syncthing/src/github.com/kr/ +ext/syncthing/src/github.com/mattn/ +ext/syncthing/src/github.com/tools/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..01fed3c4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ext/syncthing/src/github.com/syncthing/syncthing"] + path = ext/syncthing/src/github.com/syncthing/syncthing + url = https://github.com/syncthing/syncthing.git diff --git a/README.md b/README.md index 4a907a3c..139f1069 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,32 @@ ## syncthing-android -A wrapper of [syncthing](https://github.com/calmh/syncthing) for Android. +A wrapper of [syncthing](https://github.com/syncthing/syncthing) for Android. [![Get it on Google Play](https://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.nutomic.syncthingandroid) +## Requirements +- sudo apt-get install build-essential +- Android SDK 19+ and the Android Support Repository are required. +- Use `git clone --recursive https://github.com/Nutomic/syncthing-android` to download the source and its submodules. + ## Building -To get syncthing app for android running on you device/emulator the native syncthing binary has to be available. There are multiple ways to get the native syncthing binary: -- open a syncthing apk (the one taken from the play store) running on your device as a zip, extract the `lib/` folder into your project directory and rename it to `libs/`. -- Depending on your target architecture, download `syncthing-linux-386`, `syncthing-linux-armv5`, `syncthing-linux-armv7` or `syncthing-linux-mips` from [syncthing releases](https://github.com/calmh/syncthing/releases), and extract the binary to `libs/x86/libsyncthing.so`, `libs/armeabi-v7a/libsyncthing.so`, `libs/armeabi/libsyncthing.so` or `libs/mips/libsyncthing.so` respectively. -- Set up a syncthing compile and run `gradle buildNative` in your syncthing-android directory. +Use `gradlew assembleDebug` to compile the APK. + +Note: Gradlew is a gradle wrapper which allows to specify the gradle version. Use `gradle -b gradle/wrapper/build.xml wrapper` to create your own gradlew instance. Then add it to your path using `export PATH=$PATH:$(pwd)/gradle/wrapper`. + +The build process follows three phases: +- It downloads and compiles Golang v1.3 for x86 and ARM cross-compilation: Syncthing-android depends on Syncthing "native" (https://github.com/syncthing/syncthing) and this requires Go v1.3. +- The Syncthing native libraries are compiled for the different architectures using `gradlew buildNative`. +- The final APK is built using the `gradlew assembleDebug` task. + + +## Getting Syncthing without building natively + +To get Syncthing app for Android running on you device/emulator the native syncthing binary has to be available. There are multiple ways to get the native syncthing binary: +- open the Syncthing apk (the one taken from the play store) running on your device as a zip, extract the `lib/` folder into your project directory and rename it to `libs/`. +- Depending on your target architecture, download `syncthing-linux-386`, `syncthing-linux-armv5`, `syncthing-linux-armv7` or `syncthing-linux-mips` from [syncthing releases](https://github.com/calmh/syncthing/releases), and extract the binary to `libs/x86/libsyncthing.so`, `libs/armeabi/libsyncthing.so`, `libs/armeabi-v7a/libsyncthing.so` or `libs/mips/libsyncthing.so` respectively. -Then, run `gradle assembleDebug`. ## License diff --git a/build-native.sh b/build-native.sh deleted file mode 100755 index 3dd31444..00000000 --- a/build-native.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -cd "$GOPATH/src/github.com/syncthing/syncthing/" - -rm bin/ - -./build.sh test || exit 1 - -export GOOS=linux -export ENVIRONMENT=android - -GOARCH=386 ./build.sh "" -tags noupgrade -mv bin/linux_386/syncthing bin/syncthing-x86 - -GOARCH=arm GOARM=5 ./build.sh "" -tags noupgrade -mv bin/linux_arm/syncthing bin/syncthing-armeabi - -GOARCH=arm GOARM=7 ./build.sh "" -tags noupgrade -mv bin/linux_arm/syncthing bin/syncthing-armeabi-v7a diff --git a/build-syncthing.sh b/build-syncthing.sh new file mode 100755 index 00000000..6f7f8de1 --- /dev/null +++ b/build-syncthing.sh @@ -0,0 +1,86 @@ +#!/bin/bash -e + +# Build the syncthing library +ORIG=$(pwd) +mkdir -p bin + +# Load submodules +if [ ! -f "ext/syncthing/src/github.com/syncthing/syncthing/.git" ]; then + git submodule update --init --recursive +fi + +# Check for GOLANG installation +if [ -z $GOROOT ]; then + mkdir -p "build" + tmpgo='build/go' + if [ ! -f "$tmpgo/bin/go" ]; then + # Download GOLANG v1.3 + wget -O go.src.tar.gz https://golang.org/dl/go1.3.src.tar.gz + sha1=$(sha1sum go.src.tar.gz) + if [ "$sha1" != "9f9dfcbcb4fa126b2b66c0830dc733215f2f056e go.src.tar.gz" ]; then + echo "go.src.tar.gz SHA1 checksum does not match!" + exit 1 + fi + mkdir -p $tmpgo + tar -xzf go.src.tar.gz --strip=1 -C $tmpgo + rm go.src.tar.gz + # Build GO for host + pushd $tmpgo/src + ./make.bash --no-clean + popd + fi + # Add GO to the environment + export GOROOT="$(readlink -e $tmpgo)" +fi + +# Add GO compiler to PATH +export PATH=$PATH:$GOROOT/bin + +# Check whether GOLANG is compiled with cross-compilation for 386 +if [ ! -f $GOROOT/bin/linux_386/go ]; then + pushd $GOROOT/src + # Build GO for cross-compilation + GOOS=linux GOARCH=386 ./make.bash --no-clean + popd +fi + +# Check whether GOLANG is compiled with cross-compilation for arm +if [ ! -f $GOROOT/bin/linux_arm/go ]; then + pushd $GOROOT/src + # Build GO for cross-compilation + GOOS=linux GOARCH=arm ./make.bash --no-clean + popd +fi + +# Setup GOPATH +cd "ext/syncthing/" +export GOPATH="$(pwd)" + +# Install godep +$GOROOT/bin/go get github.com/tools/godep +export PATH="$(readlink -e bin)":$PATH + +# Install dependencies +cd src/github.com/syncthing/syncthing +./build.sh setup || true + +# Build test +#./build.sh test || exit 1 + +export GOOS=linux +export ENVIRONMENT=android + +# X86 +$GOROOT/bin/go run build.go -goos linux -goarch 386 -no-upgrade build +mv syncthing $ORIG/bin/syncthing-x86 +$GOROOT/bin/go run build.go clean + +# ARM-7 +$GOROOT/bin/go run build.go -goos linux -goarch armv7 -no-upgrade build +mv syncthing $ORIG/bin/syncthing-armeabi-v7a +$GOROOT/bin/go run build.go clean + +# ARM-5 +$GOROOT/bin/go run build.go -goos linux -goarch armv5 -no-upgrade build +mv syncthing $ORIG/bin/syncthing-armeabi +$GOROOT/bin/go run build.go clean diff --git a/build.gradle b/build.gradle index d6f2aad9..a38a9731 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,10 @@ dependencies { compile 'com.android.support:appcompat-v7:19.1.+' } +preBuild { + dependsOn 'buildNative' +} + android { compileSdkVersion 19 buildToolsVersion "19.1.0" @@ -84,6 +88,9 @@ android { abiFilter "mips" } } + fat { + versionCode Integer.parseInt("0" + defaultConfig.versionCode) + } } } @@ -97,19 +104,32 @@ def getVersionCodeFromManifest() { task buildNative(type: Exec) { outputs.upToDateWhen { false } - executable = './build-native.sh' + executable = './build-syncthing.sh' } task copyNative(type: Copy) { - def st_dir = System.getenv("GOPATH") + "/src/github.com/syncthing/syncthing/bin/"; - from st_dir + 'syncthing-x86', st_dir + 'syncthing-armeabi-v7a', st_dir + 'syncthing-armeabi'; - into 'libs/' + def lib_dir = "libs/" + new File(lib_dir).mkdirs() + def st_dir = "bin/"; + from st_dir + 'syncthing-x86', st_dir + 'syncthing-armeabi', st_dir + 'syncthing-armeabi-v7a'; + into lib_dir rename('syncthing-x86', 'x86/libsyncthing.so') rename('syncthing-armeabi-v7a', 'armeabi-v7a/libsyncthing.so') rename('syncthing-armeabi', 'armeabi/libsyncthing.so') } buildNative.finalizedBy copyNative -task cleanNative(type: Delete) { - delete 'libs/' +task cleanBin(type: Delete) { + delete 'bin/' } +copyNative.finalizedBy cleanBin + +task cleanNative(type: Delete) { + delete 'bin/' + delete 'build/' + delete 'libs/' + delete 'ext/syncthing/bin/' + delete 'ext/syncthing/pkg/' +} +clean.dependsOn cleanNative + diff --git a/ext/syncthing/src/github.com/syncthing/syncthing b/ext/syncthing/src/github.com/syncthing/syncthing new file mode 160000 index 00000000..c57656e4 --- /dev/null +++ b/ext/syncthing/src/github.com/syncthing/syncthing @@ -0,0 +1 @@ +Subproject commit c57656e4c3162fcdfc99eaee95bf4b2473dbbb72 diff --git a/gradle/wrapper/build.xml b/gradle/wrapper/build.xml new file mode 100644 index 00000000..34fe7ab8 --- /dev/null +++ b/gradle/wrapper/build.xml @@ -0,0 +1,3 @@ +task wrapper(type: Wrapper) { + gradleVersion = '1.12' +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..9149c4f6 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Aug 04 01:49:45 CEST 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip