Android: Using SVG in res leads to error: "The file name must end with .xml or .png"
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
or src/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 add
android.disableResourceValidation=true
into your gradle.properties
file (usually located in the root project next to settings.gradle
) to enable the pre-1.2.2 behavior.
For more info see http://b.android.com/192493
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:
buildscript {
repositories {
jcenter()
mavenCentral()
// mavenLocal() // Only if you want to use your local maven repo
}
dependencies {
// classpath 'com.android.tools.build:gradle:+'
classpath 'com.android.tools.build:gradle:1.2.2'
}
}
Add the following to your gradle.properties :
android.disableResourceValidation=true