Vector drawables that are automatically converted to pngs

Taig picture Taig · Jun 13, 2015 · Viewed 10.3k times · Source

At Google IO, the Tools team briefly showed the possibility to define vector drawables with a specific suffix (e.g. ic_heart_48px.xml) that will then be converted to pngs of all necessary densities. Unfortunately I don't find any documentation about this feature besides the IO recordings.

Is this a feature of the Build Tools or of Android Studio? Assuming it's part of the Build Tools, is it available already? Which version should I be using? Do I have to enable the feature explicitly?

Does Google provide its material icons in the Android xml vector format?

Answer

Sandro Machado picture Sandro Machado · Oct 1, 2015

With Android Studio 1.4 and Gradle Android plugin to 1.4.0-beta3 (or higher) it is only necessary to right-clicking the res/drawable folder in your project and selecting New → Vector Asset from the content menu.

enter image description here

It is possible to read on the release notes of the version 1.4 that this tools also offers backwards compatibility.

We are also excited to offer backwards compatibility for your vector assets in Android Studio 1.4. Once you have a vectorDrawable image in your res/drawable, the Gradle plugin will automatically generate raster PNG images for API level 20 and below during build time. This means you only need to update and maintain your vector asset for your app project and Android Studio can take care of image conversion process. Note, it is still best practice to create density dependent launcher icons in your res/mipmap folder.

Note that the svg format is not fully supported yet. Some features may be missing.

Read the full blog post about this feature and see the video here: http://android-developers.blogspot.pt/2015/09/android-studio-14.html