Android Studio矢量图素材导入错误 - 不支持标签

16

我一直在使用新的gradle插件-1.4.0-beta3测试Andorid Studio。

我一直试图导入自己在Inkscape中制作的矢量资产。但是我一直遇到导入错误。错误消息包含了许多不受支持的svg标签。

In mm_card.svg:
ERROR@ line 54 <defs> is not supported
ERROR@ line 56 <linearGradient> is not supported
ERROR@ line 58 <stop> is not supported
ERROR@ line 62 <stop> is not supported
ERROR@ line 66 <stop> is not supported
ERROR@ line 70 <stop> is not supported
ERROR@ line 74 <stop> is not supported
ERROR@ line 78 <stop> is not supported
ERROR@ line 83 <linearGradient> is not supported
ERROR@ line 85 <stop> is not supported
ERROR@ line 89 <stop> is not supported
ERROR@ line 93 <stop> is not supported
ERROR@ line 97 <stop> is not supported
ERROR@ line 102 <linearGradient> is not supported
ERROR@ line 104 <stop> is not supported
ERROR@ line 108 <stop> is not supported
ERROR@ line 113 <linearGradient> is not supported
ERROR@ line 115 <stop> is not supported
ERROR@ line 119 <stop> is not supported
ERROR@ line 123 <stop> is not supported
ERROR@ line 127 <stop> is not supported
ERROR@ line 131 <stop> is not supported
ERROR@ line 135 <stop> is not supported
ERROR@ line 139 <stop> is not supported

有人知道这是什么原因吗?是矢量资产工具出错了吗?或者是Inkscape创建的SVG文件有问题?还是更复杂的SVG文件不受支持?

谢谢!


这似乎是非常基本的东西,不允许使用。大多数SVG都会有一个<defs>元素,而且相当一部分SVG都会有线性渐变。 - Glenn Howes
我曾经遇到过从CorelDraw导入Android矢量资源的问题。后来我找到了解决方案:尝试使用这个工具将你导出的SVG转换为矢量图形:https://shapeshifter.design/ 如果这样做解决了你的问题。 - java acm
1个回答

15

Android Studio中的SVG导入功能对某些SVG功能仅有有限支持。

他们在宣布视频中也明确表示了这一点。他们表示他们打算改进导入器。

但请注意,渐变在VectorDrawables中也不受支持。


视频中提到,复制矢量代码并应用某些更改以修复错误,那么<defs>的替代方法是什么? - Shubham AgaRwal
1
它们的意思是复制路径定义。这是<path>元素中d属性的值。 - Paul LeBeau
VectorDrawables不支持渐变,但您可以使用GradientDrawable作为ImageView背景或作为LayerDrawable的一部分来获得相同的效果。 - Mark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接