-
Notifications
You must be signed in to change notification settings - Fork 336
/
build-apk.sh
executable file
·134 lines (114 loc) · 4.02 KB
/
build-apk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
echo "Computing build version..."
echo ""
PRODUCT_VERSION=$(cargo run -q --bin mullvad-version versionName)
echo "Building Mullvad VPN $PRODUCT_VERSION for Android"
echo ""
BUILD_TYPE="release"
GRADLE_BUILD_TYPE="release"
GRADLE_TASKS=(createOssProdReleaseDistApk createPlayProdReleaseDistApk)
BUNDLE_TASKS=(createPlayProdReleaseDistBundle)
CARGO_ARGS=( "--release" )
BUILD_BUNDLE="no"
CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"target"}
SKIP_STRIPPING=${SKIP_STRIPPING:-"no"}
while [ -n "${1:-""}" ]; do
if [[ "${1:-""}" == "--dev-build" ]]; then
BUILD_TYPE="debug"
GRADLE_BUILD_TYPE="debug"
CARGO_ARGS=()
GRADLE_TASKS=(createOssProdDebugDistApk)
BUNDLE_TASKS=(createOssProdDebugDistBundle)
elif [[ "${1:-""}" == "--fdroid" ]]; then
GRADLE_BUILD_TYPE="fdroid"
GRADLE_TASKS=(createOssProdFdroidDistApk)
BUNDLE_TASKS=(createOssProdFdroidDistBundle)
elif [[ "${1:-""}" == "--app-bundle" ]]; then
BUILD_BUNDLE="yes"
elif [[ "${1:-""}" == "--skip-stripping" ]]; then
SKIP_STRIPPING="yes"
fi
shift 1
done
if [[ "$GRADLE_BUILD_TYPE" == "release" ]]; then
if [ ! -f "$SCRIPT_DIR/android/credentials/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" == "release" && "$PRODUCT_VERSION" != *"-dev-"* ]]; then
echo "Removing old Rust build artifacts"
cargo clean
CARGO_ARGS+=( "--locked" )
else
CARGO_ARGS+=( "--features" "api-override" )
GRADLE_TASKS+=(createPlayDevmoleReleaseDistApk createPlayStagemoleReleaseDistApk)
BUNDLE_TASKS+=(createPlayDevmoleReleaseDistBundle createPlayStagemoleReleaseDistBundle)
fi
pushd "$SCRIPT_DIR/android"
# Fallback to the system-wide gradle command if the gradlew script is removed.
# It is removed by the F-Droid build process before the build starts.
if [ -f "gradlew" ]; then
GRADLE_CMD="./gradlew"
elif which gradle > /dev/null; then
GRADLE_CMD="gradle"
else
echo "ERROR: No gradle command found" >&2
echo " Please either install gradle or restore the gradlew file" >&2
exit 2
fi
$GRADLE_CMD --console plain clean
mkdir -p "app/build/extraAssets"
mkdir -p "app/build/extraJni"
popd
for ARCHITECTURE in ${ARCHITECTURES:-aarch64 armv7 x86_64 i686}; 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
echo "Building mullvad-daemon for $TARGET"
cargo build "${CARGO_ARGS[@]}" --target "$TARGET" --package mullvad-jni
STRIP_TOOL="${NDK_TOOLCHAIN_DIR}/llvm-strip"
TARGET_LIB_PATH="$SCRIPT_DIR/android/app/build/extraJni/$ABI/libmullvad_jni.so"
UNSTRIPPED_LIB_PATH="$CARGO_TARGET_DIR/$TARGET/$BUILD_TYPE/libmullvad_jni.so"
if [[ "$SKIP_STRIPPING" == "yes" ]]; then
cp "$UNSTRIPPED_LIB_PATH" "$TARGET_LIB_PATH"
else
$STRIP_TOOL --strip-debug --strip-unneeded -o "$TARGET_LIB_PATH" "$UNSTRIPPED_LIB_PATH"
fi
done
echo "Updating relays.json..."
cargo run --bin relay_list "${CARGO_ARGS[@]}" > android/app/build/extraAssets/relays.json
echo "Copying maybenot machines..."
cp dist-assets/maybenot_machines_v2 android/app/build/extraAssets/
cd "$SCRIPT_DIR/android"
$GRADLE_CMD --console plain "${GRADLE_TASKS[@]}"
if [[ "$BUILD_BUNDLE" == "yes" ]]; then
$GRADLE_CMD --console plain "${BUNDLE_TASKS[@]}"
fi
echo "**********************************"
echo ""
echo " The build finished successfully! "
echo " You have built:"
echo ""
echo " $PRODUCT_VERSION"
echo ""
echo "**********************************"