diff --git a/README.md b/README.md index a376daf5..436d9663 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ A port of [syncthing](https://github.com/calmh/syncthing) to Android. ## Building -Download or execute syncthing for your target platform, put the binary in `libs/armeabi`, `libs/armeabi-v7a`, `libs/mips`, `libs/x86`, (depending on target platform) and rename it to `libsyncthing.so`. +There are multiple ways to get the native syncthing binary: +- Depending on your target architecture, download `syncthing-linux-386`, `syncthing-linux-armv5` or `syncthing-linux-armv7` from [syncthing releases](https://github.com/calmh/syncthing/releases), and extract the binary to `libs/x86/libsyncthing.so`, `libs/armeabi-v7a/libsyncthing.so` or `libs/armeabi/libsyncthing.so` respectively. +- Set up a syncthing compile and run `gradle buildNative` in your syncthing-android directory. Then, run `gradle assembleDebug`. diff --git a/build.gradle b/build.gradle index acb16509..7948ac79 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,8 @@ buildscript { } } +import java.util.regex.Pattern + apply plugin: 'android' apply plugin: 'android_sign' @@ -23,12 +25,17 @@ dependencies { android { compileSdkVersion 19 buildToolsVersion "19.0.3" + + defaultConfig{ + versionCode getVersionCodeFromManifest() + } + sourceSets { main { jniLibs.srcDir file("libs/") - jniLibs.srcDir file("obj/") } } + signingConfigs { release { // Android Studio does not pass environment variables. @@ -51,4 +58,62 @@ android { signingConfig signingConfigs.release } } + + productFlavors { + x86 { + versionCode Integer.parseInt("4" + defaultConfig.versionCode) + ndk { + abiFilter "x86" + } + } + armeabi_v7a { + versionCode Integer.parseInt("3" + defaultConfig.versionCode) + ndk { + abiFilter "armeabi-v7a" + } + } + armeabi { + versionCode Integer.parseInt("2" + defaultConfig.versionCode) + ndk { + abiFilter "armeabi" + } + } + mips { + versionCode Integer.parseInt("1" + defaultConfig.versionCode) + ndk { + abiFilter "mips" + } + } + } } + +def getVersionCodeFromManifest() { + def manifestFile = file(android.sourceSets.main.manifest.srcFile) + def pattern = Pattern.compile("versionCode=\"(\\d+)\"") + def matcher = pattern.matcher(manifestFile.getText()) + matcher.find() + return Integer.parseInt(matcher.group(1)) +} + +ext.st_dir = System.getenv("GOPATH") + "/src/github.com/calmh/syncthing/"; +task buildNative(type:Exec) { + outputs.upToDateWhen { false } + executable = st_dir + 'build.sh' + workingDir = st_dir; + args = ['android'] +} + +task copyNative(type: Copy) { + outputs.upToDateWhen { false } + from st_dir + 'syncthing-x86', st_dir + 'syncthing-armeabi', st_dir + 'syncthing-armeabi-v7a'; + into 'libs/' + rename('syncthing-x86', 'x86/libsyncthing.so') + rename('syncthing-armeabi-v7a', 'armeabi-v7a/libsyncthing.so') + rename('syncthing-armeabi', 'armeabi/libsyncthing.so') + rename('syncthing-mips', 'mips/libsyncthing.so') +} +buildNative.finalizedBy copyNative + +task cleanNative(type: Delete) { + delete 'libs/' +} \ No newline at end of file