Tech Blog

Android

Optimize Vector Drawable Path

By Bvmg karthik2 min read
← Back to blog

Vector Drawables are supported from API level 21 in Android and it was introduced to improve the performance by reducing image rendering time and the APK size but if we use them incorrectly it can affect the performance of the application because the drawing can take a long time if the path length is too long.

For Example in the case of the below image, it has a very long vector path (1334 characters) but the suggested length is 800 characters.

To reduce the path length we have some amazing tools and the first one will be avocado. It will optimize your vector drawable XML files and it is a Node.js app so we can install it using the below command.
npm install -g avocado
Run the below command to optimize the path
avocado "E:\Vector test\vector_original_avocado.xml"






Now if we check the size it is reduced to (1027 characters) but in our case, it is still high. Most of the time avocado tool can optimize enough but if we need to optimize more then the only way is to first optimize our SVG path.

To optimize the SVG path we can use another tool svgomg. Here, we can open our SVG file and change the precision to 1. For the above image, It reduced the file size to 40%. If anyone doesn’t have the SVG file use shapeshifter to convert Vector to SVG.

We can import this SVG file by right click on the drawable folder and go to New -> Vector Asset and select SVG file.
Now run avocado to optimize the path on it, which seemed to solve the problem. This process helps to optimize the path to (769 characters) without compromising the appearance. For some detailed or complex images, it is not possible to optimize the path below the range so better use the WebP images instead of the vector drawables.

Keep reading

You may be interested in

Browse all articles →
Android Download file with Data URL
July 23, 20241 min read

Android Download file with Data URL

What is a Data URL? Data URLs are the type of URL scheme that is used to embed usually small types of files. In this URL, inline files are prefixed with the data: MIME type. data:[<mediatype>][;base64],<data> To download files having Data URLs inside Android: Firstly, we need to get an extension of the file from […]

By Bansari PanditRead More →
Download the file with blob URL in Android WebView
July 23, 20242 min read

Download the file with blob URL in Android WebView

What is the Blob URL? Blob URLs can only be generated by the browser with use of internal mapping and used within the current document while it’s open which means it is valid for the same session (ie. the life of the page/document). The blob URL looks like this: blob:http://example.com/550e8400-e29b-41d4-a716-446655440000 Below is the sample HTML […]

By Bansari PanditRead More →
Key Terminologies in Android Enterprise
December 20, 20227 min read

Key Terminologies in Android Enterprise

Android Enterprise is a Google-led initiative to enable the use of Android devices and applications in a workspace. This program offers APIs and tools for developers to integrate support of Android devices into the EMM (enterprise mobility management) or UEM (Unified Endpoint Management) solutions. The following are the key terms associated with Android Enterprise. This […]

By Sandeep KadamRead More →