Failed linking file resources

Android ResourcesAndroid Studio-3.0

Android Resources Problem Overview

This is the java file that is giving the error

package com.example.daksh.timetable;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        final Button mon_but,tue_but,wed_but,thur_but,fri_but;
        mon_but = (Button)findViewById(;
        tue_but = (Button)findViewById(;
        wed_but = (Button)findViewById(;
        thur_but = (Button)findViewById(;
        fri_but = (Button)findViewById(;
        final ImageView main_Image = (ImageView) findViewById(;
        final int[] dayarray = {R.drawable.monday,R.drawable.tuesday,R.drawable.wednesday,R.drawable.thursday, R.drawable.friday};

        mon_but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

        tue_but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
        wed_but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
        thur_but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
        fri_but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

The errors that I am getting are as follows

>Information:Gradle tasks [clean, :app:assembleDebug] C:\Projects\TimeTable\app\src\main\res\layout\activity_main.xml Error:error: resource android:attr/colorSwitchThumbNormal is private. Error:resource android:attr/colorSwitchThumbNormal is private. C:\Projects\TimeTable\app\src\main\res\layout-land\activity_main.xml Error:error: resource android:attr/colorSwitchThumbNormal is private. Error:resource android:attr/colorSwitchThumbNormal is private. Error:failed linking file resources. Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: AAPT2 error: check logs for details Error:java.util.concurrent.ExecutionException: AAPT2 error: check logs for details AAPT2 error: check logs for details Error:Execution failed for task ':app:processDebugResources'. > Failed to execute aapt Information:BUILD FAILED in 9s Information:9 errors Information:0 warnings Information:See complete output in console

This is the Activity_main.xml file

    <?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""


        app:srcCompat="@drawable/monday" />

        app:layout_constraintTop_toTopOf="parent" />

        app:layout_constraintTop_toTopOf="parent" />

        app:layout_constraintTop_toBottomOf="@id/mon" />

        app:layout_constraintTop_toBottomOf="@id/tue" />

        app:layout_constraintTop_toBottomOf="@id/wed" />

        app:layout_constraintTop_toBottomOf="@id/thur" />

        app:layout_constraintGuide_end="196dp" />

        app:layout_constraintGuide_percent="0.15339233" />


Android Resources Solutions

Solution 1 - Android Resources

You maybe having this error on your java files because there is one or more XML file with error.

Go through all your XML files and resolve errors, then clean or rebuild project from build menu

Start with your most recent edited XML file

Solution 2 - Android Resources

If anyone reading this has the same problem, this happened to me recently, and it was due to having the xml header written twice by mistake:

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?> <!-- Remove this one -->
<shape xmlns:android="">
     <solid android:color="@color/mug_blue"/>
     <corners android:radius="@dimen/featured_radius" />

The error I was getting was completely unrelated to this file so it was a tough one to find. Just make sure all your new xml files don't have some kind of mistake like this (as it doesn't show up as an error). EDIT It seems like it shows up as an error now, make sure to check your error logs.

Solution 3 - Android Resources

One possible solution I already mentioned in a comment:

> I had an issue in XML file that IDE did not highlight. Had to ask my > colleague to compile for me and it shown in his IDE. Buggy Android > Studio.

But I found a way around that.

If you go to Gradle panel on the right. Select your desired module, eg. app, then under build select assembleDebug it will show you all errors in stdout.

enter image description here

Solution 4 - Android Resources

Look at the error you are getting:

> C:\Projects\TimeTable\app\src\main\res\layout-land\activity_main.xml Error:error: resource android:attr/colorSwitchThumbNormal is private.

It means that in your activity_main.xml you are referencing the color "android:colorSwitchThumbNormal", but inside the 'android' namespace that resource is private. What you probably meant to do is try to reference that color from the support version of this attribute, so without the "android:" prefix.

<item name="android:colorSwitchThumbNormal">@color/myColor</item>

Replace with:

<item name="colorSwitchThumbNormal">@color/second</item>

Solution 5 - Android Resources

Run ./gradlew build -stacktrace in Android Studio terminal. It helps you to find a file that causes this error.

Solution 6 - Android Resources

It's Obvious that if you have a big project, it will be a nightmare to check each and every xml file.

Run the following command in android studio terminal and it will give you the filename with the issue

gradlew build --stacktrace

enter image description here

Solution 7 - Android Resources

This message means there is a syntax error in your XML file. If Logcat cannot pinpoint the error with a friendly log message with the xml file name, try cleaning the project and rebuilding the project. It worked for me.

In the Build tab, you will get a node named Android Issues.

The error message explaining the error with the XML file is under it.

Solution 8 - Android Resources

To be more generic about the answer provided by @P Fuster. There can be error in your xml files.

I encountered the same error and was having error in the drawable where end tag was missing.

Solution 9 - Android Resources

Error is associated with some issue with .xml file. Manually open each xml format file to check for error. I had same issue. Had to manually open each file. There was an error in @string call.

Solution 10 - Android Resources

It is a xml error for some reason may be because of deleting a view or string in another view or may be for missing " or /> ..... etc

But here I am using a good technique to figure out where is the problem exactly :-

  • Go to every single xml file and minimize the root element if you find something like this so you got where is the error, fix it then repeat the process for all files.

  • If the file has an error you will see three dots with red color enter image description here
  • Fix the error here I removed this line because this array is not in the string file any more. enter image description here
  • Now you can see there is no error in this file any more if you still got the main error so you have to repeat this process again to all xml files until you solve the error enter image description here

I know it is not the solution of the main problem but it will make you find where is the error quickly and save you time.


There is another way you can find out easily, as Bennik2000 write in comment, you can look at the right scrollbar for red lines, they also indicate errors.


I found a very simple way to get where is the error exactly if it is in resource file or even java file.
1- Go to Project Window.
2- Open the file that has the error.
3- Click F2 to go to the nearest error appears (it will go to the correct line)

enter image description here

Solution 11 - Android Resources

Check your XML files for resolving the Errors.Most of the time the changes made to your XMLfiles get try to check the last changes you made.

Try to Clean your Project....It Works

Happy Coding:)

Solution 12 - Android Resources

I know this question has been answered already, however, I still would like to add to what a lot has posted here for others having a similar but not specific problem.

This error sometimes also comes as “Android resource linking failed”. It is sometimes vague. The solution sometimes could be quite boring and painful but, this error is absolutely nothing serious.

In this case, the error is not Vague because Android Studio pointed to the problem file.

General Cause 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.

Solution To solve this problem, 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 XML.

You might be lucky and Android Studio will point you in the exact direction just like the one asked in the question......

Other times like when you are using an older version of Android Studio, the error would not be this specific.

Here are some 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 the exact line.

Solution 13 - Android Resources

I was having the same issue. It was due to a typo in an attribute in one of my XML file. Anyways, Android Studio did not specify the source of the error in the first run. But when I did a

> Build -> Clean Project

and then ran the app again it showed me the exact line in the XML code where the typo was.

Solution 14 - Android Resources

I have this problem.The main problem was i added an attribute to an BottomAppBar in the xml file.I found error message in android bottom build section explained that error i replaced the attribute and every thing was ok. For others who have the same error but my solution not ok with them you have to read the error message it will guide you to the pain point.

Solution 15 - Android Resources

In my case, I made a custom background which was not recognised.

I removed the <?xml version="1.0" encoding="utf-8"?> tag from the top of those two XML resources file.

This worked for me, after trying many solutions from the community. @P Fuster's answer made me try this.

Solution 16 - Android Resources

This might be useful for someone who is looking for a different answer. Go to the Gradle Panel and select your module -> Task -> Verification -> Check.

This will check the project for errors and will print the log where the error occurs. Most of the time this Kind of error must be a typo present in your XML file of your project

Solution 17 - Android Resources

It can also occur if you leave an element with a null or empty attribute in your XML layout file else if your java file's path of objects creation such as specifying improper ID for the object

enter image description here

here frombottom= AnimationUtils.loadAnimation(this,R.anim); in which anim. the id or filename is left blank can lead to such problem.

Solution 18 - Android Resources

This similar error may also show if you have deleted an Activity java file previously and have not deleted the corresponding xml layout file.

Delete the xml file for the deleted Activity java file and Clean or Rebuild the project.

The reason behind it may be because of the mismatch of context in the xml. (This might occur if you are copy-pasting an xml layout code) Match the tools:context to the java file of the activity.


Solution 19 - Android Resources

I was doing Temperatur Converter App.I was facing same error while running the app as: Android Studio linking failed. In String.xml a line was missed, I included the line. It went fine without any errors.

Before Correction

<color name="myColor">#FFE4E1</color>
<string name="Celsius">To Celsius</string>
<string name="fahrenheit">To Fahrenheit</string>
<string name="calc">Calculate</string>

After editing:

<string name="app_name">Temp Converter</string>
<color name="myColor">#FFE4E1</color>
<string name="Celsius">To Celsius</string>
<string name="fahrenheit">To Fahrenheit</string>
<string name="calc">Calculate</string>

Solution 20 - Android Resources

Sometimes it happen what you copy paste code from another project fro example you copy

        app:menu="@menu/activity_main_drawer" />

Unfortunately Android studio not always show dependency error, but what happen is that class NavigationView is missing because implementation ' not added to the project

Solution 21 - Android Resources

This sometimes happens when you have a random XML file doing nothing. Removing the file resolves the issue.

Solution 22 - Android Resources

-May be the problem is that you have deleted .java files doing this doesn't delete the .XML files so go to res-> layout and delete those .XML files that you had delete before. -the another problem may be you haven't delete the files that is present in manifests under syntax that you deleted recently... So delete and run the code

Solution 23 - Android Resources

I had the same problem but it occured in all my projects, I tried Invalidate Cache / Restart but even it doesn´t solved the problem.

At the end I realized that in my Gradle Settings, Offline Work was enabled.

Go to Build, Execution, Deployment > Gradle in Gradle Settings unchecked Offline Work.

enter image description here

It solved the the problem downloading some configuration files for my Android Studio.

Solution 24 - Android Resources

My error was in a xml drawable file. I had the first liner duplicate. Changing it to this worked for me:

<?xml version="1.0" encoding="utf-8"?>

Solution 25 - Android Resources

Add agian your deleted drawable image .jpg/png etc formate. enter image description hereand Then run your project to fine working on android studio 3.6.1

Solution 26 - Android Resources

I got this error due to 2 lines with the same content but different capitalization:


Android Studio 2020.3.1 does not mark this as an error in the xml file, but will throw the resource linking error when trying to build


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaksh BaradView Question on Stackoverflow
Solution 1 - Android ResourcesAngaView Answer on Stackoverflow
Solution 2 - Android ResourcesP FusterView Answer on Stackoverflow
Solution 3 - Android ResourcesarenaqView Answer on Stackoverflow
Solution 4 - Android ResourcesIzabela OrlowskaView Answer on Stackoverflow
Solution 5 - Android ResourcesAnton BevzaView Answer on Stackoverflow
Solution 6 - Android ResourcesMinionView Answer on Stackoverflow
Solution 7 - Android Resourceslive-loveView Answer on Stackoverflow
Solution 8 - Android ResourcesMohammed RampurawalaView Answer on Stackoverflow
Solution 9 - Android ResourcesadityaView Answer on Stackoverflow
Solution 10 - Android ResourcesKhalid AliView Answer on Stackoverflow
Solution 11 - Android ResourcesGaurav LamboleView Answer on Stackoverflow
Solution 12 - Android ResourcesFincoAppsView Answer on Stackoverflow
Solution 13 - Android ResourcesAnuj KumarView Answer on Stackoverflow
Solution 14 - Android ResourcesEL TEGANI MOHAMED HAMAD GABIRView Answer on Stackoverflow
Solution 15 - Android ResourcesAnanthView Answer on Stackoverflow
Solution 16 - Android ResourcesThiyaguView Answer on Stackoverflow
Solution 17 - Android Resourcesrevanth srinivasanView Answer on Stackoverflow
Solution 18 - Android ResourcesShitabView Answer on Stackoverflow
Solution 19 - Android ResourcesSreenidhi D RView Answer on Stackoverflow
Solution 20 - Android ResourcesPavel PoleyView Answer on Stackoverflow
Solution 21 - Android ResourcesMohamed AliView Answer on Stackoverflow
Solution 22 - Android ResourcesadarshView Answer on Stackoverflow
Solution 23 - Android ResourcesJorgesysView Answer on Stackoverflow
Solution 24 - Android ResourceslarsaarsView Answer on Stackoverflow
Solution 25 - Android ResourcesLakshman JodhawatView Answer on Stackoverflow
Solution 26 - Android ResourcesJ7bitsView Answer on Stackoverflow