Created
January 5, 2023 14:02
-
-
Save sjehutch/ed42049ed09dab480042716b5344bec4 to your computer and use it in GitHub Desktop.
android-icons.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the required tools are installed | |
if ! [ -x "$(command -v convert)" ]; then | |
echo "Error: convert tool is not installed." >&2 | |
exit 1 | |
fi | |
if ! [ -x "$(command -v androidsdkmanager)" ]; then | |
echo "Error: Android SDK Manager is not installed." >&2 | |
exit 1 | |
fi | |
# Set the name of the icon file | |
icon_file_name="my_icon.png" | |
# Set the path to the source image | |
source_image_path="path/to/source/image.png" | |
# Set the path to the Android SDK | |
android_sdk_path="path/to/android/sdk" | |
# Set the Android project's package name | |
package_name="com.example.myapp" | |
# Set the Android project's module name | |
module_name="app" | |
# Set the Android project's resource directory path | |
resource_dir_path="$module_name/src/main/res" | |
# Set the density-specific directories | |
drawable_ldpi_dir="$resource_dir_path/drawable-ldpi" | |
drawable_mdpi_dir="$resource_dir_path/drawable-mdpi" | |
drawable_hdpi_dir="$resource_dir_path/drawable-hdpi" | |
drawable_xhdpi_dir="$resource_dir_path/drawable-xhdpi" | |
drawable_xxhdpi_dir="$resource_dir_path/drawable-xxhdpi" | |
drawable_xxxhdpi_dir="$resource_dir_path/drawable-xxxhdpi" | |
# Create the density-specific directories | |
mkdir -p "$drawable_ldpi_dir" | |
mkdir -p "$drawable_mdpi_dir" | |
mkdir -p "$drawable_hdpi_dir" | |
mkdir -p "$drawable_xhdpi_dir" | |
mkdir -p "$drawable_xxhdpi_dir" | |
mkdir -p "$drawable_xxxhdpi_dir" | |
# Convert the source image to the required densities and copy them to the density-specific directories | |
convert "$source_image_path" -resize 36x36 "$drawable_ldpi_dir/$icon_file_name" | |
convert "$source_image_path" -resize 48x48 "$drawable_mdpi_dir/$icon_file_name" | |
convert "$source_image_path" -resize 72x72 "$drawable_hdpi_dir/$icon_file_name" | |
convert "$source_image_path" -resize 96x96 "$drawable_xhdpi_dir/$icon_file_name" | |
convert "$source_image_path" -resize 144x144 "$drawable_xxhdpi_dir/$icon_file_name" | |
convert "$source_image_path" -resize 192x192 "$drawable_xxxhdpi_dir/$icon_file_name" | |
# Update the app's manifest file to use the new icon | |
sed -i '' "s/android:icon=\".*\"/android:icon=\"@drawable\/$icon_file_name\"/g" "$resource_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment