Vector Asset Studio exception parsing xml - android

I have an svg file (vector graphics) which opens fine in Internet Explorer, but fails when opening in Vector Asset studio (part of android studio) with:
For input string: 2.85465in Exception while parsing XML file:
I think this is caused by the decimal point, where a comma is expected as the computer used has Dutch settings and "," is expected to be the decimal separator.
Where does Vector asset studio gets it's information for this and can it be changed locally?

With this error in Vector Asset:
Could not generate a preview
Exception while parsing XML file:
Premature end of file.
My provisional solution was:
Before getting the .svg file, I generated a .png with Photoshop CC.
I converted my .png to .svg with a converter
Verify that my .svg can be converted to VectorDrawable. This is to know if the Android Studio Vector Asset will be able to perform the conversion.
And finally, I select the VectorDrawable XML that I generated when I checked and paste a resource into the drawable directory, or I use New-> Vector Asset to generate this resource from my verified .svg.
With check I mean make sure the .svg will be parsed to xml with Vector Asset.
So I observed this error occurs when the image has tiny text and when using the .svg converter is likely to skip it.

SVG files are just text files, you can open them in any text editor (like notepad) and change their content as you like.

Try removeing the in or replace it by px. Asset Studio doesn't seem to work with any other size declaration than px.
There was a conversation on google groups, I think, that I recently read. Took the solution from there. Will add the link if I find it again.
// edit: found it: https://code.google.com/p/android/issues/detail?id=189654

Related

Error creating Vector Image Asset: <text> is not supported

I created a basic SVG file in illustrator using Line Tool, Eclipse Tool & Text only. The font I used was Century Schoolbook.
When I try to configure a vector asset I get the error, is not supported. The preview shows the SVG without the text
Am I not suppose to use text on SVG files? Surely that can't be the case?
Here's the error:
At present, Android's vector assets handle a small subset of SVG, mostly focused on paths. It does not appear that it supports text.
However, your SVG tool may have the ability to export an SVG where the text (in your desired font) is converted to paths. This also ensures that your text shows up in your desired (converted) font, as the font you might be using in your artwork may not exist on the Android device.

How do I convert pngs directly to android vector drawables?

Are there online tools to convert png file to vector drawable files (xml in Android)?
I have few pngs that I was using for icons & various places in my app.
So, now I want to convert them to xmls. Is it possible to do so?
Ok, so you can convert PNG to Android vector drawable following these steps
Step 1:
Convert PNG to SVG (Scalable Vector Graphics)
https://www.autotracer.org/
Or you can use any online converter of your choice
Step 2:
Use the generated SVG in step 1 and convert it to Android vector drawable using this link
http://inloop.github.io/svg2android/
http://a-student.github.io/SvgToVectorDrawableConverter.Web/
Alternatively you can also use Android studio to generate Vector drawables from SVG generated in Step 1.
Inside Android studio, right click on your drawable folder
New > Vector Asset
This will open up the Android studio Vector asset generator.
Select a local SVG file (the one you generated online)
You can also refer to this post
https://stackoverflow.com/a/35402459/6142219

how do you use svg in drawable folder?

i am creating a bottom navigation bar for a android app following this guide
however, when using svg in android:icon and building it, it shows a error
Error: The file name must end with .xml or .png
i found out that i needed to move the svg to the assets folder. but if i move it, i can't use the svg... any help is much appreciated, thank you
The answer above gives a link to convert pictures from SVG to XML, but this tool is not for free(only for one SVG file)
So why not to use ANDROID build-in tool?
The best way is to go to res-> drawable-> Vector Asset -> Local file (SVG, PSD) ->select your SVG file from the place you save it.
and you are done :)
Android uses vector drawables which are xml files rather than SVG's.
You will have to convert the SVG to a vector drawable. Many ways of doing it but a handy web tool is available here.
It won't do complex SVG's but copes with the majority.

Vector Asset Studio is importing colorful .svg file as black and white

I'm using the instructions found here, from Google to use the new option (March 2016) to import .svg files into drawable instead of .png files.
The problem I have is that the file gets imported as black and white, even though the file has many colors.
Here's an image of the .svg file, as read by Google Chrome:
This same file, is then read like this by the Vector Asset Studio:
And in the app, the image shows up as black and white.
Any idea of why this is happening?
The .svg file is getting generated on Adobe PhotoShop Creative Cloud, and I'm using Android Studio 1.5.1 on Mac.
Thank you!
EDIT: added link to .svg file I'm using for this question.
I also had the same problem but after digging internet
finally found the solution, here it is:-
After getting done with illustrator designing
1) Go to File --> Save As ---> Window Dialog box Opens--> type name of svg
--->Click Save
2) Now it shows SVG Options dialog box ---> At bottom left click More Options ---> In CSS Properties dropdown ---> Select Presentation Attributes
this setting makes svg compatible code for android import with colors !!
Sorry for making this answer elaborate ... did this for those who are beginners
Android Studio's SVG importer is somewhat limited. It only handles very simple SVG files. And I don't believe it supports the <style> element, or the class attribute. So you will need to change the CSS to XML properties.
For example:
<path class="st0" d="M163.3,10.8c2.4-0.5,6.2-0.9,10-0.9c5.5,0,9,0.9,11.6,3.1c2.2,1.6,3.5,4.1,3.5,7.5c0,4.1-2.7,7.7-7.2,9.3v0.1
c4,1,8.7,4.3,8.7,10.6c0,3.6-1.4,6.4-3.6,8.5c-3,2.7-7.7,4-14.6,4c-3.8,0-6.7-0.3-8.5-0.5V10.8z M168.8,28.1h5c5.8,0,9.2-3,9.2-7.1
c0-5-3.8-6.9-9.3-6.9c-2.5,0-4,0.2-4.8,0.4V28.1z M168.8,48.4c1.1,0.2,2.6,0.3,4.6,0.3c5.7,0,10.9-2.1,10.9-8.2
c0-5.8-5-8.2-10.9-8.2h-4.5V48.4z"/>
Will need to be changed to:
<path fill="#007299" d="M163.3,10.8c2.4-0.5,6.2-0.9,10-0.9c5.5,0,9,0.9,11.6,3.1c2.2,1.6,3.5,4.1,3.5,7.5c0,4.1-2.7,7.7-7.2,9.3v0.1
c4,1,8.7,4.3,8.7,10.6c0,3.6-1.4,6.4-3.6,8.5c-3,2.7-7.7,4-14.6,4c-3.8,0-6.7-0.3-8.5-0.5V10.8z M168.8,28.1h5c5.8,0,9.2-3,9.2-7.1
c0-5-3.8-6.9-9.3-6.9c-2.5,0-4,0.2-4.8,0.4V28.1z M168.8,48.4c1.1,0.2,2.6,0.3,4.6,0.3c5.7,0,10.9-2.1,10.9-8.2
c0-5.8-5-8.2-10.9-8.2h-4.5V48.4z"/>
Etcetera for the rest of the <path> elements.
It's so simple
you can change your color directly from your svg xml after adding image to your project .
when you added image to your project; svg color must be like this :
android:fillColor="#000000"
just need to change to this :
android:fillColor="#b3ff856d"
just looking for android:fillColor

How do I export Android XML vector drawables to another format?

I want to recreate my app for iOS and the icons in Android are XML vectors with the "android:pathData" attribute. How do I convert these to an image that I can place into Xcode and use (preserving transparency)?
I have searched for a solution and found nothing and read the article on the Android Developer site on Vector Asset Studio but found nothing about exporting these drawables to something I can import into Xcode.
I did it by creating an SVG file and copying the value of the pathData attribute of the path element in the XML file and pasting it into the d attribute of the path element in the SVG file. I then converted it to PNG using ImageMagick.
So
<path android:pathData="[Path Data]">
becomes
<path d="[Path Data]">.
Then
convert -background none image.svg image.png
in the command line.
If there is a better way of doing this please post it.
After using the trick Questioner provide, I use a browser to open the svg file, zoom-in to the size as big as possible and take a screenshot. FYI.

Categories

Resources