How to convert multiple svgs to Android vector drawable in one shot

Ravi Bhojwani
2 min readDec 19, 2017

--

It becomes really cumbersome when you have to import multiple svgs in android studio. It’s a one by one process where you navigate to Project →New Vector Asset → Browse the svg (to be converted to vector drawable) → Rename if required →Next →Finish. Oops that’s really a big pain if you have to import multiple svgs.

I was working on rebranding of an app and had to import 150+ svgs and this was what made me think on finding a solution to avoid the O(n) solution and find O(1) for the same (though programatically it will be O(n), but yeah human effort will be O(1)).

I did find some online tools but there were little differences in generated xml’s.

This lead me to think and find the piece of code that converts svg’s to vector drawable xml in Android Studio. I found Svg2Vector class which parses svg and converts to vector drawable xml.

My end goal was to convert all svg files present under a particular folder, convert those in separate folder following similar folder structure with few customisable options for now like provide extension, extension suffix and destination folder path.

Source for the java project is available in github Svg2VectorAndroid

One can directly use the jar as below :

java -jar Svg2VectorAndroid-1.0.jar <SourceDirectoryPath>

Above command will generate the svgs in “ProcessedSvg” folder created under provided SourceDirectoryPath.

You can use Svg2VectorAndroid for basic stuff which is obviously conversion and do customisations on top of this as per need.

I currently have a need to change fillColor attribute in xml from hex value to color reference (Imagine manually changing over multiple places over 150+ files) i.e.

android:fillColor=”#FFFFFF”

should changed to

android:fillColor=”@color/app_theme_color”

Will work on the same and share if it interests you.

--

--