|尝试从AndroidStudio 2.2,Ubuntu 14.04的本地svg文件生成矢量资产时出现此错误
Could not generate a preview
In icon.svg
ERROR@ line 6 <defs> is not supported
ERROR@ line 25 <use> is not supported
我谷歌发现发生这种情况是因为AndroidStudio不支持<defs>
,<use>
...
但我不知道如何解决它?
我可以将<defs>
更改为AndroidStudio支持的另一个标签吗?
或者我永远不能从这个SVG文件生成矢量资产?
任何帮助或建议都将非常感激。
答案 0 :(得分:10)
我直接从草图导入svg到android工作室时遇到了同样的问题,我使用这个tool将它转换为vector drawable然后导入它。
答案 1 :(得分:6)
您的SVG使用<linearGradient>
,为了制作模糊阴影,它使用SVG过滤器(<filter>
)。 VectorDrawables都不支持这些。所以任何解决方案都会涉及删除那些。
看起来该文件是在Sketch中创建的。您可以尝试在Sketch中删除这些项目并再次尝试导入。
如果仍然不起作用,那么您可能必须手动修复导入程序不支持的其他元素:<use>
。好消息是它很容易解决。
我已经在下面包含了手动编辑的文件版本,修复了这三个问题。它应该导入到Android Studio中,但我不知道它是否符合您的审美需求。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="353px" height="475px" viewBox="0 0 353 475" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: sketchtool 40.2 (33826) - http://www.bohemiancoding.com/sketch -->
<title>3765E978-B278-427B-8571-70DE79D99C8A</title>
<desc>Created with sketchtool.</desc>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="LoadingScreen" transform="translate(-370.000000, -455.000000)">
<g id="icon" transform="translate(302.881496, 430.476899)">
<g id="Page-1-Copy-3" transform="translate(227.267540, 231.515653) rotate(-40.000000) translate(-227.267540, -231.515653) translate(82.767540, 51.515653)">
<g id="Combined-Shape">
<path stroke="#55FFD9" stroke-width="1" fill="#49D1B7" fill-rule="evenodd"
d="M186.685057,69.3951579 C179.071738,84.054677 167.196464,93.5829106 147.566191,86.4324469 C145.5069,85.6807637 143.143294,85.6854176 140.908382,85.4719208 C110.344523,82.5443919 101.488745,66.5911886 116.541777,40.0162683 C124.759532,25.5078922 135.844381,13.0321318 151.386964,5.38509524 C176.103451,-6.77934919 195.596784,4.90406969 195.936794,31.9247221 C196.09814,44.884376 193.040127,55.9872472 186.685057,69.3951579 L186.685057,69.3951579 Z M198.595037,119.672673 C182.675646,106.53093 181.93282,99.7311426 194.798418,84.9441152 C210.815159,66.5375926 231.906487,60.2048217 243.950958,70.1893157 C255.533227,79.7914354 252.958093,97.0539863 237.290073,114.861111 C222.808075,131.31966 214.025927,132.411187 198.595037,119.672673 L198.595037,119.672673 Z M261.701593,172.524646 C256.255382,175.618319 247.028302,174.835442 241.296061,165.817955 C230.52687,148.874141 231.029057,142.675217 248.302041,132.303868 C258.061419,126.443308 268.19848,124.565822 276.849824,132.235549 C286.713683,140.98316 282.007021,150.347416 276.816132,159.049853 C272.613406,166.093343 261.701593,172.524646 261.701593,172.524646 L261.701593,172.524646 Z M258.884249,185.876613 C265.445061,178.927297 275.146113,178.821092 281.280117,183.8411 C290.291923,191.219766 290.497384,203.145311 281.829513,210.911347 C265.175566,225.832917 237.744852,208.265824 258.884249,185.876613 L258.884249,185.876613 Z M253.914854,238.407128 C259.379321,233.168583 266.48379,232.575328 271.037507,236.310514 C277.728699,241.7988 277.025625,250.455585 270.795386,257.209223 C258.269501,270.789008 235.658358,255.908285 253.914854,238.407128 L253.914854,238.407128 Z M0.471927459,334.579649 C-0.840210761,352.465266 12.3567324,362.93098 29.9512025,357.954605 L143.456907,325.850939 C195.727834,313.150715 236.519224,256.512569 230.761952,204.648157 C227.6544,176.61325 213.571088,151.367964 191.116546,133.562925 C168.660361,115.756584 140.515656,107.517709 111.868627,110.365293 C58.8564726,115.631895 10.7533507,166.485529 8.95278386,218.977994 L0.471927459,334.579649 L0.471927459,334.579649 Z M149.592296,185.327725 C166.515393,198.746676 169.20872,223.050038 155.605641,239.498964 C142.002561,255.94789 117.165239,258.42118 100.242142,245.002229 C83.3190454,231.583278 80.6257184,207.279916 94.2287979,190.83099 C107.831877,174.382064 132.669199,171.908774 149.592296,185.327725 L149.592296,185.327725 Z"></path>
</g>
</g>
</g>
</g>
</g>
</svg>
&#13;