1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 12:21:15 +00:00

Docker image, and windows builds (#1049)

This commit is contained in:
Audrius Butkevicius 2018-04-09 21:13:25 +01:00 committed by GitHub
parent 7194e25a5c
commit 66ee130e7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 155 additions and 10 deletions

View file

@ -12,7 +12,7 @@ dependencies {
implementation 'com.annimon:stream:1.1.9'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "com.google.dagger:dagger:2.14.1"
implementation 'com.google.dagger:dagger:2.14.1'
annotationProcessor "com.google.dagger:dagger-compiler:2.14.1"
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'com.android.support:support-annotations:27.0.2'
@ -28,7 +28,7 @@ android {
playAccountConfigs {
defaultAccountConfig {
jsonFile = file('keys.json')
jsonFile = file(System.getenv("SYNCTHING_RELEASE_PLAY_ACCOUNT_CONFIG_FILE") ?: 'keys.json')
}
}
defaultConfig {
@ -55,7 +55,13 @@ android {
}
buildTypes {
release {
signingConfig signingConfigs.release
signingConfig = signingConfigs.release.storeFile ? signingConfigs.release : null
}
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
minifyEnabled false
}
}
@ -66,7 +72,7 @@ android {
}
play {
jsonFile = file('keys.json')
jsonFile = file(System.getenv("SYNCTHING_RELEASE_PLAY_ACCOUNT_CONFIG_FILE") ?: 'keys.json')
uploadImages = false
track = 'production'
}

41
docker/Dockerfile Normal file
View file

@ -0,0 +1,41 @@
FROM openjdk:8
ENV GO_VERSION 1.9.5
ENV ANDROID_SDK_VERSION 3859397
WORKDIR /opt
# Install Go
RUN wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -zxf go${GO_VERSION}.linux-amd64.tar.gz && \
rm go${GO_VERSION}.linux-amd64.tar.gz
ENV GOROOT /opt/go
ENV PATH /opt/go/bin:${PATH}
# Install Android SDK manager
RUN mkdir -p /opt/android-sdk && cd /opt/android-sdk && \
wget -q https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_VERSION}.zip && \
unzip -q sdk-tools-linux-${ANDROID_SDK_VERSION}.zip && \
rm sdk-tools-linux-${ANDROID_SDK_VERSION}.zip
ENV ANDROID_HOME /opt/android-sdk
# Accept the SDK license, as we can't install packages otherwise
RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses
# Install other android packages, including NDK
RUN ${ANDROID_HOME}/tools/bin/sdkmanager tools platform-tools "build-tools;27.0.2" "platforms;android-27" "extras;android;m2repository" ndk-bundle
# Accept licenses of newly installed packages
RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses
# Setup the NDK path
ENV ANDROID_NDK_HOME ${ANDROID_HOME}/ndk-bundle
# Enable prebuild mode
ENV SYNCTHING_ANDROID_PREBUILT 1
# Run prebuild script (will prebuild stuff into the image if env var is set)
ADD prebuild.sh /opt/prebuild.sh
RUN /opt/prebuild.sh
WORKDIR /mnt

7
docker/README.md Normal file
View file

@ -0,0 +1,7 @@
# How to use this
1. Build the docker image: `docker build -t syncthing-android-builder:latest .`
2. Checkout syncthing-android somewhere (for the sake of discussion let's say /tmp/syncthing-android)
3. Inside /tmp/syncthing-android, do `git submodule init; git submodule update`
4. Run `docker run --rm -v /tmp/syncthing-android:/mnt syncthing-android-builder ./gradlew buildNative assembleDebug`
5. Retrieve APKs from /tmp/syncthing-android/app/build/outputs

41
docker/prebuild.sh Executable file
View file

@ -0,0 +1,41 @@
#!/bin/bash -e
[ -z "$SYNCTHING_ANDROID_PREBUILT" ] && echo "Prebuild disabled" && exit 0
for ARCH in arm x86 arm64; do
GOARCH=${ARCH}
SDK=14
case ${ARCH} in
arm)
GCC="arm-linux-androideabi-clang"
;;
arm64)
SDK=21
GCC="aarch64-linux-android-clang"
;;
x86)
GOARCH=386
GCC="i686-linux-android-clang"
;;
*)
echo "Invalid architecture"
exit 1
esac
STANDALONE_NDK_DIR="${ANDROID_NDK_HOME}/standalone-ndk/android-${SDK}-${GOARCH}"
echo "Building standalone NDK - ${STANDALONE_NDK_DIR}"
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
--platform=android-${SDK} --arch=${ARCH} \
--install-dir=${STANDALONE_NDK_DIR}
echo "Pre-building Go standard library for $GOARCH"
CGO_ENABLED=1 CC="${STANDALONE_NDK_DIR}/bin/${GCC}" \
GOOS=android GOARCH=$GOARCH go install -v std
done
echo "Prepopulating gradle cache"
git clone https://github.com/syncthing/syncthing-android
cd syncthing-android
./gradlew --no-daemon lint
cd ..
rm -rf syncthing-android

View file

@ -2,13 +2,24 @@
set -e
if [ -z "${ANDROID_NDK_HOME}" ]; then
echo "Please set ANDROID_NDK_HOME environment variable"
exit 1
fi
MODULE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_DIR="${MODULE_DIR}/.."
MIN_SDK=$(grep "minSdkVersion" "${PROJECT_DIR}/app/build.gradle" -m 1 | awk '{print $2}')
# Use seperate build dir so standalone ndk isn't deleted by `gradle clean`
BUILD_DIR="${MODULE_DIR}/gobuild"
GO_BUILD_DIR="${BUILD_DIR}/go-packages"
export GOPATH="${MODULE_DIR}/"
if [ "${OSTYPE}" = "cygwin" ]; then
export GOPATH=`cygpath -w ${GOPATH}`
GO_BUILD_DIR=`cygpath -w ${GO_BUILD_DIR}`
fi
cd "${MODULE_DIR}/src/github.com/syncthing/syncthing"
# Make sure all tags are available for git describe
@ -40,11 +51,41 @@ for ANDROID_ARCH in arm x86 arm64; do
exit 1
esac
# Build standalone NDK toolchain if it doesn't exist.
# https://developer.android.com/ndk/guides/standalone_toolchain.html
STANDALONE_NDK_DIR="${BUILD_DIR}/standalone-ndk/android-${MIN_SDK}-${GOARCH}"
if [ -z "${SYNCTHING_ANDROID_PREBUILT}" ]; then
# Build standalone NDK toolchain if it doesn't exist.
# https://developer.android.com/ndk/guides/standalone_toolchain.html
STANDALONE_NDK_DIR="${BUILD_DIR}/standalone-ndk/android-${MIN_SDK}-${GOARCH}"
PKG_ARGUMENT="-pkgdir ${GO_BUILD_DIR}"
else
# The environment variable indicates the SDK and stdlib was prebuilt, set a custom paths.
STANDALONE_NDK_DIR="${ANDROID_NDK_HOME}/standalone-ndk/android-${MIN_SDK}-${GOARCH}"
PKG_ARGUMENT=""
fi
if [ ! -d "$STANDALONE_NDK_DIR" ]; then
if ! which python &>/dev/null; then
echo "Could not find python"
exit 1
fi
# We can't build the NDK with Cygwin/MinGW provided python, check that python is reporting a sensible host system.
# Also, strip \r as that is returned by Windows python.
HOST_PLATFORM=`python -c 'import platform; print platform.system()' | tr -d '\r'`
case ${HOST_PLATFORM} in
Windows|Linux|Darwin)
;;
*)
echo "Cannot build NDK with Python provided by an unsupported system: ${HOST_PLATFORM}"
echo "Please make sure that python that is available on the path is native to your host platform (Windows/Linux/Darwin)"
exit 1
;;
esac
if [ "${OSTYPE}" = "cygwin" ]; then
STANDALONE_NDK_DIR=`cygpath -w ${STANDALONE_NDK_DIR}`
fi
echo -e "Building standalone NDK\n"
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
--platform=android-${MIN_SDK} --arch=${ANDROID_ARCH} \
@ -53,7 +94,7 @@ for ANDROID_ARCH in arm x86 arm64; do
echo -e "Building Syncthing\n"
CGO_ENABLED=1 CC="${STANDALONE_NDK_DIR}/bin/${GCC}" \
go run build.go -goos android -goarch ${GOARCH} -pkgdir "${BUILD_DIR}/go-packages" -no-upgrade build
go run build.go -goos android -goarch ${GOARCH} $PKG_ARGUMENT -no-upgrade build
# Copy compiled binary to jniLibs folder
TARGET_DIR="${PROJECT_DIR}/app/src/main/jniLibs/${JNI_DIR}"

View file

@ -1,10 +1,19 @@
import org.gradle.internal.os.OperatingSystem
task buildNative(type: Exec) {
outputs.upToDateWhen { false }
executable = './build-syncthing.bash'
if (OperatingSystem.current().isWindows()) {
if (!file("../app/src/main/jniLibs").exists()) {
throw new GradleException('Please run ./build-syncthing.bash via cygwin/MinGW manually')
}
executable = 'rundll32' // Does nothing
} else {
executable = './build-syncthing.bash'
}
}
/**
* Use seperate task instead of standard clean(), so these folders aren't deleted by `gradle clean`.
* Use separate task instead of standard clean(), so these folders aren't deleted by `gradle clean`.
*/
task cleanNative(type: Delete) {
delete "../app/src/main/jniLibs/"