Vector Drawables flag doesn't work on Support Library 24+
Asked Answered
A

7

23

Today, it seems as though Android Nougat was released. Thus, I am more excited than ever to optimize my app for the new features like split-screen. I would like to push a version of my app that targets SDK version 24 so that users aren't notified that my app may not work in split-screen. However, doing so means that I should also update to version 24 of the Support Library. Like many others, I experienced a problem when updating to version 23.2.0 of the Support Library. However, I followed this answer and it fixed my issue. Now the issue is returning as of version 24.0.0 and up of the Support Library. In all of my tests I am using the gradle flag described in the linked answer:

vectorDrawables.useSupportLibrary = true

It is also important to note that this is only happening on pre-Lolliop devices (Kitkat and below). Lollipop and up works perfectly. When using the following dependencies, the flag works fine:

compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'

But when using these dependencies, I get a crash similar to the one I got before using the flag:

compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'

Here is the stack trace of the crash:

FATAL EXCEPTION: main
Process: com.badon.brigham.time, PID: 2070
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.badon.brigham.time/com.badon.brigham.time.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
      at android.app.ActivityThread.access$800(ActivityThread.java:135)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5017)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
      at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f
      at android.content.res.Resources.loadDrawable(Resources.java:2101)
      at android.content.res.Resources.getDrawable(Resources.java:700)
      at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:182)
      at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:717)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:187)
      at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
      at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
      at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
      at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
      at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
      at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
      at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
      ...

Am I totally missing something? Or is this already a known issue (I couldn't find anything on Google)? Any help would be appreciated.

Alfie answered 23/8, 2016 at 2:44 Comment(5)
That looks like the resource couldn't be found, make sure it is in the correct folderFortuitous
Is this happening in Debug version of app, or only in Release?Brace
@JorgeMendez It's actually a resource that can't be found internally within the Support Library. It has to to with the new vector capabilities for pre-Lollipop devices. More HereAlfie
@Brace I am having this problem in the Debug version of the app - let me see about the Release version.Alfie
@Brace Yup, release too.Alfie
A
30

Ugh... I hate it when this happens. You ask a question and then answer it yourself a few hours later. Anyways, it appears as though I was using an outdated build tools version. All I had to do was change one line in my gradle:

buildToolsVersion "24.0.1"
Alfie answered 23/8, 2016 at 15:57 Comment(5)
this did not fix my issue on pre-Lollipop APIs. I am using support lib version 24.2.0, build tools 24.0.2 and i am supplying --no-version-vectors when using aapt.Anzac
@HypotheticalintheClavicle Do you have the same stack trace and everything?Alfie
@Thanks. For me, compileSdkVersion was 25, but buildToolsVersion was 21.1.2. I correct it to 25.0.1 and workedJonme
didnt help me tooIdonah
The secret sauce here is that compileSdkVersion, buildToolsVersion, and the support library versions all need to be on the same major version number (all begin with the same major number, like 24, for example).Banksia
F
11

In addition to the Gradle configuration, for me the trick was to add this line within the activity onCreate():

@Override
public void onCreate() {
    super.onCreate();
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

Your build.gradle (project) if using version 2.0+ add below code in your build.gradle (app)

// Gradle Plugin 2.0+  
 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

and, if using version 1.5 add below in your build.gradle (app)

// Gradle Plugin 1.5  
 android {  
   defaultConfig {  
     generatedDensities = []  
  }  

  // This is handled for you by the 2.0+ Gradle Plugin  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
 }

and, of course within the layout files, you should use srcCompat attribute:

<ImageView  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  app:srcCompat="@drawable/ic_add"/>
Fidelfidela answered 2/2, 2017 at 15:53 Comment(6)
It works well for imageview but actually what i need for background image of textview, Please helpOscar
@shwetac I don't know if you can do that, but instead of only use a textView, you could try to use a imageView as a background image and a textView on top of it.Fidelfidela
moustard I used same android:background but got error.Oscar
I didn't try it, but I'm pretty sure you cannot do that, you must use app:srcCompatFidelfidela
This helped me fix an Android 4 issue with React Switch. Thanks!Hueyhuff
@Hueyhuff I’m glad to hear that.Fidelfidela
C
3

In 24.2.0 the v4 Support Library has been splitted by google into several smaller modules:

com.android.support:support-compat:24.2.0

Provides compatibility wrappers for new framework APIs, such as Context.getDrawable() and View.performAccessibilityAction().

com.android.support:support-core-utils:24.2.0

Provides a number of utility classes, such as AsyncTaskLoader and PermissionChecker.

com.android.support:support-core-ui:24.2.0

Implements a variety of UI-related components, such as ViewPager, NestedScrollView, and ExploreByTouchHelper.

com.android.support:support-media-compat:24.2.0

Backports portions of the media framework, including MediaBrowser and MediaSession.

com.android.support:support-fragment:24.2.0

Backports the fragment framework. This module has dependencies on support-compat, support-core-utils, support-core-ui, and support-media-compat.

You can see all the changes here

Carolynecarolynn answered 23/8, 2016 at 14:11 Comment(3)
This can't be the reason I'm experiencing the crash as I start seeing it as early as 24.0.0 . It is interesting, though, that at version 24.2.0 the xml file of the not-found resource changes which might have something to do with this "split".Alfie
Does this mean that if we remove com.android.support:support-v4:24.2.0 from our gradle file and add the 6 dependencies listed above we would technically get all of the same functionality?Wartburg
I'm seeing the same issue today after updating my project to 25.0.1 verison of support libraries. Honestly, the Android library maintainers have no excuse for yet another debacle in library design. There's no indication yet (i'll keep looking) about the library that I need to include so that my project can find abc_vector_test.xmlChela
C
2

So the answer to this problem is to remind Android maintainers that they've dropped the ball and ask them to fix their libraries.

The file abc_vector_text.xml is missing from the project at runtime, but the missing file won't be flagged in the build if your project isn't using it in the first place. The name of the file indicates it's just part of some test suite.

I'm using the following dependency: compile 'com.android.support:appcompat-v7:25.0.1'

Because this page indicates that the file is found in that library: https://github.com/dandar3/android-support-v7-appcompat/blob/master/res/drawable/abc_vector_test.xml.

and yet, I still see the error at runtime.

Notice that's a github link of a project that is not the official Android project. I can't seem to find the file in the official project build anywhere. Which, yet again, indicates this is just a problem of sloppy maintenance. Here's my stacktrace for comparison:

ontent.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.os.Looper.loop(Looper.java:137)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at java.lang.reflect.Method.invokeNative(Native Method)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at java.lang.reflect.Method.invoke(Method.java:511)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at dalvik.system.NativeStart.main(Native Method)
01-02 00:02:23.130 E/AndroidRuntime( 3037): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.content.res.Resources.loadDrawable(Resources.java:1953)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.content.res.Resources.getDrawable(Resources.java:660)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.ccc.lib.activity.LoggingAppCompatActivity.onCreate(LoggingAppCompatActivity.java:416)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.ccc.lib.debugMode.DebugModeActivity.onCreate(DebugModeActivity.java:95)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.ccc.lib.activity.IBusActivity.onCreate(IBusActivity.java:46)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at com.ccc.lib.activity.MainActivity.onCreate(MainActivity.java:173)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.Activity.performCreate(Activity.java:5104)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     ... 11 more
01-02 00:02:23.130 E/AndroidRuntime( 3037): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     at android.content.res.Resources.loadDrawable(Resources.java:1950)
01-02 00:02:23.130 E/AndroidRuntime( 3037):     ... 33 more
Chela answered 9/12, 2016 at 21:49 Comment(1)
Althought that is not the official release, that is a conversion of the AAR that Google releases into an Eclipse library project. See the notes in the REAMDE.md and you may be able to find the resource file in the AAR locally on your machine to confirm. github.com/dandar3/android-support-v7-appcompat/tree/25.0.1Bowlds
A
1

I had the same problem with dexguard. Add this line on your configuration file:

-keepresourcexmlattributenames vector/*
Agrimony answered 23/8, 2016 at 9:6 Comment(3)
I'm not using DexGuard. I am using ProGuard, but that is only enforced for release builds and my error occurs on debug builds.Alfie
@ialfa I assume you got that solution from my previous post. That was the reason I asked if it was in Release version only.Brace
@ialfa I'm happy I have helped someone!Brace
H
0

for me it was the old build tools wrapper in the project root build.gradle file

dependencies {
    ....
    classpath 'com.android.tools.build:gradle:2.1.2'
}

instead of

classpath 'com.android.tools.build:gradle:1.X.X'
Harty answered 19/2, 2017 at 11:37 Comment(0)
P
-2
 classpath 'com.android.tools.build:gradle:2.1.0'
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Punkah answered 27/8, 2016 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.