Skip to content

Instantly share code, notes, and snippets.

@Dirk-Sandberg
Last active May 9, 2020 00:19
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 Dirk-Sandberg/216da4f89eb8a9e21c743c13df158848 to your computer and use it in GitHub Desktop.
Save Dirk-Sandberg/216da4f89eb8a9e21c743c13df158848 to your computer and use it in GitHub Desktop.
Automates generating keys and building release apks with buildozer
#!/bin/bash
KEYNAME=$1
KEYPASS=$2
function generate_keys() {
# Make keystores directory if it doesn't exist
if [ ! -d ~/keystores ]; then
mkdir ~/keystores
fi
# Make keystore file if it doesn't exist
if [ ! -f ~/keystores/${KEYNAME}.keystore ]; then
keytool -genkey -keystore ~/keystores/${KEYNAME}.keystore -alias ${KEYNAME}-keystore -storepass ${KEYPASS} -keyalg RSA -keysize 2048 -validity 10000
keytool -importkeystore -srckeystore ~/keystores/${KEYNAME}.keystore -destkeystore ~/keystores/${KEYNAME}.keystore -deststoretype pkcs12 -storepass ${KEYPASS}
echo "Finished generating keystore!"
fi
}
function set_env_var() {
export P4A_RELEASE_KEYSTORE=~/keystores/${KEYNAME}.keystore
export P4A_RELEASE_KEYSTORE_PASSWD=${KEYPASS}
export P4A_RELEASE_KEYALIAS_PASSWD=${KEYPASS}
export P4A_RELEASE_KEYALIAS=${KEYNAME}-keystore
echo "Finished exporting env variables!"
}
function change_buildozer_arm() {
# Get script to help edit buildozer.spec
if [ ! -d a2346014a77e86733956e618aff44dbe ]; then
git clone https://gist.github.com/Dirk-Sandberg/a2346014a77e86733956e618aff44dbe.git
else
git -C a2346014a77e86733956e618aff44dbe pull
fi
cp a2346014a77e86733956e618aff44dbe/update_buildozer_spec.py ./
# Set min target API and the arch to 64 bit (arm64-v8a)
python3 update_buildozer_spec.py arm64-v8a
buildozer android release
# Set the arch to 32 bit (armeabi-v7a)
python3 update_buildozer_spec.py armeabi-v7a
buildozer android release
# Clean up temp files
rm update_buildozer_spec.py
sudo rm -r a2346014a77e86733956e618aff44dbe
}
function echo_finished() {
echo "> FINISHED BUILDING RELEASE APKs"
echo "> TWO APKs BUILT"
echo "> files are under the /bin folder"
echo "> Go to https://play.google.com/apps/publish to start the upload process"
echo "> Make sure you upload the 64 bit apk before the 32 bit apk. The order is important."
}
function print_usage() {
echo "Usage: ${0} <keyname> <keypassword>"
}
function do_all() {
if [ -z ${KEYPASS} ]; then
print_usage
return 1
fi
if [ -z ${KEYNAME} ]; then
print_usage
return 1
fi
generate_keys
set_env_var
change_buildozer_arm
echo_finished
}
do_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment