How to use Android Studio's SVG-to-VectorDrawable converter from the command line


Since the very beginning, one of the most annoying aspects of using VectorDrawables on Android has been the lack of a reliable SVG converter. Google has recently made huge strides towards improving Android Studio’s SVG-to-VectorDrawable tool in order to improve this experience.

However, there has always been one major issue for me: the tool doesn’t support batch conversion of SVGs and can’t be invoked from the command line. Working at Lyft, it’s not uncommon for me to need to convert hundreds of SVGs into VectorDrawables at a time. Having to go through Android Studio’s GUI in order to convert each SVG one-by-one is simply not realistic.

Well, this weekend my good buddy Nick Butcher taught me how to build the tool as a binary that can be executed from the command line, and I’m so excited about it that I had to share it with the world! :)

Where can I download it?

I anticipate many won’t want to go through the trouble of building these binaries from scratch, so I built them myself and hosted them on Google Drive here.

How do I run it?

The following command will convert all SVGs in a directory called svgs/, convert them all into VectorDrawables, and write them to a directory called vectors/. Note that both directories must exist beforehand.

./vd-tool -c -in svgs/ -out vectors/

How do I build it?

In case you want to build these yourself, here’s how I did it.

First, follow the Downloading the Source guide to install and set up the repo tool, but instead of running the listed repo commands to initialize the repository, run the folowing:

repo init -u -b <most-recent-android-studio-branch>

At the time of this writing, the most recent Android Studio branch was studio-3.2.1. This will obviously change over time as newer versions of Android Studio are released.

Now that your repository is set to pull only what you need for building and running the tool, download the code using the following command (you might want to grab a coffee or something too, as this command might take a while to complete):

repo sync -j8 -c

Finally, execute the following to build the binaries:

cd ./tools/base
../gradlew publishLocal

Once it completes, you should find the binaries in a <root>/out/build/base/vector-drawable-tool/build/distributions/ file. Unzip it and it will extract a /bin directory that contains binaries compatible with Mac OS X, Linux, and Windows.

How do I report bugs?

Now for the most important part of this blog post…

Please, please, please file bugs if you discover SVGs that don’t convert properly! File the bugs in the Android Studio public issue tracker. Here’s an example bug I recently reported if you need a template to go by.

My goal is to make the Android Studio converter the most reliable SVG-to-VectorDrawable converter out there. So if and when you file a bug, feel free to hit me up on Twitter with a link to the report and I’ll do my best to ensure the bug is fixed as quickly as possible!

Happy converting!

+1 this blog!

Android Design Patterns is a website for developers who wish to better understand the Android application framework. The tutorials here emphasize proper code design and project maintainability.

Find a typo?

Submit a pull request! The code powering this site is open-source and available on GitHub. Corrections are appreciated and encouraged! Click here for instructions.

Apps by me

Shape Shifter simplifies the creation of AnimatedVectorDrawable path morphing animations. View on GitHub.
2048++ is hands down the cleanest, sleekest, most responsive 2048 app for Android!