49

Start from this month, I was not able to import any svg file though Vector Asset in my laptop, I always get the msg 'Internal error parsing abc.svg'

I tried to import same svg file using android studio in other laptop, it works, but my laptop cannot import anymore.

I was using android studio in my laptop around 2 years and has been go through many updates, but this month suddenly cannot import anymore, I had performed factory reset in my laptop, and re-install android studio again. I tried create new project as well, but it still cannot work, anyone can help me?

enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148
Kok Soon
  • 493
  • 1
  • 4
  • 6

11 Answers11

62

UPDATE December 23, 2018

Base on issuetracker seems this bug fixed in Android Studio 3.2 Canary 5 and above so update your android studio is another way to fix! now i use version 3.2.1 and work fine.

OLD ANSWER

Finally i found solution. I don't know what going on but i have same problem and fixed when i download same svg again and open it with notepad++ and export it with different name as svg! and it's work!

EDIT

If you use flat icon for download svg, before download just click on edit and then download! this svg work fine in android studio.

I have android studio 3.1.1

This just a bug in android studio

EDIT 2

There is another bug in decimal numbers in svg viewBox that can be fixed by change decimal to integer (thanks to crgarrido)

Sample :

Change decimal numbers to integers numbers in svg file header

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 375 135.4">

Change 135.4 to 135

Radesh
  • 13,084
  • 4
  • 51
  • 64
61

In my case, I had a decimal value indicating the height, rounded it to an integer solved the issue

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 375 135.4">

Changing the 135.4 to a 136 did the job

Update

After that, In the IDE Fatal errors section I constated the following exception:

NumberFormatException

The vector assert parser fails when you have a decimal dimension, I reported the issue. I hope it will be fixed soon.

crgarridos
  • 8,758
  • 3
  • 49
  • 61
15

I had this error too, and I think I got an answer.

When you "Add a Vector Asset" in your project, Android Studio creates a .xml file in res/drawable folder.

So I found this website : http://a-student.github.io/SvgToVectorDrawableConverter.Web/

You just have to drop your .svg file in the box and wait a few seconds.

Then, just right click on drawable folder in Android Studio, New -> Drawable resource file, set the icon name, etc... And you finally replace the content by the xml code the website gave you.

Save the file, and your icon is ready to go !

Mathieu
  • 1,435
  • 3
  • 16
  • 35
4

I solved the problem adding width and height to the svg tag.

Example

From

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 43.42 56.15">

To

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 43.42 56.15" width="24" height="24">

I guess Android Studio can't add vectors from svg files without mentioning the dimensions.

sunlover3
  • 1,999
  • 1
  • 20
  • 25
  • @KokSoon I know. You need to customize your vector after you import the svg. But at least you won't have errors on importing the svg into your project. – sunlover3 Jul 19 '18 at 07:34
2

Hi you have to convert all float number to integer. for example open .svg file in text editor

 width="292.362px" height="292.362px" viewBox="0 0 292.362 292.362" style="enable-background:new 0 0 292.362 292.362;"

change to

width="292px" height="292px" viewBox="0 0 292 292" style="enable-background:new 0 0 292 292;"
Erfan Eghterafi
  • 4,344
  • 1
  • 33
  • 44
1

The problem is your SVG file. You must set the page measure to be in pixels.

With Inkscape, in Windows, press Ctrl + Shift + D to open the Document Properties. Set the size units to pixels (px).

Hope it helps. Let me know if it worked.

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Luís Henriques
  • 604
  • 1
  • 10
  • 30
  • But why i use my colleague laptop can be import, but my laptop cannot be import? we both tried import the same svg file, and my laptop can view the svg file in chrome, are you sure is the svg file problem ? – Kok Soon Apr 19 '18 at 09:24
  • Of course I'm not sure. The only way I could be sure is if I was handling the situation myself. I'm only going by what you tell me. But yes, it's most likely an svg problem. Have you tried what I suggested? – Luís Henriques Apr 19 '18 at 09:59
  • I tried your idea, i did open Properties but i didnt see any size units, i cant find anywhere to set pixels (px). – Kok Soon Apr 20 '18 at 09:42
  • Android Studio 3.1.1, i think it should be the latest version. – Kok Soon Apr 24 '18 at 08:20
1

I solved my problem by removing the comma separated values in the viewBox, i.e. I had

viewBox="0, 0, 350,450"

and changing it to

viewBox="0 0 350 450"

allowed it to be imported

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

I used Gimp and Export Path to produce a simple SVG. It had the width and height as decimal inches. Changing these to the pixel width/height fixed it.

and
  • 31
  • 4
-1

w: 85.3 h:120.4px ==> w:85px H:120px its ok and work

Amin Emadi
  • 17
  • 3
-1

Open your SVG file in Notepad. Round all the decimal values in viewBox ="no decimal values allowed here".

Deepak Kataria
  • 554
  • 3
  • 10
-2

I was able to solve this internal error by parsing abc.svg error problem, please change width="512px" and height="512px" and it should work.

enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148