Skip to content

Instantly share code, notes, and snippets.

@mochadwi
Last active October 8, 2020 06:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mochadwi/e86546b66f2730d019bd1ae4f533b0c4 to your computer and use it in GitHub Desktop.
Save mochadwi/e86546b66f2730d019bd1ae4f533b0c4 to your computer and use it in GitHub Desktop.
(DEPRECATED) Extracting or Installing an AAB to APK.

DISCLAIMER, in Google Play Console you can download Universal APK directly. No need to use this extracting from AAB to APK method

Download Universal APK from AAB

Please make sure to run this script with your .aab file in the same folder.

The script has the following placeholders, which should be replaced for your specific environment/application:

  • $PASSWORD, $KEYSTORE_FILE, $ALIAS are the details used to sign the .aab in Android Studio
  • $PATH_TO_BUNDLE_TOOL is the path of the bundletool e.g. ~/Downloads/bundletool-all-0.8.0.jar
  • Download bundletool using homebrew: brew install bundletool, then check for the bundletool jar
  • brew info bundletool, see e.g: cd /usr/local/Cellar/bundletool/0.11.0
  • ls -al libexec/bundletool-all-0.11.0.jar *please make sure to check the correct path

Fixed + Updated version from this the original version doesn't supported on zsh terminal (i guess) due to using {ENV_VARIABLE_NAME} enclosing tag, without dollar-sign ${ENV_VARIABLE_NAME}

This script able to run to device (optional 2nd argument) or just want to extract from AAB to APK/APKs

Run this curl -s -L https://git.io/JedUF | bash -s [e.g: release-name]

#!/usr/bin/env bash
set -e
# convert default .aab file to other products
# - apks to install in device directly
# - universal apk to install in device
if [ "$#" -lt 1 ]; then
echo "Illegal number of parameters - required"
echo "1. name"
echo "(optional) 2. device (from adb devices)"
exit
fi
default_name=app
target_name=$1
folder=release
mode=universal
apk_container=apk_container
default_aab=$folder/$default_name.aab
default_apks=$folder/$default_name.apks
default_apk=$folder/$apk_container/$mode.apk
target_aab=$folder/$target_name.aab
target_apks=$folder/$target_name.apks
target_apk=$folder/$apk_container/$target_name.apk
password=$PASSWORD
keystore=$KEYSTORE_FILE
alias=$ALIAS
if [ -f "$(basename *.aab)" ]; then
mkdir $folder
mv "$(basename *.aab)" $default_aab
else
echo "please make sure to check your .aab file in the current directory, then run this script"
exit
fi
if [ -f $default_aab ]; then
java -jar $PATH_TO_BUNDLE_TOOL build-apks --overwrite --mode=$mode --bundle=$default_aab --output=$default_apks --ks=$keystore --ks-pass=pass:$password --ks-key-alias=$alias --key-pass=pass:$password
else
echo "cannot find $default_aab"
exit
fi
if [ -f $default_apks ]; then
unzip $default_apks -d $folder/$apk_container
else
echo "cannot find $default_apks"
exit
fi
if [ ! -f $target_aab ] && [ -f $default_aab ]; then
mv -f $default_aab $target_aab
else
echo "cannot find $default_aab or target $target_aab already exists"
exit
fi
if [ ! -f $target_apks ] && [ -f $default_apks ]; then
mv -f $default_apks $target_apks
fi
if [ ! -f $target_apk ] && [ -f $default_apk ]; then
mv -f $default_apk $target_apk
fi
if [ "$#" -eq 2 ] && [ -f $target_apks ]; then
device=$2
java -jar $PATH_TO_BUNDLE_TOOL install-apks --apks=$target_apks --device-id=$device
fi
zip -er $folder/$target_name.zip $folder/$apk_container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment