**Updated to export Artboards as well as Layers with seperate scripts. Please download the latest version from GitHub**
I have recently been working on Android icons in Adobe Illustrator and quickly worked out manually exporting to mdpi, hdpi, xhdpi and xxhdpi is a lengthy process. Needless to say I wanted to remove this pain. Step in scripts to the rescue. After discovering Articmill’s script for iOS I decided to jump in and make my own for Android. I currently have a set of 23 icons which is exported to 92 PNG’s with one click!
What it does
- Exports Illustrator layers to mdpi, hdpi, xhdpi and xxhdpi PNG’s for Android
- Creates drawable-mdpi, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi folders ready to copy/paste into your Android project
- Only exports layers with ‘$’ special char so you can keep working layers in your document
- Only exports unlocked layers so you can pick and choose what gets exported each time you run the script
How to use it
Copy/paste the downloaded ExportAndroidResPNGs.jsx into your presets folder. On Windows and using Adobe Illustrator CC (64bit) the path is below. You will need to find the equivalent on your OS and Illustrator version.
C:\Program Files\Adobe\Adobe Illustrator CC (64 Bit)\Presets\en_US\Scripts
You can also use the File > Scripts > Other Script… menu to run it from any location. Great if you don’t have admin rights!
Your file should be set to the mdpi pixel dimensions (More info). In Android everything scales off this. For example, if you are making Actionbar icons then set your Illustrator Artboard to 32×32 pixels. The script will then take care of scaling up to 48×48, 64×64 and 96×96 to match the higher dpi images required. Please also note that this script will work for any Android image so long as you stick to the baseline mdpi pixel dimensions.
Setup your layers like in the screenshot below. Only unlocked layers with the ‘$’ special character will be exported.
Run the script
Run File > Scripts > ExportAndroidResPNGs from the menu. This will now start the script and you will layers being turned off and on as it goes down the layer tree. Once finished all layers will not be visible. The resolution folders are saved in the same folder as the AI file like below.
And in each folder you will have the saved PNG’s.
Hopefully this script helps you out as much as it has for me. Manually exporting PNG’s to different resolutions for Android should now be a thing of the past.