Closed romainpiel closed 8 years ago
We could probably add that. It'd just be a matter of finding an svg -> Android converter. Do you of any good ones?
I only know that one https://github.com/inloop/svg2android but it's written in javascript. I don't know any based on gradle. Sounds like a good idea for a plugin. Actually the gradle build tools thing takes android vectors as an input instead of SVGs so the distinction int he generated folder is easier to make for them.
What the Android plugin does is kind of odd at first. It takes the Android vectors and re-outputs them to a bunch of generate folders, one for each density (in addition to rasterizing PNGs for them pre-21).
Maybe we could steal their SVG -> Android vector code once it's open sourced.
So the SVG -> Android vector code is part of Android Studio and not the build tools. Does that usually get open sourced too?
Actually branch 1.4 is available: http://tools.android.com/build
Repo sync takes forever, but I've found it: https://android.googlesource.com/platform/tools/base/+/master/sdk-common/src/main/java/com/android/ide/common/vectordrawable/
I'll look into how easy it would be to integrate this with Victor when I get some time.
Awesome! I can help you out with that
The overall gameplan is:
Alright, I've just finished my first pass at this and things aren't looking good from a few perspectives:
px
sizing (no relative sizes like pt
). So we'd have to edit the source to some extent (making this even harder).You can check out what I've been up to on https://github.com/trello/victor/tree/dlew/svg2vector but it won't work without manually doing jarjar and whatnot.
tl;dr - this will be a fair amount of work.
I’m not entirely convinced this is worth the effort right now. Actual vector drawables don’t make a difference if you have to package the PNGs, too. Unless there's some other advantage I'm missing.
Right, it's not a big thing missing but it would be nice to have it especially for animated vectors on API 21 +. For example you have an animation morphing one path to another. You could define both of them as SVGs, and declare and Android animation describing the morphing without having to redefine the vectors in separate Android vectors xml files. Pretty niche, I agree.
Anyway I thought that converting SVGs and Android vectors were pretty similar but they are apparently not. Feel free to close this ticket if you feel like it's not valuable enough.
I'd say that for your particular situation using the Android plugin is probably better anyways - then you start with exactly the Android vectors you need for the animation.
It's a similar problem, but what made Victor possible was all the hard work that was previously put into batik. I think I'm going to leave this open but wait for a better Svg2Android to come along before engaging more.
Small update on this, I'm playing with AS SVG to Android vector sources and I managed to extract + make it compile: https://github.com/RomainPiel/gradle-svg2android Maybe we could plug Victor to that.
Gradle android build tools 1.4.0-beta1 is bringing support for vectors to png conversion at compile time. We tried it and got back to Victor as it's working better for us. One minor feature requirement I would have though: the build tools are generating pngs only for versions older than v21. For a given vector file (
ic_search.svg
), the output generated folder looks like this:ic_search.xml
being an Android vector file. I don't see why Victor could not do that, anyone has tried to add this feature?