IF you're using Gradle Plugin 2.0, you need to make changes in your gradle
:
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
If you are using Gradle 1.5 you’ll use instead of previus:
// Gradle Plugin 1.5
android {
defaultConfig {
// Stops the Gradle plugin's automatic rasterization of vectors
generatedDensities = []
}
// Flag to tell aapt to keep the attribute ids around
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Check also: Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0.
Android Support Library Ref.: Support Vector Drawables and Animated Vector Drawables.
Also update Android Support dependencies from
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
to
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
as you're already using build-tools in version of 24.0.2
.
If any of the other solutions does not work, you can add this line in your Activity
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
and of course, update your gradle and appcompat to the latest versions. This worked in my case.
None of these worked for me. But this did:
Change
android:src="@drawable/your_drawable"
to
app:srcCompat="@drawable/your_drawable"
I ran into this issue in Xamarin.Android with Xamarin.Android.Support.Design 24.0.2. Here is how I solved it:
Added the following line to my Application class OnCreate
:
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
Replaced:
var upArrow = ContextCompat.GetDrawable(this, Resource.Drawable.abc_ic_ab_back_material);
With:
var upArrow = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.abc_ic_ab_back_material, null);
Since this page is the first result of google android.content.res.Resources$NotFoundException: File res/drawable/
, I want to share that this exception might caused by your foo.xml contains improper code.
e.g. foo.xml
:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<size android:height="@android:style/Widget.ProgressBar.Horizontal" />
<corners android:radius="5dip" />
<gradient
android:startColor="#000000"
android:centerY="0.75"
android:angle="270"
/>
</shape>
</item>
</layer-list>
This xml contains <size android:height="@android:style/Widget.ProgressBar.Horizontal" />
which compiled successfully but throws exception at Runtime, vary in different app.
use like this in your Activity:
public class MainActivity extends AppCompatActivity {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
...
}
and this in your build.gradle :
android {
...
defaultConfig {
....
vectorDrawables.useSupportLibrary = true
}
}
and in your xml:
app:srcCompat="@drawable/your_icon"
Ok, i just solved my problem, the problem was my gradle outdated and my sdk , so if anyone is running with this problem just do this steps
1.- Make sure your libs are updated as piotrek1543 says above 2.- Update your sdk if is necesary 3.- Update your gradle files (VERY IMPORTANT) just go to the project gradle and add this
classpath 'com.android.tools.build:gradle:2.1.0'
then go to your app project > app > graddle > graddlewrapper.properties and add
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
4.- change your compile compileSdkVersion to 24 and your buildToolsVersion "24.0.2" (MAKE SURE YOUR DEPENDENCES ARE UP TO DATE WITH THE SDK)
Have fun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With