Ove Stoerholt
Ove Stoerholt

Reputation: 3974

Android Studio 3.0 vector drawables and LINT tools:ignore="VectorPath"

After upgrading to 3.0 Android Studio has started to complain about long paths in vector drawables.

The warning says:

Very long vector path (7958 characters), which is bad for performance. Considering reducing precision, removing minor details or rasterizing vector. less... (⌘F1) Using long vector paths is bad for performance. There are several ways to make the pathData shorter: * Using less precision * Removing some minor details * Using the Android Studio vector conversion tool * Rasterizing the image (converting to PNG)

The documentation https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html shows us how to use vector drawables in our apps, and recommends it over png's etc.

I have both been using the Android Studio Vector Conversion Tool and this excellent service for converting SVG's to vector drawables: http://inloop.github.io/svg2android/

Are there other services that does more to reduce vector drawable complexity? Where can I find guidelines on how 'advanced' my vector drawables can be?

Upvotes: 30

Views: 15930

Answers (5)

Shiroyasha
Shiroyasha

Reputation: 31

This may not be an ideal solution, but Initially I had drawn the vector asset in a single shot as a single object, this resulted in longer <path> problem. I started from scratch again and this time I split my object into many parts i.e. I drew each part of my single object individually and later I grouped them together (I used Inkscape). As a result, when .svg converts to .xml the single <path> tag gets split into multiple shorter <path> tags.

Upvotes: 3

epic
epic

Reputation: 1443

My path was around 1800 and i used svg-path-editor to lower to around 1000. Still showed the warning but quite close to the max 800

I am sure there is a better way to use this tool but i just copied the pathData from android studio xml to the Path box, pressed Round and got the result back to the xml

If your path is more than 2000, consider converting to png (with mdpi, hdpi, xhdpi...)

enter image description here

Upvotes: 13

Levon Petrosyan
Levon Petrosyan

Reputation: 9625

Try to use this tool by decreasing Precision.

Upvotes: 7

Alex Lockwood
Alex Lockwood

Reputation: 83303

Try optimizing the vector drawable using avocado! It should help reduce the complexity of your paths.

Upvotes: 31

marianosimone
marianosimone

Reputation: 3606

There's an extra step you can add before using svg2android, which is running it through svgo

An example pipeline that I use looks like (note that instead of the web tool, I'm using svg2vectordrawable)

~$ svgo image.svg --config=config -o image.svg.optimized
~$ s2v "image.svg.optimized image.xml

My config file looks like (you can play around with it to match your needs):

"plugins": [
    {
        "convertPathData": {
            "leadingZero": false,
            "floatPrecision": 2
         }
    }
]

Upvotes: 8

Related Questions