为什么我的SVG无法在Vector Asset Studio中加载

Luk*_*son 34 svg android android-layout androidsvg android-vectordrawable

下面的SVG无法在Android Studio的Vector Asset Studio中打开导致错误:

"清空预览图像!解析TareSymbol.svg时的异常:对于输入字符串:"8.7337904mm"解析XML文件时出现异常:文件过早结束."

为什么以下SVG文件与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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 36

Android Studio的Vector Asset Studio目前不支持SVG的所有功能.您可以使用此工具将SVG转换为VectorDrawable .

希望能帮助到你.

  • 非常感谢您的建议,但不幸的是,这也不起作用. (6认同)
  • 现在不推荐使用此工具。它建议使用Android Studio的矢量资产工具,但仍然会出现错误。 (2认同)

Kin*_*dio 13

你需要改变svg的宽度和高度mmpx代替使用.当问题得到解决时,这是当前的解决方法.

已经有一个提交bug报告在这里


idi*_*ish 10

花了几个小时后,我发现了问题,甚至使用外部的svg2vectordrawable脚本也无济于事.

形状的大小和/或文档的页面大小不能包含宽度/高度的浮点数,例如14.134或3.5

意味着形状和页面的宽度和高度必须是整数!


Blu*_*ell 10

我的 SVG 是,viewbox标签中创建的(来自在线网站)。

IE:

viewBox="0, 0, 350,450"

将此更改为:

viewBox="0 0 350 450"

允许 Android Studio 导入它


Den*_*sGL 9

正如@Kingsley Adio所说,您必须使用pxSVG文档的单位.
在Inkscape中,我设法通过创建自定义页面大小并将输出单位设置为px:

Inkscape文档属性


Luk*_*son 6

将Inkscape中生成的.svg文件导入Adobe Illustrator并导出它们可以100%解决此问题.