Reputation: 3974
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
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
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...)
Upvotes: 13
Reputation: 83303
Try optimizing the vector drawable using avocado
! It should help reduce the complexity of your paths.
Upvotes: 31
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