AndroidStudio import SVG with ERROR@ <mask> is not supported

旧街凉风 提交于 2019-12-06 17:23:53

问题


I got message "ERROR@ <mask> is not supported" when try to import SVG using

 Android Studio 3.0.1
Build #AI-171.4443003, built on November 10, 2017
JRE: 1.8.0_152-release-915-b08 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

Anyway to import SVG and make them show correctly?


回答1:


Solution 1

Flattern image in Sketch and use this site to convert SVG to xml for Android

Solution 2

I use nonZero instead of evenOdd and open it in Sketch to reverse Order after reverse it will change pathData and remove android:fillType and everything work fine on Android 21+.

Solution 3

PNG

TLDR

After some research I found that there are two fill-rule property methods for Vector graphics, SVGs, the “evenodd” vs “nonzero”

I opened the SVG icon in Sketch and inspected the hole at the top of the icon. As expected it uses fill-rule:evenodd property. Now I have to change the fill-rule to use “nonzero” property. How? Select the path. In the right side, there is a settings icon at the “Fills” property. Click it and choose “non-zero”.

From the main menu, choose Layer → Paths → Reverse Order. I got the hole back at the top of the icon and got the hole in the app, too.

For more detail




回答2:


  1. Open the SVG file and remove the mask element. You can keep the use element.
  2. Import
  3. Open imported file
  4. Remove the last element that hasfillType="evenOdd"
  5. Update the color on the android:fillType="nonZero" element

This depends of course on how the designer exports the asset but editing paths like this will most always get you where you want.




回答3:


If all you have is the .svg file, you can manipulate the .svg markup by hand to remove the mask and apply a fill inline.

If you're working with a designer, you can ask them to take the icon and remove whatever is inside the mask and apply a fill to the icon instead. Then have the designer export the .svg file and retry the import into Android Studio.

When the asset you're trying to import is exported from a designer software like Sketch or other, AND the icon is a mask (as opposed to a fill) it will export with that tag. Android Studio only accepts .svg's with fills (this is not a problem with iOS)




回答4:


In my case this was the result of a symbol override in Sketch which is a known technique which enables you to easily change a symbol's color. It requires you to use a (color) symbol inside a symbol (nested symbols) as a mask. This is the mask that was causing issues.

My solution was simply to create an export version of the original symbol where I delete the mask.



来源:https://stackoverflow.com/questions/49488312/androidstudio-import-svg-with-error-mask-is-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!