Skip to content

Commit

Permalink
Create helper script to build app for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Janito Vaqueiro Ferreira Filho committed Jul 18, 2019
1 parent 193a616 commit 4897b4d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 17 deletions.
17 changes: 0 additions & 17 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ android {
variant.mergeAssetsProvider.configure {
dependsOn copyApiRootCertificate
}

variant.ndkCompileProvider.configure {
dependsOn copyMullvadJni
dependsOn copyWireguardGo
}
}
}

Expand Down Expand Up @@ -114,18 +109,6 @@ task format(type: FormatTask, group: 'formatting') {

lint.dependsOn lintKotlin

task copyMullvadJni(type: Copy) {
from "$repoRootPath/target/aarch64-linux-android/debug"
include 'libmullvad_jni.so'
into "$extraJniDirectory/arm64-v8a"
}

task copyWireguardGo(type: Copy) {
from "$repoRootPath/dist-assets/binaries/aarch64-linux-android"
include 'libwg.so'
into "$extraJniDirectory/arm64-v8a"
}

task copyApiRootCertificate(type: Copy) {
from "$repoRootPath/dist-assets"
include "api_root_ca.pem"
Expand Down
76 changes: 76 additions & 0 deletions build-apk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

PRODUCT_VERSION="$(node -p "require('$SCRIPT_DIR/gui/package.json').version" | sed -Ee 's/\.0//g')"

if [[ "${1:-""}" == "--dev-build" ]]; then
BUILD_TYPE="debug"
GRADLE_TASK="assembleDebug"
APK_SUFFIX="-debug"
CARGO_FLAGS=""
else
BUILD_TYPE="release"
GRADLE_TASK="assembleRelease"
APK_SUFFIX=""
CARGO_FLAGS="--release"

if [ ! -f "$SCRIPT_DIR/android/keystore.properties" ]; then
echo "ERROR: No keystore.properties file found" >&2
echo " Please configure the signing keys as described in the README" >&2
exit 1
fi
fi

if [[ "$BUILD_TYPE" == "debug" || "$(git describe)" != "$PRODUCT_VERSION" ]]; then
GIT_COMMIT="$(git rev-parse --short HEAD)"
APK_VERSION="${PRODUCT_VERSION}-dev-${GIT_COMMIT}"
else
APK_VERSION="$PRODUCT_VERSION"
fi

ARCHITECTURES="aarch64 armv7 x86_64 i686"

cd "$SCRIPT_DIR/android"
./gradlew --console plain clean
mkdir -p "${SCRIPT_DIR}/android/build/extraJni"

cd "$SCRIPT_DIR"

for ARCHITECTURE in $ARCHITECTURES; do
case "$ARCHITECTURE" in
"x86_64")
TARGET="x86_64-linux-android"
ABI="x86_64"
;;
"i686")
TARGET="i686-linux-android"
ABI="x86"
;;
"aarch64")
TARGET="aarch64-linux-android"
ABI="arm64-v8a"
;;
"armv7")
TARGET="armv7-linux-androideabi"
ABI="armeabi-v7a"
;;
esac

. env.sh "$TARGET"
cargo build $CARGO_FLAGS --target "$TARGET" --package mullvad-jni

cp -a "$SCRIPT_DIR/dist-assets/binaries/$TARGET" "$SCRIPT_DIR/android/build/extraJni/$ABI"
cp "$SCRIPT_DIR/target/$TARGET/$BUILD_TYPE/libmullvad_jni.so" "$SCRIPT_DIR/android/build/extraJni/$ABI/"
done

cd "$SCRIPT_DIR/android"
./gradlew --console plain "$GRADLE_TASK"

GENERATED_APK="$SCRIPT_DIR/android/build/outputs/apk/$BUILD_TYPE/android-$BUILD_TYPE.apk"

mkdir -p ../dist
cp "$GENERATED_APK" "$SCRIPT_DIR/dist/MullvadVPN-${APK_VERSION}${APK_SUFFIX}.apk"

0 comments on commit 4897b4d

Please sign in to comment.