Skip to content

Commit 24ea5a0

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 e77aa04 commit 24ea5a0

File tree

1 file changed

+9
-81
lines changed

1 file changed

+9
-81
lines changed

build.sh

Lines changed: 9 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +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-
### JAVA_HOME # path to local copy of Java SDK.
6-
7-
### Environment variables:
8-
# ANDROID_SDK=~/Android/Sdk
9-
# ANDROID_NDK=~/Android/Sdk/ndk
10-
# The latest JDK,
11-
# JAVA_HOME=/usr/local/buildtools/java/jdk
12-
# JDK 17, work for current build,
13-
# JAVA_HOME=/google/data/ro/projects/java-platform/linux-amd64/jdk-17-latest/bin
14-
15-
# For help in getting the correct version numbers of gradle, the gradle plugin,
16-
# and Java, see the following:
17-
# https://developer.android.com/build/releases/gradle-plugin#updating-gradle
18-
# https://docs.gradle.org/current/userguide/compatibility.html
19-
GRADLE_DOWNLOAD_VERSION=7.6.4
3+
WORK_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
204
GRADLE_TRACE=false # change to true to enable verbose logging of gradle
21-
5+
GRADLE_WRAPPER="$WORK_DIR/gradlew"
226

237
function log {
248
if [[ -n $1 ]]; then
@@ -27,69 +11,13 @@ function log {
2711
fi
2812
}
2913

30-
function fail_with_message {
31-
echo
32-
echo "Error: ${1}"
33-
exit 1
34-
}
35-
36-
function require_environment_variable() {
37-
if [[ -z ${!1+set} ]]; then
38-
fail_with_message "the environment variable $1 is not set"
39-
else
40-
log "${1}: ${!1}"
41-
fi
42-
}
43-
44-
function require_folder_exists() {
45-
if [[ ! -d "${1}" ]]; then
46-
fail_with_message "the folder at ${1} does not exist"
47-
else
48-
log "ls ${1}"; ls "${1}"
49-
fi
50-
}
51-
52-
5314
log "pwd: $(pwd)"
5415
log "ls"; ls
5516
log
5617

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

@@ -100,15 +28,15 @@ if [[ "$GRADLE_TRACE" = true ]]; then
10028
GRADLE_DEBUG=--debug
10129
GRADLE_STACKTRACE=--stacktrace
10230
fi
103-
log "${GRADLE_BINARY} assembleDebug"
104-
${GRADLE_BINARY} ${GRADLE_DEBUG} ${GRADLE_STACKTRACE} assembleDebug
31+
log "${GRADLE_WRAPPER} assembleDebug"
32+
${GRADLE_WRAPPER} ${GRADLE_DEBUG} ${GRADLE_STACKTRACE} assembleDebug
10533
BUILD_EXIT_CODE=$?
10634
log
10735

10836

10937
if [[ $BUILD_EXIT_CODE -eq 0 ]]; then
110-
log "find . -name *.apk"
111-
find . -name "*.apk"
38+
log "find $WORK_DIR -name *.apk"
39+
find $WORK_DIR -name "*.apk"
11240
log
11341
fi
11442

0 commit comments

Comments
 (0)