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.
Related
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
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 research material design project for 4.x API, It seem too many problems in style values, always style.... (in v-21) not found. I think v-21 is only build with api 21. But I want to build for 4.x API, do anyone know problem?
Here is some project in Github i found:
https://github.com/wasabeef/awesome-android-ui
https://github.com/rey5137/material
I use eclipse too. Change ANdroid API 21,22,23 but it still not work
The Log say : no resource found that matches the given name "TextAppearance.Appcompat.Body1"
Here is my picture:
OTHER QUESTION:
The Author say this material project can run on API 2.x -> 4.x , but why it need to build with API 21 -> 23? So can lower device can run it?
Set compileSdkVersion 23 or 21 or above in your build.gradle file.
The Log say : no resource found that matches the given name
"TextAppearance.Appcompat.Body1"
This is because you might not have imported AppCompat Library to your Eclipse Project.
The Author say this material project can run on API 2.x -> 4.x , but
why it need to build with API 21 -> 23? So can lower device can run
it?
Yes, Its always a good practice to build your App with the latest API version as this will include all the updated resources which might be not available in previous versions of Android. However, this will not affect your APK size in anyways.
As per guidelines here for Android L development, I used android:elevation property in my application, but it shows the following error:
No resource identifier found for attribute elevation in package
android
I am using eclipse and I have downloaded the latest version just 2 days ago.
I have also set my target sdk as API level 21 and minimum as API level 14. I have also installed the latest updates on sdk-build tools shown in sdk manager.
Anyone know the solution? plz help me.
1) Select Project > Right Click > Properties > Check Android L > apply > Ok
2) android:minSdkVersion="L"
Hope this will work for you.
One thing worth noting is that Android Lollipop corresponds to API level 21. There is no such thing (yet) as API level 22.
You should be able to solve your problem by setting android:minSdkVersion and android:targetSdkVersion to "21".
Select Project, then Properties, then Android and tick Android 5.0. Ignore all the answers telling you to set android:minSdkVersion. Android is designed to ignore stuff inside elements it does not understand just so that in this case you can apply elevation when running on lollipop devices and it is ignored on earlier devices.
You can hide the remaining lint warning in the xml file by adding tools:ignore="NewApi" in the element. This needs xmlns:tools="http://schemas.android.com/tools" specified in the root element.
AppCompat v21 allows a fair bit of Material Design to be used on pre-lollipop devices, but I've yet to work out how to add it to a project in Eclipse.
android:elevation or View.setElevation() is introduced since Android API 21. So, if you set android:minSdkVersion="14", it's not OK. android:minSdkVersion="14" is integrant.
I don't use this attribute in any xml file, even if when I set "2.3.3" android version to my project properties, I get this error.
(If I set 4.1 clean works. But I want to find out why the app crash on real phone, so I tried to set to 2.3.3. The app doesn't crash on Android 2.2 Emulator)
And this one:
Bad XML block: header size 63322 or total size 142711912 is larger than data size 0
Suggestions?
This is typical of declaring a target version lower than 11 (Honeycomb). Some features are only available from 11 onward (same as Theme.Holo).
Change that in PROJECT > PROPERTIES > ANDROID (dont worry, it can hang for up to 10 minutes, check your sysMonitor, as long as eclipse is eating up CPU time, you are fine).
You may also have to change your version in your AndroidManifest.xml file
Solved.
I found out the problem by myself.
I checked the xml file and deleted the reported attribute.