Skip to content

Instantly share code, notes, and snippets.

@abeldantas
Created October 26, 2023 15:22
Show Gist options
  • Save abeldantas/8d1f923a65ca542d087246e80c34e716 to your computer and use it in GitHub Desktop.
Save abeldantas/8d1f923a65ca542d087246e80c34e716 to your computer and use it in GitHub Desktop.
AAB Processing Script for Android Development
#!/bin/bash
# Usage: ./script.sh [file1.aab file2.aab ...]
# If no arguments are provided, the script will find and process all .aab files in the current directory.
# The script performs the following steps for each .aab file:
# 1. Builds an .apks file using bundletool.
# 2. Deletes the original .aab file.
# 3. Renames the .apks to .zip.
# 4. Decompresses the .zip into a new directory.
# 5. Deletes the .zip file.
# 6. Executes a `tree -L 2 -h` command in the new directory.
#
# Note: This script assumes that 'bundletool' is installed. If it's not, download it from:
# https://github.com/google/bundletool/releases
process_aab() {
file="$1"
# Build the .apks file
output_name="${file%.aab}.apks"
bundletool build-apks --bundle="$file" --output="$output_name"
# Delete the original .aab file
rm "$file"
# Rename the .apks to .zip
zip_name="${output_name%.apks}.zip"
mv "$output_name" "$zip_name"
# Create and decompress into new directory
dir_name="${file%.aab}"
mkdir "$dir_name"
unzip "$zip_name" -d "$dir_name"
# Delete the .zip file
rm "$zip_name"
# Execute the tree command in the new directory
tree -L 2 -h "$dir_name"
}
if [ "$#" -eq 0 ]; then
# If no arguments, find .aab files in current directory
for file in *.aab; do
if [ -e "$file" ]; then
process_aab "$file"
fi
done
else
# If arguments, process each as an .aab file
for file in "$@"; do
if [[ "$file" == *.aab ]]; then
process_aab "$file"
else
echo "Ignoring $file as it's not an .aab file."
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment