Skip to content

Instantly share code, notes, and snippets.

@michpohl
Last active September 18, 2024 19:51
Show Gist options
  • Save michpohl/b25395d1f616b8b6b1ce9bdbcc8cb666 to your computer and use it in GitHub Desktop.
Save michpohl/b25395d1f616b8b6b1ce9bdbcc8cb666 to your computer and use it in GitHub Desktop.
How to easily batch convert many .svg files to Android Vector Drawables

How to easily batch convert many .svg files to Android Vector Drawables

Note that Android Studio claims to also be able to batch-import files starting version 3.4. Depending on how well that works and what you like, this solution might still be preferrable (it is for me)

We will need two tools:

  1. Prior to conversion we want to optimize our .svg files using SVGO. SVG Optimizer is a Node.js-based tool for optimizing SVG vector graphics files. Find it here: https://www.npmjs.com/package/svgo

  2. For conversion we will use vd-tool, a command line tool built from the actual converter inside Android Studio, so we know it will just do the same conversions. Here is a link: https://www.androiddesignpatterns.com/2018/11/android-studio-svg-to-vector-cli.html

Preconditions: I suggest setting up three folders. One for your source files, the optimized ones and then the converted files. So that after each step, you can - if necessary - verify if the files still look like they are supposed to (Since these are command line tools you won't see anything when using them so precautions like this make sense).

  1. First we optimize our svgs by using $ svgo -f SOURCE-FOLDER -o OPTIMIZED-FOLDER

  2. When these look good (usually they do, don't worry), we continue by converting using vd-tool: $ ./vd-tool -c -in OPTIMIZED-FOLDER -out CONVERTED-FOLDER. That's it.

  3. Now we have converted files, we can just drag and drop them into Android Studio and in 99% of the cases there should be no rework necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment