I just updated Android Studio 1.2.1.1 and now gradle got problems with svg in my resources folder. I was always using SVGs with no problem and I hope they will be "allowed" in the future.
:app:mergeDebugResources
:app:mergeDebugResources FAILED
/home/petergriffin/folder1/another-app/MyAwesome-App/app/src/main/res/drawable-hdpi/logo.svg
Error:Error: The file name must end with .xml or .png
Error:Execution failed for task ':app:mergeDebugResources'.
> /home/petergriffin/folder1/another-app/MyAwesome-App/app/src/main/res/drawable-hdpi/logo.svg: Error: The file name must end with .xml or .png
Information:BUILD FAILED
Any ideas how to solve that ?
SVG files are not supported by Android as drawables. Even if you put them there, the system cannot decode them as you would expect. Instead try to put them in
src/main/res/raw
orsrc/main/assets
folder and load them appropriately (via an external library). Most people confuse SVG and Vector-drawables, they're not the same thing. Vector-drawables use SVG-compatible path mini-language, but that's about it.The current accepted solution is to revert back to an archaic version of the Gradle plugin, which is counterproductive in most cases. The tools team is investing a lot of effort in making the build much better (it's really noticable).
Instead of reverting you should pull forward to
1.5.0
(has been stable for a while now) and addandroid.disableResourceValidation=true
into yourgradle.properties
file (usually located in the root project next tosettings.gradle
) to enable the pre-1.2.2 behavior.For more info see http://b.android.com/192493
the problem still remains on gradle 1.5. It seems that the only option in the future is to convert the svg files to xml using the "create vector asset" and then select svg file option.
Within Android you should be using (XML) Vector Drawable files (they contain the SVG information inside the XML, details: https://developer.android.com/training/material/drawables.html#VectorDrawables).
Vector Drawables can be downloaded from this repository: https://github.com/google/material-design-icons. Look for the folders called drawable-anydpi-v21 within the icon directories. This folder includes the Vector Drawable files to be placed within the drawable directory of your app.
Note that working with the Vector Drawable files is only supported for Android 5.0 and higher. In case you need to be compatible with <5.0 Android version I would recommend to make use of this library: https://github.com/trello/victor This library can be used to convert SVG files to drawables in different formats during compilation of your app. Which saves you from having to create and mantain mdpi/hdpi/xhdpi/xxhdpi folders manually.
In case you name the Vector drawable files and the SVG files equally, you can use both approaches next to each other.
Same problem with webp files in the drawable resource directory.
The latest gradle plugin (v1.2.3) is not recognizing some of the image formats that used to work before. I don't have the issue when I switch back to v1.2.2
UPDATE: Given that this feature was fixed, you should upgrade to the latest gradle plugin release instead of reverting back.
You can change the version in your build.gradle by setting:
there is a problem in android studio 1.5.1 while using build:gradle:1.5.0.please give the solution. I just updated Android Studio 1.5.1 and now gradle got problems with svg in my resources folder. I was always using SVGs with no problem and I hope they will be "allowed" in the future.