Issue
Situation: I got SVG files from a Designer.
Icon Fonts are not easy to use in standard Android components.
So i need drawables for all my supported sizes
Everything should be automated through Gradle.
Used:
I found and used this nice plugin https://github.com/eowise/gradle-imagemagick
Unfortunately it doesn't worked out of the box. I allways got "No such file or directory" from gradle. It is unable to find the ImageMagick convert tool which is used by the plugin.
Straight from the shell without gradle the generated call for convert is working.
Solution
Finally i fixed it for me and i will write it down to give a short cut for this.
Installation: execute from the shell
- brew update
- brew install imageMagick
- brew install librsvg
Setup:
Setting the PATH variable doesn't worked for me. I had to write the installation path of the imageMagick convert tool to /etc/launchd.conf I found the info here: [https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x][1]
again shell:
- sudo touch /etc/launchd.conf
- sudo nano /etc/launchd.conf
add this line:
- setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
You can check where convert is installed. Type "which convert" in a shell. For now it was /usr/local/bin
After saving modified laundchd.conf.
RESTART
Configuration of Gradle:
Add the following snippet to you global build.gradle script.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.eowise:gradle-imagemagick:0.4.0'
}
}
task svgToPNG {
[
[ variant: 'mdpi', size: '32x32' ],
[ variant: 'hdpi', size: '48x48' ],
[ variant: 'xhdpi', size: '64x64' ],
[ variant: 'xxhdpi', size: '96x96' ],
[ variant: 'xxxhdpi', size: '128x128']
].each {
item ->
task( "buildIcons${item.variant.capitalize()}", type: com.eowise.imagemagick.tasks.Magick) {
convert './app/src/main/svgResources', { include '*.svg' }
into "./app/src/main/res/drawable-${item.variant}"
actions {
-background('none')
inputFile()
-resize(item.size)
outputFile { filename, extension -> "${filename}.png" }
}
}
}
}
Adjust the paths to you SVG resources and your app Module.
Now you can run - ./gradlew svgToPNG
and you will get for each drawable category a single task.
- buildIconsHdpi buildIconsMdpi buildIconsXhdpi buildIconsXxhdpi buildIconsXxxhdpi
Run them all and you should see your newly generated assets under the given drawable folders
Happy Generating!
Answered By - fky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.