19

In recent google IO 2015, google announced that the new Android Studio 1.3/ new gradle plugin will have support for importing and SVG file and the build system will generate the assets for different device densities (hdpi, xhdpi, xxhdpi etc):

http://robovm.com/google-io-summary-whats-new-in-android-development-tools/ https://www.youtube.com/watch?v=f7ihSQ44WO0&feature=youtu.be&t=2m46s

Unfortunately there doesnt seem to be more information about how to achieve that. Does any one have any more details about it?

There is some mention of it in : Android: Using SVG in res leads to error: "The file name must end with .xml or .png"

and I tried to create a hello world app and places an svg file (renamed it to xml in the drawable folder). it compiled and installed on the device, but crashed during execution saying svg is not a vlaid tag. suppose the original file needs more conversion.

Community
  • 1
  • 1
Nilesh Pawar
  • 3,845
  • 3
  • 19
  • 18
  • 1
    It's possible this feature isn't available on first 1.3 preview, if you listen closely mr Eason says "so soon, with Android Studio.." – harism Jun 01 '15 at 19:35
  • @Nilesh Ever make headway on this topic? I'd like to use this feature in Android Studio as well... – IgorGanapolsky Jun 09 '15 at 18:33
  • @IgorGanapolsky I think it has not been released by google until now. So i will be waiting for the google guys to provide some documentation. – Nilesh Pawar Jun 10 '15 at 21:22
  • @NileshPawar Typical google - they announce a feature at IO, and then don't release it. – IgorGanapolsky Jul 17 '15 at 15:31
  • 1
    This feature was supposed to be released in 1.3, but [AS 1.3 release notes](http://tools.android.com/recent/androidstudio13betaavailable) state "Similarly, the vector rasterization support is also still not enabled due to various bugs." – Adam Johns Aug 02 '15 at 20:52
  • 3
    A bit of an update http://tools.android.com/recent/androidstudio14preview1incanarychannel Don't miss the fine print. This change will be in gradle 1.4 which hasn't been released for preview yet. – Stimsoni Aug 26 '15 at 00:25
  • @Stimsoni thanks for the update. – Nilesh Pawar Aug 26 '15 at 22:37

2 Answers2

8

To add a new vector asset right click on your drawable folder in Android Studio and choose New > Vector asset. Please note that you need Gradle 1.4 or newer to use vector assets with projects with a build target lower than 21. In this case Gradle will convert the vector images to PNGs at build time.

The current beta version of Gradle 1.4 has some issues with opening keystores when releasing an apk, so before importing a lot of vector images, try to release your app first (this is only my personal experience with Gradle 1.4.0-beta6, Gradle will report a tampered keystore, e.g. see here)

enter image description here enter image description here

Community
  • 1
  • 1
crysxd
  • 3,013
  • 16
  • 31
0

For anyone using Android Studio 3.0+, you can go to right-click on your drawable folder on your directory structure as shown below;

enter image description here

Go to New > and click on Vector Asset. It should take you to a window similar to the one below;

enter image description here

  1. Make sure the Local file (SVG, PSD) is selected.
  2. Type a custom name for your new vector image (optional).
  3. Click on the path field and navigate to the location of your SVG or PSD file and open it.
  4. Configure any other options you want to customize your vector and then click FINISH.

Android studio should generate a <the vector name you entered>.xml file in your drawable folder and you now can use it in your project.

Kenneth Murerwa
  • 561
  • 10
  • 13