55

The SVG below is failing to open in Android Studio's Vector Asset Studio in resulting in the error:

"Empty preview image! EXCEPTION in parsing TareSymbol.svg: For input string: "8.7337904mm"Exception while parsing XML file: Premature end of file."

Why is the following SVG file not compatible with Vector Asset Studio?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   id="svg20235"
   viewBox="0 0 61.500162 30.946501"
   height="8.7337904mm"
   width="17.356712mm">
  <defs
     id="defs20237" />
  <metadata
     id="metadata20240">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     transform="translate(-109.24987,-351.17467)"
     id="layer1">
    <path
       d="m 145.03542,367.34167 10.897,-4.49325 -0.009,3.30587 13.69124,0.0372 1.13537,0 0,2.1285 -1.13537,0 -13.69662,-0.0373 -0.009,3.33988 -10.87325,-4.281 z m -13.38814,-13.15875 0,-3.00825 16.97389,0 0,3.00825 -6.8995,0 0,27.93825 -3.15214,0 0,-27.93825 -6.92225,0 z m 3.31725,13.15875 -10.897,4.49325 0.009,-3.3055 -13.69129,-0.0373 -1.13537,0 0,-2.1285 1.13537,0 13.69662,0.0372 0.009,-3.33988 10.87325,4.28063 z"
       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
       id="path20212" />
  </g>
</svg>

enter image description here

Luke Allison
  • 3,118
  • 3
  • 24
  • 40

11 Answers11

42

Android Studio's Vector Asset Studio is currently not support all the features of SVG. You can convert SVG to VectorDrawable using this tool.

Hope it helps.

  • 8
    Thanks a lot for the suggestion but unfortunately this doesn't work either. – Luke Allison Apr 28 '16 at 10:51
  • Check out this [Youtube link](https://www.youtube.com/watch?v=KpXtYoE-NCk) for your further references. –  Apr 29 '16 at 03:36
  • Thanks for the link. I can confirm that this tool worked for me on a particular svg file where one of the paths was left out by Android Studio. – BooleanCheese Apr 03 '18 at 13:23
  • 2
    This tool is deprecated now. It suggests to use Android studio's vector asset tool but it still gives an error. – dhanushkac Jan 12 '19 at 11:50
15

You need to change the width and height of the svg from mm to use px instead. This is a current workaround pending when the issue is fixed.

There is already a filed bug report here

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Kingsley Adio
  • 728
  • 5
  • 16
15

My SVG was being created (from an online website) with , in the viewbox tag.

i.e:

viewBox="0, 0, 350,450"

changing this to:

viewBox="0 0 350 450"

allowed Android Studio to import it

Blundell
  • 75,855
  • 30
  • 208
  • 233
10

After spending some hours, I figured out the problem, and even using external svg2vectordrawable scripts couldn't help.

The size of the shapes and/or the document's page size cannot contain floating numbers in its width/height such as 14.134 or 3.5

Meaning the width and height of the shape and the page must be integers!

idish
  • 3,190
  • 12
  • 53
  • 85
9

As @Kingsley Adio said, you must use px units for your SVG document.
In Inkscape, I managed to do it by creating a custom page size and setting the output unit to px:

Inkscape Document Properties

DenisGL
  • 1,190
  • 1
  • 16
  • 31
7

Importing the .svg files produced in Inkscape into Adobe Illustrator and exporting them fixed this issue 100%.

Luke Allison
  • 3,118
  • 3
  • 24
  • 40
1

Compilation of things that worked for me when trying to import SVGs with the Vector Asset tool (they are not mutually exclusive):

  • Change values from mm to px (typically found in the width / height attributes)
  • Round values float values to integer (typically found in the width / height or viewBox or style attributes). Like 224.5. You won't have to do this in the polygons, but only on the SVG node.
xarlymg89
  • 2,552
  • 2
  • 27
  • 41
  • 1
    For SVGs from https://www.flaticon.com seems to be working perfectly so far. Already imported more than 10 SVGs following this guidelines. – xarlymg89 Jun 22 '18 at 14:54
1

Changing the language in settings helped me! I had Dutch as language on my computer (where comma's are used instead of floating points) and changing it to English and restarting worked for me.

Hester
  • 11
  • 3
  • 1
    Hey, thanks for contributing Unfortunately your question could be classified as low effort, albeit it could be technically correct. Please try to include details into your answer, such as step-by-step way to change the floating point symbol, so it can be used as a proper answer – Samuel Hulla Aug 03 '18 at 15:03
0

Changing Text to Object fixed this issue for me. If you are using Inkscape: first click Ctrl+K (Path Combine) then Ctrl+J (Dynamic Offset).

TofferJ
  • 4,678
  • 1
  • 37
  • 49
0

There are various option that might cause such an error (some of them listed here).

On causing could be the use of rgba(r,g,b,a) in your .svg file. Just check and convert if found.

Hint: You can edit .svg fils in any file editor.

Hannes Tiltmann
  • 2,296
  • 1
  • 12
  • 20
0

I had similar problem. I was using Illustrator 2015. Problem turned out to be I had multiple artboards in my illustrator project and I had to choose one particular artboard when saving as svg file (why it does so? no idea). Solved by having only one artboard containing the design I want to save as svg.

  1. Make sure your illustrator design has only one artboard containing
    the design you want to use as vector asset in android studio.

  2. In Illustrator File->Save as->select svg from dropdown. Keep all other options as default.

  3. Go to android studio, right click on drawables and click vector asset and import your newly created svg file. It would be saved as an xml file in drawables.

Umer Mehmood
  • 87
  • 10