1
0
Fork 0
android-builder/release

67 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/sh
set -e
2018-09-23 09:56:49 +08:00
BUILT_APK=none
ALIGNED_APK=app/build/outputs/apk/release/app-release-unsigned-aligned.apk
SIGNED_APK=app/build/outputs/apk/release/app-release.apk
# Ensure directory exists
mkdir -p app/build/outputs/apk/release/
2018-09-21 11:38:43 +08:00
TEMP_DIR="$(mktemp -d)"
TEMP_STORE_FILE="$TEMP_DIR/store.jks"
2018-09-21 12:17:12 +08:00
if [ -z "$STORE_FILE" ] || [ -z "$STORE_PASSWORD" ] || [ -z "$KEY_ALIAS" ]; then
echo "STORE_FILE, STORE_PASSWORD or KEY_ALIAS are not configured secrets. Aborting..."
exit 1
fi
echo
2018-09-21 11:40:13 +08:00
echo "Reading STORE_FILE from environment"
echo $STORE_FILE | xxd -ps -r > $TEMP_STORE_FILE
# The following file is not required for the following process
# but I'm gonna leave it here anyway
echo > keystore.properties << EOF
storeFile=$TEMP_STORE_FILE
2018-09-21 11:40:13 +08:00
storePassword=$STORE_PASSWORD
2018-09-21 12:17:12 +08:00
keyAlias=$KEY_ALIAS
EOF
echo
echo "I think you're lazy so we will build a unsigned release APK and then sign it manually,"
2018-09-21 15:52:43 +08:00
echo "rather than using the gradle process."
echo
echo "Building unsigned release APK"
set -x
./gradlew assembleRelease
set +x
2018-11-10 16:12:05 +08:00
BUILT_APK=$(find . -name "*.apk" -path "*release*")
2018-09-23 09:56:49 +08:00
echo
echo "Doing zipalign"
set -x
zipalign -v -p 4 $BUILT_APK $ALIGNED_APK
set +x
echo
echo "Signing"
set -x
apksigner sign \
--ks $TEMP_STORE_FILE \
2018-09-21 11:40:13 +08:00
--ks-pass pass:$STORE_PASSWORD \
2018-09-21 12:17:12 +08:00
--ks-key-alias $KEY_ALIAS \
--out $SIGNED_APK \
$ALIGNED_APK
set +x
echo
echo "Verifying"
set -x
apksigner verify $SIGNED_APK
set +x
echo "Done!"