Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 870
Ove Stoerholt Avatar asked Nov 06 '17 09:11

Ove Stoerholt


People also ask

Is SVG compatible with Android?

Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.

What is vector Drawables in Android?

A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.

How do I use SVG files on Android?

If you want to use some icons that are not present in the list of predefined icons, then you can add your own icon by selecting the Asset Type as Local File(SVG, PSD) and then select the path of your file by clicking on Path. After that click on Next > Finish. Now your icon will be added to your res/drawable folder.


3 Answers

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

like image 192
Alex Lockwood Avatar answered Oct 18 '22 16:10

Alex Lockwood


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

like image 11
epic Avatar answered Oct 18 '22 17:10

epic


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
         }
    }
]
like image 8
marianosimone Avatar answered Oct 18 '22 17:10

marianosimone