Vector Drawable Optimization

Android

Raster PNG icons shipped at multiple density variants instead of vector drawables. A single vector XML file replaces 5-6 density-specific PNGs, saving 70%+ per icon set.

Vector drawables (VectorDrawable) are XML-based vector graphics that describe images using path data, fills, and strokes rather than pixel grids. Unlike raster images, a single vector drawable file scales to any screen density without quality loss, eliminating the need to provide separate assets for mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi. A typical raster icon set requires 5-6 density variants; a vector drawable replaces all of them with a single small XML file. VectorDrawableCompat in AndroidX provides backward compatibility to API 7.


Why this happens

  • Legacy raster icon sets: Projects created before vector drawable support often ship full density sets of PNG icons.

  • Designer workflow: Designers deliver assets as PNG exports. Without a conversion step, these ship directly into the APK.

  • Complex illustrations as vectors: Developers sometimes convert complex artwork to vectors, resulting in oversized XML files that perform poorly.

  • Missing backward compatibility setup: Without VectorDrawableCompat configuration, developers fall back to generating raster PNGs from vectors at build time, negating the size benefit.


Size impact

Vector drawables eliminate multi-density raster duplication and are ideal for icons, simple illustrations, and UI elements.

Google I/O app

482 KB savings from vector icons

Per-icon typical

Vector is ~30% the size of raster set

Density multiplication

One 800-byte vector replaces ~9 KB of multi-density PNGs


How we detect it

Scans res/drawable-* directories for PNG files that could be replaced with vectors. Lint inspection "VectorPath" warns about overly complex vector paths. Icons that exist as multi-density PNGs are conversion candidates.


How to fix

1

Enable VectorDrawableCompat support

This tells Gradle to not auto-generate raster PNGs from vectors, keeping only the small XML file.

build.gradle.kts (app module)

android { defaultConfig { vectorDrawables.useSupportLibrary = true } }

2

Import SVG as vector drawable

In Android Studio: File > New > Vector Asset > Local File (SVG). The Asset Studio converts SVG to VectorDrawable XML format.

3

Use app:srcCompat for backward compatibility

Use AppCompat's srcCompat attribute instead of android:src to ensure vectors load correctly on all API levels.

Layout XML

<ImageView android:layout_width="24dp" android:layout_height="24dp" app:srcCompat="@drawable/ic_settings" />

4

Optimize vector XML with avocado

Use the open-source avocado tool to remove unnecessary attributes and simplify path data without visual changes.

# Install avocado npm install -g avocado # Optimize a vector drawable avocado res/drawable/ic_complex.xml

Important: Vector drawables are significantly slower to render than PNGs (~16.6 ms vs ~0.18 ms). Limit vectors to 200x200 dp maximum. Do NOT use vectors for photographs, complex illustrations with many gradients, or images with thousands of paths. Setting vectorDrawables.useSupportLibrary = true disables automatic PNG generation, so you MUST use app:srcCompat in XML and AppCompatResources.getDrawable() in code.


Powered by Bitrise, trusted by 8,500+ brands

Size Analyzer is built by Bitrise, the leading mobile DevOps platform used by over 400,000 developers at companies like Shopify, TripAdvisor, and BuzzFeed. Free forever. No signup required.

Bitrise provides a full-stack mobile DevOps solution that unites the tools, processes, and testing frameworks engineering teams need to ship best-in-class mobile experiences.

Bitrise logo