Reputation: 5911
I have a library project and an application project. Beside other things the libary project contains some png and some vector drawables. Now I can easily overwrite a png drawable in the application project by giving it the same name and it will be displayed correctly. This does not work with vector drawables, though: The app always shows the vector drawables defined in the library, both on Android 4 and 5. The app would never show the application project's vector drawables.
Google claims an application's resources always have priority over a library's resources:
Since the tools merge the resources of a library module with those of a dependent application module, a given resource ID might be defined in both modules. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or highest-priority library taking precedence.
But as I said, in case of vector drawables, for some reason, it's the other way round. Any idea what I can do to make sure the vector drawables are overridden just like normal drawables and other resources are?
UPDATE: Resolved in support library v23.2! Nothing to do now :)
Upvotes: 7
Views: 1750
Reputation: 5911
Based on the "NOTE" in Jared Rummler's answer and since this won't fit in a comment I'll post a little tutorial here for people who have trouble finding the generated PNG files:
You can find the folders with the required files inside build/intermediates/res/merged/debug
or, if you are using product flavors build/intermediates/res/merged/<flavor>/debug
. Now the least difficult way of copying the PNG files to the app would be to fully copy their folders, which are:
drawable-ldpi-v4
drawable-mdpi-v4
drawable-hdpi-v4
drawable-xhdpi-v4
drawable-xxhdpi-v4
drawable-xxxhdpi-v4
As a last and tedious step you should remove all files inside you don't need, i.e. those that aren't generated from your vector drawables. This is done easiest if you are using a VCS by adding only the PNGs you need. This places all redundant files under Unversioned Files.
And there you go, together with drawable-anydpi-v21 there are now 7 additional folders just because of this stupid bug :(
UPDATE: Resolved in support library v23.2! As of today, there is finally no need to do any of the above. Just make sure to use app:srcCompat instead of android:src everywhere.
Upvotes: 3
Reputation: 38131
When the library project is built, the VectorDrawable
creates PNG files for each density and places the original VectorDrawable
in drawable-anydpi-v21.
If you place your VectorDrawable
in drawable-anydpi-v21 in your app, then it will override the drawable from your library project. This seems like a bug and a new issue should be created (if one doesn't already exist).
NOTE: this will not replace the generated PNG files from the library. You will need to add those to your app as well to override them.
Upvotes: 11