Issue
I added a vector asset to a wear os project using and cannot access it using:
ContextCompat.getDrawable(mContext,R.drawable.ic_settings);
It does not seem to be finding the asset. I have the Drawable directory and see the assets in it. I opened up the xml file and there is an error:
"The drawable 'ic_settings' in drawable has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier"
I have no idea what this means. I just added it using the New -> Vector Asset menu. Does anybody know how to solve this issue?
Here is where it is in android studio:
Furthermore I have a roundbutton.xml in the drawable directory which is referred by R.drawable in another pice of code, and which there are no errors.
UPDATE
After doing all the checks (is the asset in the drawable directory), I closed and restarted Android Studio and it recognized them. Ye ol' reboot. Thanks to all for the responses. I am going to select the one which helped the most as the answer.
Solution
The problem is that your asset is specific to a certain configuration, so if the configuration doesn't match with device settings then the drawable can't be found by resource and will lead to a crash.
Some variants are:
- drawable (base, if not found in any folder)
- drawable-ldpi (low-resolution devices will look into it)
- drawable-mdpi (medium-resolution devices will look into it)
- drawable-v24 (devices with API level v24 or v24+ will look into it)
For more info, you can see: https://developer.android.com/training/multiscreen/screendensities
To Fix it:
Goto Android window and expand app > res > drawable, find the drawable, and right-click on it. From the menu goto Refactor > Move File...
From the text edit box remove the substring after the word "drawable" (in the image you can see "-xxxhdpi" after the drawable word which we should remove) and press Refactor.
Now, you're good to go.
Answered By - Tareq Joy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.