1min read

Handling vector assets on Android

Our daily work involves a lot of interaction between designers and developers. Since introducing changes to assets in an Android project was quite time-consuming, we decided to optimize the flow.

The biggest advantage of vector assets over raster ones is that we need only one vector image for all screen densities. One resource for all densities means less work for

  • UI designers - as they don’t have to convert vector assets to raster ones and scale them to desired densities
  • developers - they avoid replacing many existing assets with new ones, for example in case when design of the app has changed

On the other hand, Android components (in API 20 and below) require raster resources to be provided. Furthermore, for each density we support in our application, we should provide a separate file to avoid scaling.

Android Studio 1.4 has introduced several new features. One of them is vector assets support. Although vector assets support is a life-saver, it was introduced recently and still is in beta. For this reason we are using another solution - Android SVG Drawable plugin.

It is an open source Gradle plugin, that generates PNG(raster) files from SVG(vector) resources during build process. All you need to do in order to integrate it is following:

  • adding a plugin to build.gradle file
  • configure input and output directory
  • define set of desired densities and to add SVG files themselves It might be a good idea to choose generation output directory, which is ignored by version control, e.g. build/generated.

We may use raster images in XML files directly, exactly the same as if they were created manually and added to the project.

Wojtek Piwoński

Senior Software Engineer

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!