-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_sign_prod_release_bundle.sh
executable file
·75 lines (63 loc) · 2.46 KB
/
build_sign_prod_release_bundle.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
#!/bin/bash
function messageExit() {
RED='\033[0;31m'
NC='\033[0m'
echo -e "\n${RED}$1${NC}\n"
exit 1
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Newline for easier reading
echo -e "\nBuilding app..."
# Script's dir must have a gradlew
GRADLEW=$DIR/gradlew
if [ ! -f "$GRADLEW" ]; then
messageExit "Call this script from the project dir"
fi
# App dir must have a build file
APP_BUILD_FILE=$DIR/app/build.gradle.kts
if [[ ! -f "$APP_BUILD_FILE" ]]; then
messageExit "App build file not found relative to the project dir"
fi
# Build file must not order signing (will be done later this script)
buildFileContents=$(<$APP_BUILD_FILE)
buildSigningLine=$(sed -n '/^[[:space:]]*signingConfig[[:space:]]*=[[:space:]]*signingConfigs\.getByName/p' "$APP_BUILD_FILE")
if [[ ! -z "${buildSigningLine}" ]]; then
messageExit "Comment the signingConfig line in the app build file before running this script"
fi
# Signing properties must be set as envvars and keystore file must exist
if [[ -z "$CRISIS_CLEANUP_ANDROID_KEYSTORE_PW" ]]; then
messageExit "Set CRISIS_CLEANUP_ANDROID_KEYSTORE_PW to continue building"
fi
if [[ -z "$CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_ALIAS" ]]; then
messageExit "Set CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_ALIAS to continue building"
fi
if [[ -z "$CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_PW" ]]; then
messageExit "Set CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_PW to continue building"
fi
if [[ -z "$CRISIS_CLEANUP_ANDROID_KEYSTORE_PATH" ]]; then
messageExit "Set CRISIS_CLEANUP_ANDROID_KEYSTORE_PATH to continue building"
fi
if [[ ! -f "$CRISIS_CLEANUP_ANDROID_KEYSTORE_PATH" ]]; then
messageExit "Keystore does not exist at specified path. Not attempting build."
fi
# Clean and build
$GRADLEW clean
$GRADLEW bundleProdRelease
APP_OUT=$DIR/app/build/outputs
if [[ -z "$DIST_DIR" ]]; then
DIST_DIR=$DIR/app/build
fi
DIST_AAB=$DIST_DIR/app-prod-release.aab
cp $APP_OUT/bundle/prodRelease/app-prod-release.aab $DIST_AAB
# Sign app bundle
jarsigner -verbose -storepass $CRISIS_CLEANUP_ANDROID_KEYSTORE_PW -keystore $CRISIS_CLEANUP_ANDROID_KEYSTORE_PATH $DIST_AAB $CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_ALIAS -keypass $CRISIS_CLEANUP_ANDROID_KEYSTORE_KEY_PW
# Most likely successful
if [[ -f "$DIST_AAB" ]]; then
GREEN='\033[0;32m'
NC='\033[0m'
dirPathLength=${#DIR}
bundleRelativePath=${DIST_AAB:dirPathLength}
echo -e "\n${GREEN}Signed bundle at${NC} .$bundleRelativePath.\n"
else
messageExit "Something went wrong during build/signing"
fi