Skip to content

Commit 8abbb8e

Browse files
Fix build.sh script and simplify it by removing environment variable checking, relying instead on Gradle wrapper and AGP for detecting and reporting such issues.
1 parent bc6d91a commit 8abbb8e

File tree

1 file changed

+9
-84
lines changed

1 file changed

+9
-84
lines changed

build.sh

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1+
#!/usr/bin/env bash
12
### Bash script for building Talkback-for-Partners Android apk
2-
###
3-
### The following environment variables must be set before executing this script
4-
### ANDROID_SDK # path to local copy of Android SDK
5-
### ANDROID_NDK # path to local copy of Android NDK
6-
### JAVA_HOME # path to local copy of Java SDK.
7-
8-
# For help in getting the correct version numbers of gradle, the gradle plugin,
9-
# and Java, see the following:
10-
# https://developer.android.com/build/releases/gradle-plugin#updating-gradle
11-
# https://docs.gradle.org/current/userguide/compatibility.html
12-
GRADLE_DOWNLOAD_VERSION=7.3.3
3+
WORK_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
134
GRADLE_TRACE=false # change to true to enable verbose logging of gradle
14-
5+
GRADLE_WRAPPER="$WORK_DIR/gradlew"
156

167
function log {
178
if [[ -n $1 ]]; then
@@ -20,79 +11,13 @@ function log {
2011
fi
2112
}
2213

23-
function fail_with_message {
24-
echo
25-
echo "Error: ${1}"
26-
exit 1
27-
}
28-
29-
function require_environment_variable() {
30-
if [[ -z ${!1+set} ]]; then
31-
fail_with_message "the environment variable $1 is not set"
32-
exit 1
33-
else
34-
log "${1}: ${!1}"
35-
fi
36-
}
37-
38-
function require_folder_exists() {
39-
if [[ ! -d "${1}" ]]; then
40-
fail_with_message "the folder at ${1} does not exist"
41-
exit 1
42-
else
43-
log "ls ${1}"; ls "${1}"
44-
fi
45-
}
46-
47-
4814
log "pwd: $(pwd)"
4915
log "ls"; ls
5016
log
5117

52-
53-
require_environment_variable ANDROID_SDK
54-
require_folder_exists "${ANDROID_SDK}"
55-
require_environment_variable ANDROID_NDK
56-
require_folder_exists "${ANDROID_NDK}"
57-
require_environment_variable JAVA_HOME
58-
require_folder_exists "${JAVA_HOME}"
59-
log
60-
61-
62-
log "Write local.properties file"
63-
echo "sdk.dir=${ANDROID_SDK}" > local.properties
64-
echo "ndk.dir=${ANDROID_NDK}" >> local.properties
65-
log "cat local.properties"; cat local.properties
66-
log
67-
68-
69-
# Download the gradle binary at the version set atop this file
70-
GRADLE_ZIP_REMOTE_FILE=gradle-${GRADLE_DOWNLOAD_VERSION}-bin.zip
71-
GRADLE_ZIP_DEST_PATH=~/${GRADLE_DOWNLOAD_VERSION}.zip
72-
log "Download gradle binary from the web ${GRADLE_ZIP_REMOTE_FILE} to ${GRADLE_ZIP_DEST_PATH} using wget"
73-
time wget -O ${GRADLE_ZIP_DEST_PATH} https://services.gradle.org/distributions/${GRADLE_ZIP_REMOTE_FILE}
74-
log
75-
76-
77-
# Unzip the gradle binary
78-
GRADLE_UNZIP_HOSTING_FOLDER=/opt/gradle-${GRADLE_DOWNLOAD_VERSION}
79-
log "Unzip gradle zipfile ${GRADLE_ZIP_DEST_PATH} to ${GRADLE_UNZIP_HOSTING_FOLDER}"
80-
sudo unzip -n -d ${GRADLE_UNZIP_HOSTING_FOLDER} ${GRADLE_ZIP_DEST_PATH}
81-
GRADLE_BINARY=${GRADLE_UNZIP_HOSTING_FOLDER}/gradle-${GRADLE_DOWNLOAD_VERSION}/bin/gradle
82-
log "\${GRADLE_BINARY} = ${GRADLE_BINARY}"
83-
log "\${GRADLE_BINARY} -version"
84-
${GRADLE_BINARY} -version
85-
log
86-
87-
88-
log "find gradle"
89-
find gradle
90-
log
91-
92-
9318
if [[ "$GRADLE_TRACE" = true ]]; then
94-
log "${GRADLE_BINARY} dependencies"
95-
${GRADLE_BINARY} dependencies
19+
log "${GRADLE_WRAPPER} dependencies"
20+
${GRADLE_WRAPPER} dependencies
9621
log
9722
fi
9823

@@ -103,15 +28,15 @@ if [[ "$GRADLE_TRACE" = true ]]; then
10328
GRADLE_DEBUG=--debug
10429
GRADLE_STACKTRACE=--stacktrace
10530
fi
106-
log "${GRADLE_BINARY} assembleDebug"
107-
${GRADLE_BINARY} ${GRADLE_DEBUG} ${GRADLE_STACKTRACE} assembleDebug
31+
log "${GRADLE_WRAPPER} assembleDebug"
32+
${GRADLE_WRAPPER} ${GRADLE_DEBUG} ${GRADLE_STACKTRACE} assembleDebug
10833
BUILD_EXIT_CODE=$?
10934
log
11035

11136

11237
if [[ $BUILD_EXIT_CODE -eq 0 ]]; then
113-
log "find . -name *.apk"
114-
find . -name "*.apk"
38+
log "find $WORK_DIR -name *.apk"
39+
find $WORK_DIR -name "*.apk"
11540
log
11641
fi
11742

0 commit comments

Comments
 (0)