If Android Studio shows Android resource linking failed, the message usually means the Android build tools found a problem while processing or connecting your app’s resources.
The error can look alarming because the final line is often very general:
Android resource linking failed
The real cause is usually a few lines above it.
You may see a more specific message such as:
error: resource style/Theme.AppCompat not found
error: attribute colorPrimary not found
error: resource drawable/ic_launcher not found
error: style attribute ... not found
error: resource android:attr/lStar not found
These errors do not all have the same fix. A missing theme usually points to a dependency problem, while an unknown android:attr can indicate a compileSdk mismatch. A malformed XML file or incorrectly named resource can also cause the same overall Android resource linking failed message.
The key is to read the first specific resource error rather than trying random fixes.
This guide explains what Android resource linking failed means, why it happens, and how to fix the most common AAPT2 resource linking errors in Android Studio.
What Does Android Resource Linking Failed Mean?
Android uses resources for items such as:
- Layouts
- Colors
- Strings
- Drawables
- Themes
- Styles
- Fonts
- Menus
- XML configuration files
- App icons
During a build, Android’s resource tools process those files and connect references to the resources they point to.
The Android Asset Packaging Tool 2, usually called AAPT2, is responsible for compiling and linking Android resources. Android Developers explains that the linking stage merges processed resources and packages them for the app build.
When AAPT2 cannot resolve a resource, finds invalid XML, encounters an invalid reference, or detects incompatible resource definitions, the build can stop with Android resource linking failed.
In simple terms, Android is saying:
“Your project is referring to a resource that I cannot find, understand, or link correctly.”
The generic error is not enough to identify the cause. The important part is the detailed message that names the missing file, attribute, style, color, drawable, or Android framework resource.
For the technical background behind AAPT2, see the official Android Developers AAPT2 documentation.
Read the First Actual Error Before Trying a Fix
This is the most important step.
Do not focus only on:
Android resource linking failed
Instead, scroll upward in the Build output and look for the first error that names a specific resource.
For example:
error: resource color/colorPrimary not found
or:
error: attribute colorPrimary not found
or:
error: resource android:attr/lStar not found
The first specific error is often the root cause. Later messages may simply be consequences of the earlier failure.
If you have ten errors, fixing the first invalid resource can sometimes remove several of the others.
1. Check for a Missing Resource
A resource linking error often occurs because your code or XML refers to a resource that does not exist.
For example:
android:background="@color/app_background"
If app_background does not exist in your color resources, Android cannot link the layout.
Check the relevant resource folder:
app/src/main/res/
Then confirm the resource exists in the correct location.
Common folders include:
res/color/
res/drawable/
res/layout/
res/mipmap/
res/values/
res/menu/
res/font/
res/xml/
For example:
@color/app_background
should point to a valid color resource, while:
@drawable/logo
should point to a valid drawable resource.
Also check spelling carefully. Resource names are case-sensitive in the sense that Android resource naming rules require lowercase names, and a typo in the reference will prevent the resource from being found.
2. Check Resource File Names
Android resource files must follow strict naming rules.
A resource filename should generally use:
- Lowercase letters
- Numbers
- Underscores
These are valid:
app_logo.xml
main_screen.xml
button_background.xml
ic_settings.png
These can cause problems:
AppLogo.xml
main-screen.xml
button background.xml
ic@settings.xml
If you recently copied an image, XML file, or resource from another project, rename it to a valid Android resource name.
Then update every reference to the old name.
For example, if you rename:
AppLogo.png
to:
app_logo.png
the reference should become:
android:src="@drawable/app_logo"
not:
android:src="@drawable/AppLogo"
3. Check for an Invalid XML File
A single broken XML file can trigger Android resource linking failed.
The problem may be in:
- A layout file
colors.xmlstrings.xmlthemes.xmlstyles.xml- A drawable XML file
AndroidManifest.xml
Common mistakes include missing closing tags:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
when the element should either be closed with /> or have a matching closing tag.
Another common mistake is putting an invalid resource item inside a values XML file.
Open the file named in the Build output and look for:
- Missing closing tags
- Invalid nesting
- Duplicate resource names
- Invalid characters
- Incorrect namespaces
- Incorrect attribute values
Android Studio may highlight the exact line with a red underline, but the Build output should still be your main guide because it often tells you which resource failed during the build.
4. Fix Incorrect Resource References
Android resources must be referenced using the correct syntax.
A normal resource reference uses @.
For example:
android:background="@color/black"
android:src="@drawable/ic_logo"
android:text="@string/app_name"
A theme attribute reference usually uses ?.
For example:
android:textColor="?android:textColorSecondary"
Mixing these reference types can cause linking errors.
Android’s resource documentation distinguishes between normal resource references and style attribute references. A style attribute is resolved from the current theme, which is why it uses ? rather than the ordinary @ syntax.
Check the resource type expected by the property before changing the symbol.
5. Fix resource ... not found Errors
If the Build output says:
error: resource ... not found
the first question is simple:
Does that resource actually exist in the project or in one of its dependencies?
Suppose you see:
error: resource style/AppTheme not found
Check your res/values/ resources for a style named AppTheme.
A style may look like:
<resources>
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
</style>
</resources>
If the style was renamed but your manifest still references the old name, Android will fail to link it.
Check your manifest:
<application
android:theme="@style/AppTheme">
Make sure AppTheme exists and is spelled exactly as intended.
6. Fix attribute ... not found Errors
An error such as:
error: attribute colorPrimary not found
often means your project is using an attribute that is not available from the theme or library currently configured.
For example, older tutorials may use:
<item name="colorPrimary">@color/purple_500</item>
while the project may be using a different theme setup or missing the dependency that defines the expected attributes.
Before copying more code from another tutorial, check which UI system your project uses:
- Traditional Android Views with AppCompat
- Material Components
- Material 3
- Jetpack Compose
Do not assume that a theme snippet from an older AppCompat project will work unchanged in a newer Material 3 project.
The best fix is to use a theme and attributes that match the dependencies already configured for the project.
7. Fix resource android:attr/... not found
This error is often related to the Android SDK level used to compile the app.
For example:
error: resource android:attr/... not found
can occur when a dependency expects an Android framework attribute that is not present in the SDK platform selected by your project’s compileSdk.
Open the app module’s Gradle configuration and check the SDK version.
With Kotlin DSL, you may see:
android {
compileSdk = 36
}
With Groovy, the syntax may look like:
android {
compileSdk 36
}
The exact version should be appropriate for the current Android development setup and compatible with your Android Gradle Plugin and dependencies.
After changing compileSdk, install the corresponding SDK platform through Android Studio’s SDK Manager if it is not already installed.
Then sync Gradle and build the project again.
Do not confuse compileSdk with minSdk. compileSdk determines which Android APIs and framework resources are available to your app at compile time, while minSdk determines the oldest Android version your app supports.
8. Check Your AndroidX and Material Dependencies
Missing or incompatible dependencies can produce resource linking errors.
For example, an older project may reference an AppCompat or Material theme that is no longer declared in the app module’s dependencies.
Open the module-level Gradle file and inspect the dependencies.
A typical modern project might include AndroidX or Material dependencies such as:
dependencies {
implementation("androidx.appcompat:appcompat:...")
implementation("com.google.android.material:material:...")
}
The exact versions should not be copied blindly from an old article. Use versions compatible with your project’s Android Gradle Plugin and dependency setup.
If an error began immediately after adding a library, check:
- Whether the dependency was added to the correct module
- Whether Gradle sync completed successfully
- Whether the library requires a higher
compileSdk - Whether another dependency is pulling in an incompatible version
9. Check compileSdk, Android Gradle Plugin, and Dependency Compatibility Together
A resource linking failure is sometimes caused by a mismatch rather than one obviously missing file.
For example:
- A library expects a newer Android framework resource
- Your project uses an older
compileSdk - The Android Gradle Plugin is too old for the dependency setup
- Another library introduces incompatible resources
Do not update everything at once.
Instead:
- Identify the exact missing resource.
- Identify which dependency or framework provides it.
- Check the library’s requirements.
- Update the relevant SDK or dependency if needed.
- Sync Gradle.
- Build again.
Changing five build settings at the same time can make the real cause harder to find.
10. Check Your Theme Parent
A common error involves a missing or invalid parent theme.
For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
If the project does not include the library that provides that parent theme, Android cannot resolve it.
The same issue can happen when you copy a theme from an old project that uses a different UI framework.
Open your themes.xml or styles.xml and check:
- The style name
- The parent theme
- The dependencies that provide the parent
- The attributes used inside the style
Android Developers documents style resources as items stored under res/values/, with the style’s name used as the resource ID.
If the parent does not exist, fix the parent reference or add the correct supported dependency.
11. Check the xmlns Namespace in XML Files
Some resource errors come from missing or incorrect XML namespaces.
A typical layout begins with:
xmlns:android="http://schemas.android.com/apk/res/android"
If you use custom attributes, you may also need:
xmlns:app="http://schemas.android.com/apk/res-auto"
If you use tools: attributes, you need:
xmlns:tools="http://schemas.android.com/tools"
For example:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
If an attribute uses the app: prefix but the namespace is missing, the XML cannot be interpreted correctly.
Check the root element of the file and confirm every namespace used in that XML is declared.
12. Check for Duplicate Resource Names
Android projects can contain multiple resource configurations, but duplicate resources in the wrong location can cause conflicts.
Look for duplicate definitions such as:
<string name="app_name">My App</string>
appearing more than once in the same effective resource configuration.
Also check whether you accidentally created duplicate styles, colors, or IDs while copying code between files.
Android Studio’s Find in Files feature can help.
Search for the resource name and review every definition.
Do not delete alternative resources simply because they have the same name. Android intentionally allows the same resource name to exist in different configuration directories, such as language or screen-size alternatives. The problem is an invalid duplicate within the same configuration scope.
13. Clean and Rebuild the Project
Once you have corrected the specific resource problem, clean the project and rebuild it.
In Android Studio, use the Build menu to run a clean and then rebuild the project.
You can also build with Gradle from the command line.
For example:
./gradlew clean
Then:
./gradlew assembleDebug
On Windows, the command is commonly:
gradlew.bat clean
Cleaning can remove outdated build output, but it is not a cure for a genuinely missing resource.
Do not keep cleaning and rebuilding if the same specific error remains. Go back to the first detailed error and fix the resource it identifies.
14. Sync Gradle Again
If you recently changed:
- Dependencies
- SDK versions
- Plugin versions
- Gradle configuration
sync the project again before assuming the resource problem remains.
Use Android Studio’s Gradle sync option and wait for it to finish.
A dependency that was added to the Gradle file but never successfully resolved may lead to missing resources from that library.
Read the Gradle sync output as well. You may have a dependency-resolution error that happened before AAPT2 reached the resource-linking stage.
15. Invalidate Caches Only After Checking the Real Error
Invalidating Android Studio caches can help with an IDE indexing problem, but it should not be your first response to every resource linking error.
Use it after you have:
- Checked the exact Build output
- Fixed obvious XML errors
- Verified missing resources
- Synced Gradle
- Rebuilt the project
If the editor appears to show stale errors or Android Studio cannot recognize resources that are definitely valid, restarting the IDE and invalidating caches may help.
However, cache invalidation will not create a missing @color, fix an invalid theme, or install a missing dependency.
16. Check the Resource Folder Structure
Android expects resources to be stored in recognized directories.
For example:
res/layout/
res/drawable/
res/mipmap/
res/values/
res/menu/
res/xml/
res/font/
A file placed in the wrong folder may not generate the resource type you expect.
For example, a color resource and a drawable resource are not interchangeable simply because both contain XML.
If the Build output says a resource cannot be found, verify both:
- The filename
- The directory containing it
Android’s resource documentation provides the supported resource directory structure and explains how resources are referenced from XML and code.
17. Check Generated Resources Such as R
Developers sometimes try to fix this problem by manually importing R.
Be careful.
If your own resource references suddenly appear unresolved, the problem may not be the import. A failed resource build can prevent Android from generating the expected R entries.
First fix the resource linking error.
Also make sure you are not accidentally importing:
android.R
when you intend to reference resources from your own app.
An incorrect android.R import can make valid app resources appear missing or cause confusing attribute references.
18. Check Third-Party Library Resources
A dependency can bring its own:
- Themes
- Colors
- Attributes
- Drawables
- Styles
- Resource requirements
If the error started after adding a library, temporarily identify that change.
Check the dependency documentation for:
- Required
compileSdk - Required Android Gradle Plugin version
- Required transitive dependencies
- Migration instructions
- Theme requirements
Do not simply downgrade random libraries until the error disappears. That can introduce security, compatibility, and maintenance problems.
Instead, determine which dependency is associated with the missing resource.
19. If the Error Mentions a Specific XML Line, Start There
A message such as:
res/values/themes.xml:12:5: error: ...
is valuable.
Open that exact file and line.
Check the resource name, parent, attribute, and value.
For example:
<item name="android:windowLightStatusBar">@color/black</item>
may fail if the syntax or referenced resource is wrong for the context.
The error line is often more useful than searching the entire internet for the final phrase “Android resource linking failed.”
20. A Quick Diagnostic Checklist
When you see Android resource linking failed, check these in order:
- Read the first specific error above the generic message.
- Open the exact file and line named in the Build output.
- Check whether the referenced resource exists.
- Check spelling and resource naming rules.
- Check whether the file is in the correct
res/directory. - Check XML syntax and closing tags.
- Check
@versus?resource references. - Check the parent theme.
- Check AndroidX or Material dependencies.
- Check
compileSdkif anandroid:attrresource is missing. - Sync Gradle.
- Clean and rebuild.
- Investigate third-party libraries if the error started after adding one.
- Invalidate IDE caches only if the error appears to be stale or indexing-related.
Common Android Resource Linking Failed Errors and Their Likely Causes
resource ... not found
Usually means:
- The resource does not exist
- The name is misspelled
- The file is in the wrong directory
- A dependency that provides the resource is missing
attribute ... not found
Usually means:
- A theme attribute is unavailable
- The wrong UI library is being used
- A dependency is missing
- A project is using code intended for another theme system
resource android:attr/... not found
Usually means:
compileSdkis too old for the framework resource- A dependency requires a newer SDK
- The project configuration needs to be updated compatibly
style ... not found
Usually means:
- The style was renamed or deleted
- The style file contains an invalid definition
- The parent theme is missing
- The required library is not included
error: expected ... but got ...
Usually means:
- The wrong resource type was supplied
- A resource reference is missing
@ - A raw string was used where a resource was expected
- The XML value is invalid for the attribute
Frequently Asked Questions
What causes Android resource linking failed?
The error is usually caused by a missing resource, invalid XML, incorrect resource reference, missing dependency, incompatible theme, or Android SDK and dependency mismatch.
What is AAPT2?
AAPT2 stands for Android Asset Packaging Tool 2. It compiles and links Android resources during the build process. When it cannot resolve or process a resource correctly, Android Studio can display an Android resource linking failed error.
How do I find the real cause of Android resource linking failed?
Scroll above the generic message in Android Studio’s Build output and find the first specific error. Look for the file name, line number, and exact resource, style, or attribute that could not be resolved.
Does cleaning the project fix Android resource linking failed?
Sometimes cleaning removes outdated build output, but it will not fix a missing resource, invalid XML file, or incompatible dependency. Fix the specific error first.
Why does android:attr say not found?
The Android framework attribute may not exist in the SDK platform selected by your project’s compileSdk, or a dependency may require a newer SDK configuration.
Should I delete the .gradle folder?
Not as a first step. Deleting caches can force Gradle to regenerate files, but it does not fix the underlying configuration or resource error. Read the specific AAPT2 error first.
Why did this error start after adding a dependency?
The new library may require a newer compileSdk, a different dependency version, a theme, or another supporting library. Check the dependency’s official requirements and the first specific resource error.
Can I fix Android resource linking failed by invalidating caches?
Only if the issue is caused by stale IDE indexes or cached project state. It will not fix an actual missing resource or invalid XML definition.
The fastest way to fix Android resource linking failed is to stop treating the final message as the real error. AAPT2 is telling you that resource linking failed, but the line above it usually tells you what Android could not find or process.
Start with that exact resource. Check whether it exists, whether the XML reference is valid, whether the correct dependency is installed, and whether your compileSdk supports the framework resource being requested.
For additional reference on how Android resources and style attributes are structured, see the official Android Developers resource documentation.
