[SOLVED] Android resource linking failed Error: failed linking file resources.
- Posted by Finco Agbontaen
- 2 Comments
- Categories: Android Errors & Solutions, Tutorials
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.
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.
Note the “android:endCollor” attribute.
Solution
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.
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. 🙂
Источник
Failed linking file resources
This is the java file that is giving the error
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: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:com.android.tools.aapt2.Aapt2Exception: 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
26 Answers 26
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
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:
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.
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.
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.
Run ./gradlew build -stacktrace in Android Studio terminal. It helps you to find a file that causes this error.
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
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.
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.
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.
Источник
Error — Android resource linking failed (AAPT2 27.0.3 Daemon #0)
I have this error
I am try reinstall android studio and remove .gradle folder , any solution please?
33 Answers 33
The Android resource linking failed error can also appear if you have an error in any of your XML resources. In my case I was using the following line twice in one of my XML drawables in drawable folder:
I removed the duplicate line and the error disappeared. The error was a bit misleading:
Android resource linking failed Output: /Users/johndoe/Desktop/myapp/app/src/main/res/layout/activity_main.xml:2: error: resource drawable/bg_main (aka com.example.myproject:drawable/bg_main) not found.
According to the above error, the first thing you need to do is to proof read all the drawable resources that are accessed in the activity_main because the chances are higher that you will find the error. In the worst case scenario you might end up checking all your resource files.
Had exactly the same problem. Solved it by doing the following: Searching for and replacing com.android.support:support-v4:+ with com.android.support:support-v4:27.1.0 in the platform/android directory.
Also I had to add the following code to the platforms/android/app/build.gradle and platforms/android/build.gradle files:
Edited to answer «Where is this com.android.support:support-v4:+ setting ?» .
The setting will probably(in this case) be in one of your plugin’s .gradle file in the platform/android/ directory, for example in my case it was the starter-barcodescanner plugin so just go through all your plugins .gradle files :
Double check the platforms/android/build.gradle file.
Hope this helps.
Note: Android Studio spits out a load of crazy errors like this if you upgrade the support libraries to 28.0.0 and your compileSdkVersion is not 28 also.
Problem fixed for me by replacing compileSdkVersion 23 with compileSdkVersion 28 in build.gradle (Project: build) .
If you are using Windows 10, and Android Studio 3.2, you can simply go to the app’s build.gradle, and change the version.
In your layout (xml) files almost every element has a property i.e. «id» which, can be assigned in order to refer to it from the java/kotlin code or from the xml itself.
Now sometimes or in some versions of Android Studio errors in xml files is either not reported or some random error is thrown while compiling, of which, this thread is an example i.e. when assigning an id to an element or when refering to another element in the layout we use the ID but ids are not just written like any other word rather they are prefixed by these characters: @+id/ , otherwise the above error is thrown.
Hence the solution below should be considered:-
I resolved it by adding @+id/ before all my IDs.
feel so stupid — (for whatever reason) i had one empty xml in drawable folder. and AS produced dozens of unrelated errors >
com.android.support:support-v4 just recently got update and maybe affect to plugin that use updated version in their dependencies. But if you cannot find in the dependencies (like if you use crosswalk plugin), just put this code in top of your code gradle plugin (no need to add on build.gradle).
Example location to put the code in crosswalk plugin here
Feel free to edit version of com.android.support (DO NOT USE THE 28.0.0) because thats the problem
I imported new colors to my project and got the same problem. So I opened styles.xml and re-assigned items to colors using new colors names.
I had the same problem and solved it by going to File -> Project Structure. -> Suggestions and then Apply all. Like suggested by @JeffinJ I think the problem was because of the Gradle plugin update.
There should be some error in resource files. It mean is there may be miss typed value of attributes. Go through the resource files and correct these value and enjoy the work.
There can be multiple reasons for this problem and these reasons are mainly in the resource or app level build.gradle file.
In my case, a view in the resource file didn’t had the required dependency included in the build.gradle file.
So, make sure to include all the required dependencies in the build.gradle file.
Check your Gradle plugin version. Try downgrading it if you have updated to a newer version just before this issue showed up. Go to File -> Project Structure. Change to the previous version.
Try update latest build version, target and compile version and also update dependencies but not works for me
In my case change to in manifest works for me.
Hope its helpful for someone.
I had the same problem, but it was because in my buttons layout_width/height I forgot to put dp at the end when editing them. Added dp and problem fixed :/
For me, the error appeared after changing my launcher icon using Asset Studio. Turns out that the ic_launcher_foreground.xml file that was generated was missing the following line at the top of the file:
In my case I accidentally wrote:
Interestingly, Android Studio were able to navigate the string via CTRL+click. It was just giving Build Time error. Changing to standard «dot seperation» did the trick
Found one of the reasons which causes this problem
When we try to use any
in manifest file that is not present in values (string.xml,style.xml,color.xml,etc,) then this type of error occurs
i got the same bug, and i fixed it when i close the AndroidStudio and delete the dir like C:\Users\Jalal D\.gradle\caches\transforms-1\ in the build error info.
I was missing this line at the top of one of my XMLs:
I was having similar problem but I came out of the solution the problem was that you were using any thing in the dependency that correspond to same domain but with different versions make sure those all are same
I was facing same issue and it is resolved by removing error from resource files like style, colors files in values folder. In my case, error in style colors as below:
Changing the version of the support library of the last one enabled (28.0.0) by the previous (27.1.0), the error Android Resource Linking Failed disappeared.
It should be noted that version 27.1.0 is the maximum allowed in our implementations, which works, but you could use an older one if you wish. And this has to be used in all dependencies that start with the string com.android.support:
project/app/build.gradle
project/build.gradle
Then, Sync Project with Gradle Files
Same issue occurred for me, but before getting this error, my app was running. So I just did undo 2/3 times. And did changes again. And build app.app ran successfully.
I’ve come across the same issue after adding the following dependency:
And the reason was that latest version of evernote uses dependencies to AndroidX, while I had support library version 27.1.1 in my project. So there was an option of upgrading support libraries to 28.0.0, as the other answers suggest, but that was a bit tricky for a large project with lots of custom views. So, I resolved the issue by downgrading evernote version to 1.3.1.
It may sound banal, but for me Build > Clean Project fixed this error without any other changes.
I’m using Studio 3.3.1 Build from Jan 28.
For me I was getting the «error android resource linking failed» pointing to a line in a layout file using ConstraintLayout that had been working correctly until today when the only change to my app level gradle file was to update the versions of:
from 1.0.0-rc01 to 1.0.0-rc02 .
The error message said something about not recognizing layout_constraintTop_toTopOf which of course is silly because it had been compiling quite happily for months.
I am already on 28.0.3 of build tools and compileSdkVersion of 28. I’ve been using androidx.appcompat everywhere for a while now (converted this project months back to androidx).
I first went through a project clean (no help), and invalidating cache/restart (no help). The layout in question had been originally defined using
, and components (which had been working fine until today).
But after reading the above answers I thought maybe somehow there was confusion being caused here so I changed the layout to use:
versions of all the various components. No change — still got the error.
So something strange in that widget definition I thought. here is what it was:
I then pasted back the block I had Ctrl-V cut previously and changed the references back to that ID in the other components that reference it in the layout. Compile failed.
I cut the block again and pasted it to WordPad. Then reading from the WordPad paste, I actually typed it back in (i.e. I didn’t copy/paste this time) — line by line, doing a make on the project after I typed in the minimal definition, and then again thereafter when I put in each new line. Each time the project compiled cleanly!
I don’t know what to make of this. Perhaps some spurious invisible character was in the file originally?
Источник