Skip to content

Instantly share code, notes, and snippets.

@hamidzr
Last active March 11, 2019 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamidzr/df5f26b52575c908dd806d41482dd3a4 to your computer and use it in GitHub Desktop.
Save hamidzr/df5f26b52575c908dd806d41482dd3a4 to your computer and use it in GitHub Desktop.
a utility script to help create signed and aligned APKs ready for publishing on app stores.
#!/bin/bash
# usage: scriptname keystore_path key_alias
keystore=$1
alias=$2
version=$(cat config.xml| grep widget | grep -Eo 'version="(.{2,6})"' | grep -Eo '".*"' | sed 's/"//g')
app_name=roboscape
apk_dir=platforms/android/app/build/outputs/apk/release
final_name="$app_name-release-$version.apk"
unsigned_name="$app_name-release-unsigned-$version.apk"
# check if args are passed in
if [ -z "$alias" ]; then
echo pass in keystore and alias
exit 1
fi
set -e
function safe_deletion() {
echo version $version already exists. Do you wanna overwrite it?
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -i $apk_dir/$final_name
else
exit 1
fi
}
function check_version() {
echo "You are about to publish version $version (major, minor, patch)"
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ok
else
echo bump the version in config.xml
exit 1
fi
}
check_version
[ -f $apk_dir/$final_name ] && safe_deletion
cordova build android --prod --release
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $keystore $apk_dir/app-release-unsigned.apk $alias
zipalign -v 4 $apk_dir/app-release-unsigned.apk $apk_dir/app-release.apk
mv $apk_dir/app-release.apk $apk_dir/$final_name
# keep notes
notes_file=$apk_dir/$version-notes.txt
echo "#############=====###########" > $notes_file
git log > $notes_file
echo "#############" > $notes_file
git status > $notes_file
echo published $app_name $version to $apk_dir/$final_name
@hamidzr
Copy link
Author

hamidzr commented Mar 11, 2019

requires zipalign software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment