As an Android developer, we are faced with so many technical stuff while building an awesome application in terms of less APK size. So all the technical stuck is actually part of developer life. In this tutorial, I am trying to explain about the vector drawable which is the frequently used in android application development.
In Android, a vector file is an XML file in the format of binary which works well in all android screen size device. We need to store the vector file inside the drawable folder to reflect in the user interface. But the problem comes here when your client has provided the SVG or PSD file format for image and icon for your android application.
Generally, an android studio is not supported the SVG and PSD file to keep in your drawable folder to load an icon or image. In that case, we need to convert the SVG and PSD file into either PNG file or Vector Drawables file. But the question is how to convert into vector Drawable file?
We can convert the SVG and PSD file in many ways. Either you can use the online website to convert. But we need to make much better way then I would be recommended two different methods to convert into vector drawable file.
Ok, Let’s explore by the first method to convert the SVG or PSD file into vector Drawable file.
Android Studio has an option to convert the SVG file into vector formate. You need to right click on the drawable folder of your android studio project and click the new option and then select the Vector Asset. For your reference, I am giving the snapshot below.
Please select the SVG file from the directory path and convert.
That’s great. Now let’s see the use the second option by convert by using the command. It is a little bit difficult but good to explore the code which is provided by the Android framework.
Before we explore the android framework base code, we can use the exiting tools to use for conversion. And I am really thankful to Nick Butcher. He has provided and shared SVG to vector drawable tool into zip format into Google Drive. What you need to just download the file and unzip it and run the below command.
The following command will convert all SVGs in a directory called svgs/
, convert them all into VectorDrawable
s, and write them to a directory called vectors/
. Note that both directories must exist beforehand.
./vd-tool -c -in svgs/ -out vectors/
That’s was great. Now question that how to get the tools from the Android repository and build it? So I would say do not worry we will sync the android repository to use the framework tool to run and execute the code.
To download the Android open source code you need to first install the repo and git version control in your system. Once you have done the steps now you can use below git command to initialize the repo and sync.
repo init -u https://android.googlesource.com/platform/manifest
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
repo sync
repo sync -j8
cd ./tools/base
../gradlew publishLocal
<root>/out/build/base/vector-drawable-tool/build/distributions/vd-tool.zip
file. Unzip it and it will extract a /bin
directory that contains binaries compatible with Mac OS X, Linux, and Windows.Now we have a good understanding about to convert the SVG and PSD file into png or vector drawable file formate by using the android studio or by using tools provided by the Android framework.
If you are wondering to learn Android then Please Learn from Android category and wondering to lean Kotlin then Kotlin Category will help you. If you want to learn all the python article, then learn from the python category.
Please do subscribe your email to get the newsletter on this blog on below and if you like this post then do not forget to share like and comment on the below section.
Happy Coding
I am a very enthusiastic Android developer to build solid Android apps. I have a keen interest in developing for Android and have published apps to the Google Play Store. I always open to learning new technologies. For any help drop us a line anytime at contact@mobologicplus.com
Hi everyone, In this article, we are going to learn how to hide the production… Read More
Hello everyone, Today in this article, we are going to learn about localisation to support… Read More
Hello everyone, In this article, we are going to learn something to handle the callback… Read More
In this article, we are learning about the run time permissions for request permission launchers.… Read More
Hello everyone. In my last tutorial, we learned about the Jetpack Compose introduction and about applying the… Read More
Hello everyone, In this article, we are going to learn about the Jetpack Compose with… Read More