This Android lifehack can save a lot of time for developers around the globe! Originally was published in Stanfy Blog: https://stanfy.com/blog/how-to-get-rid-of-drawable-xdpi-folders-in-your-android-project-using-vector-assets-for-drawables
Mobile Application Development-Android and It’s Tools
How to get rid of drawable [x]dpi folders in your android project – using vector assets for drawables
1. How to Get Rid of Drawable-[x]dpi Folders in Your
Android Project – Using Vector Assets for
Drawables
By Nikolay Soroka, Android Engineer at Stanfy.
2. In Android app development, it’s a good
practice to support multiple screens. And
even if you’re making an app only for
smartphones and only for a portrait mode,
you have to deal with different screen
densities.
So, you open your design file in Photoshop or
Sketch, and start extracting assets, adding all
those multipliers for mdpi, hdpi, xhdpi, xxhdpi
and now also xxxhdpi (!) device density.
It’s a dull and tedious process. App
developers and designers even have
created scripts and plugins for that.
4. But I will share with you a few hacks on how to make this easier!
Here is what you need:
•Android Studio 1.4
•Android Gradle plugin 1.5.0
5. Open your design files and export your assets in .svg
format. Now in Android Studio right click on res folder
→ new → Vector Asset. This will open Vector Asset
Studio and you can select one of the default material
icons, in case you need one, or you can import your
svg file.
A hint: if Android Vector Studio says there is an error
importing your file, no worries, there is a plenty of
online resources to help you with vector drawables. Or
you can your open svg file and copy pathData into your
vector drawable.
That’s it! Now you have only one resource for each
asset.
6. In reality though, vector drawables are supported only on Android 5.0, api
level 21, so what happens is that gradle plugin renders all that drawables
for different densities to package them into resulting .apk file to be
displayed on older versions.
Much faster and simpler, right??
7. Thanks! Hope this slides were useful!
If yes, please share it J
By Nikolay Soroka, Android Engineer at Stanfy.