I’m working on a project with minSdk 23 and compileSDK 31. I’m seeing an issue when running the app on API 23 where when loading a vector resource via
ImageVector.vectorResource(id = R.drawable.vectorID)
I receive an error
android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi-v4/vectorID.png
But I can load the drawable successfully using AppCompatResources.getDrawable(LocalContext.current, R.drawable.vectorID)
Looking at the build folder, folders drawable-[x][xx][etc]hdpi are generated with the xml converted to pngs. But there is no -v4 folders generated.
Why are api level 4 folders being generated for a nexus5 api 23 device? Didn't androidx drop all these version tags? Furthermore, any suggestions on how to get around this?
Appcompat version is androidx.appcompat:appcompat:1.3.1
Related
This question already has answers here:
References to other resources are not supported by build-time PNG generation
(9 answers)
Closed 10 months ago.
I downloaded an icon from google Material.io. while trying to build my project after integrating it, I ran into the error that says: Can't process attribute android:fillColor="#android:color/white"
Here is a screenshot:
In the app build.gradle add the following line within the android section:
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
Check This For Further Detail :Vector drawables overview
Open the drawable you downloaded and replace android:fillColor="#android:color/white" with android:fillColor="#ffffff". In vector drawables the fillColor attribute must be set explicitly and not reference other resources
There are two ways to fix this.
One quick option is to go to the problematic XML file and change android:fillColor="#android:color/white" to android:fillColor="#FFFFFF". The error would disappear immediately. However, this problem would still recur if you have any other file with a similar line in the future.
Here's permanent solution:
Go to your build.gradle file and add this:
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
Sync and the error would disappear immediately.
You should use AppCompatTheme to access to ?attr/colorControlNormal
AS 3.3.2 / gradle-4.10.1
I had the same compiler problem:
Error: java.lang.RuntimeException: java.lang.RuntimeException: Error while processing .../main/res/drawable/ic_white_set.xml : Can't process attribute android:fillColor="#color/selector_tab_color": references to other resources are not supported by build-time PNG generation.
I opened the incriminated file and got the following Lint warning:
Resource references will not work correctly in images generated for this vector icon for API < 21; check generated icon to make sure it looks acceptable.
Inspection info:Vector icons require API 21 or API 24 depending on used features, but when minSdkVersion is less than 21 or 24 and Android Gradle plugin 1.4 or higher is used, a vector drawable placed in the drawable folder is automatically moved to drawable-anydpi-v21 or drawable-anydpi-v24 and bitmap images are generated for different screen resolutions for backwards compatibility. However, there are some limitations to this raster image generation, and this lint check flags elements and attributes that are not fully supported. You should manually check whether the generated output is acceptable for those older devices. Issue id: VectorRaster
Then I checked my build.gradle files and, sure enough, they all had minSdkVersion to 16.
So, as an alternative to the #Bhavesh Moradiya solution, I set minSdkVersionto 21 and the problem was solved.
The drawback is that you lose support for devices with SDK < 16 though.
I'm using svg format icons in my app. my application's minimum API level is 21 and target is 24. I knew that I can convert svg format icons into usual android vectors by android studio's "Vector asset" tool. ( which is accessible if you right-click on res/drawable directory -> new -> vector asset. )
Created vectors by this approach result well in android api higher than 21. but it causes app crashing in android 5 devices. though in google's documentation on vector assets it is said that vector assets are supported on api level 21 and higher.
Is there any idea that what can I do with this?
here's a sample of errors while app is trying to inflate an activity/fragment xml and a vector asset causes the crash:
android.view.InflateException: Binary XML file line #26: Error inflating class ImageView
After upgrading to Android Studio 3.1 my project will no longer build, giving me an error pointing to one of my VectorDrawables defined in xml:
Error while processing /Users/richard/project/app/src/main/res/drawable/name_of_drawable.xml : null
Any ideas how to fix this?
This will happen if your XML drawable is using unsupported XML attributes. Navigate to the drawable that is reporting the issue and you will probably see an error like: Attribute endX is only used in API level 24 and higher (current min is 23).
There are a few ways to fix this. You can either bump your minSdkVersion to a higher version, remove the attributes that are causing the errors, or put the drawable in a specific version resource folder, e.g. drawable-v24.
I used Android studio 2.3 version before and now updated to 3.0 stable version and target version 25 to 26. I kept all my customs fonts Assets folder
I am using it in my xml like:
app:font="font_regular.ttf"
using
compileSdkVersion 26
buildToolsVersion "26.0.2"
minSdkVersion 16
targetSdkVersion 26
renderscriptTargetApi 26
When I am trying to use my custom fonts which are in Assets folder it's was worked fine before 3.0 but now it's showing error like:
Error:(17, 19) String types not allowed (at 'font' with value 'font_regular.ttf').
Any suggestions
Hey got quick solution by referencing from developer Doc
Android 8.0 (API level 26) introduces a new feature, Fonts in XML, which lets you use fonts as resources. You can add the font file in the res/font/ folder to bundle fonts as resources. These fonts are compiled in your R file and are automatically available in Android Studio. You can access the font resources with the help of a new resource type, font. For example, to access a font resource, use #font/myfont, or R.font.myfont.
So I moved all my fons in to font folder inside the res
Now am using it like:
app:font="#font/font_regular"
I'd like to customize one drawable e.g.
/drawable/image.png
only for APis 19 to 21. For later APIs (after 22 incl. I'd like a drawable to be different). Do I need to create directories
drawable-v19,
drawable-v20,
drawable-v21,
drawable-v22 (for the others?)
? It's a bit unclear to me how it works...
You should only need to create directories for the versions that set a different resource. So your resources directory would look something like:
res/
drawable/ --> SDK version below 19
image.png
drawable-v19/ --> SDK version between 19 and 21 (including both)
image.png
drawable-v22/ --> SDK version 22 and greater
image.png
Edit: Seems to be working this way. I've set up a small project with strings.xml for sdk 19 and 22, launched two emulators, with sdk 21 and 25. The SDK 21 one showed the string in the v19 strings, and the SDK 25 the one in v22 strings. Here's a pic with the results:
Hope it helps. (Couldn't test it with sdk lower than 19, but that should take values from the default file, since no qualifier applies.)
You can create drawable folders like drawable-v19, drawable-v20, drawable-v21, drawable-v22 for each custom images for each versions. If the app is running on one of these devices it picks from these matching version custom respective folders or else falls back to the generic drawable folder.