This error sometimes also comes as “Android resource linking failed” is another frequent and vague error in Android Studio. The solution sometimes could be quite boring and painful but I assure you, this error is absolutely nothing serious.
The error shows up when Gradle encounters an error (Usually a syntax or typo error) in one or more of your XML files.
Most of the XML files are located in the res folder, however, you might still find some outside the res folder. For example, the AndroidManifest.xml located in “/src/main/AndroidManifest.xml”. Here is an example of a layout file that would give the “Error: failed linking file resources” error.
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="https://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="90" android:centerColor="@color/colorPrimaryDark" android:endColor="@color/colorPrimaryDark" android:startColor="@color/colorPrimaryDark" android:endCollor="@color/colorPrimaryDark" android:type="linear" /> <corners android:radius="10dp"/> </shape>
Note the “android:endCollor” attribute.
The solution to the error is obvious, right? All you have to do is go through each of your XML files to figure out where the error might be. This could sometimes be time-consuming but be rest assured that the error will disappear as soon as you find and fix the problem child (problem XML).
You might be lucky and Android Studio will point you in the exact direction as shown in the screenshot below:
Other times like when you are using an older version of Android Studio, the error would not be this specific.
Tips to finding the problem XML quickly
If you have a lot of XML files and it would be just too difficult to go through them one after the other, you could use the following tips to make the process easier:
- Undo: Most times, you are already halfway through a project before you experience this issue. Meaning that it was a recent change to one of your XML files that caused the issue. If that is the case, you can try to undo your recent change to the XML files. To undo, simply use the key combination: Ctrl+Z.
- Open every XML file: The second method involves simply opening every single XML file in your project (Without scanning). The reason for this is that sometimes, after opening the problem XML file, Android Studio then detects the error and underlines it.
And that’s it.
If you enjoyed this post, feel free to share it. If you have any questions, feel free to ask them in the comment box below. 🙂