Last active
August 9, 2021 19:01
-
-
Save michpohl/c193f78fb8554cfae6c281244f87f7e9 to your computer and use it in GitHub Desktop.
Bash script to build vd-tool from Android sources to batch convert SVG to VectorDrawables via terminal
This file contains 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 | |
# inspiration for this script comes from here: https://www.androiddesignpatterns.com/2018/11/android-studio-svg-to-vector-cli.html | |
DESIRED_PATH="$1" | |
if [ -z "$1" ] | |
then | |
echo "No path provided.Please specify a path to clone the source files into." | |
echo -e "\nUsage: $ ./build_vdtool.sh [my-desired-path]\n" | |
echo "It is suggested to place these files outside of your app's source in order to not mess up the project files" | |
echo "Example: ./my-repo-files, to place it side by side with your app's folder" | |
exit 1 | |
fi | |
CURRENT_DIR=$(pwd) | |
echo "This script builds a fresh vd-tool executable. This takes a while. Go get a coffee or better, a few :-)" | |
echo "Creating vd-tool build resources in this path: $DESIRED_PATH" | |
# create folder | |
mkdir $DESIRED_PATH | |
cd $DESIRED_PATH | |
# if we find the initok file, we skip repo initialization, since it takes ages to finish | |
if test -f "$CURRENT_DIR/$DESIRED_PATH/initok"; then | |
echo "The repository is already initialized." | |
else | |
# install repo launcher | |
mkdir ~/bin | |
PATH=~/bin:$PATH | |
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo | |
chmod a+x ~/bin/repo | |
gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65 | |
curl https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ~/bin/repo | |
# init repo TODO this should match the Android studio version (version as input) | |
# find correct branch here: https://android.googlesource.com/platform/manifest/+refs | |
repo init -u https://android.googlesource.com/platform/manifest -b studio-4.0.0 --partial-clone | |
if [ $? -eq 0 ] | |
then | |
# creating a file as a marker that the initialization has been successful | |
touch "$CURRENT_DIR/$DESIRED_PATH/initok" | |
echo "Successfully initialized the repository" | |
else | |
echo "Repository initialization failed. Please try again." >&2 | |
fi | |
fi | |
# sync the repo | |
repo sync -j8 -c | |
# build the tool | |
cd ./tools/base | |
../gradlew publishLocal | |
echo -e "\nTool successfully compiled" | |
# copy the tool | |
TOOL="$CURRENT_DIR/$DESIRED_PATH/out/build/base/vector-drawable-tool/build/distributions/vd-tool.zip" | |
mkdir "$CURRENT_DIR/$DESIRED_PATH" | |
# unzip in the desired folder with forced overwrite | |
unzip "$TOOL" -d "$CURRENT_DIR/$DESIRED_PATH" | |
if [ $? -eq 0 ] | |
then | |
echo -e "\nNew tool has been built and unzipped and can be used now" | |
echo "It can be found here: $CURRENT_DIR/$DESIRED_PATH/bin" | |
exit 0 | |
else | |
echo "Something went wrong. Tool unzipping failed" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment