Android : automate SVG import

天大地大妈咪最大 提交于 2019-12-23 19:19:08

问题


We have a legacy Android project using drawables in the respective drawable folders for mdpi, hdpi, etc., We are planning to remove the PNG files and transition to SVG. The SVG Import UI described here creates the drawables xml from the svg. Is there a way to run this tool from command line so that we can automate the conversion from SVG to Android Drawable.xml format. We have a lot of files, so doing it manually is tedious. (Alternatively, if this is not possible, I will be writing a script to convert from SVG to Android Drawable.xml format. If such a tool already exists it will be very helpful.)

Thanks.


回答1:


The converter code from Android Studio can be found here:

SVG2Vector.java

It should be fairly easy to extract it and turn it into a command line utility.




回答2:


Look at this tool from the Android SDK source base: https://www.androiddesignpatterns.com/2018/11/android-studio-svg-to-vector-cli.html

You can download a compiled version, or compile it yourself.




回答3:


Maybe too late, but I would recommend Respresso which is an online tool capable to batch convert SVG images to Android vector drawables. (If you need, it will also convert it to pdf for iOS.)

You have to upload the images (in batch) then sync the resized/converted ones directly to your project using the tool's gradle plugin.

Please note that it will require you to create an account (for free) as it will sync any change to your project directly. (So you can add/change an image (svg, pdf, png, jpeg, android drawable) and it will automatically add/change the converted files in your project at the next build.)

I worked on the tool and I think it is really cool and I use it personally. I have no shares in it. I hope you will also like it.




回答4:


Found an online tool : http://inloop.github.io/svg2android/ If there is a Android provided command line tool, it will be very helpful in terms of automating via scripts.



来源:https://stackoverflow.com/questions/40927461/android-automate-svg-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!