Android resource linking failed is usually not the real error. It is the final message AAPT2 prints after it fails to compile or link one of your app resources. The useful clue is normally a few lines above it.
You may see errors such as:
error: resource color/app_background not found
error: resource style/AppTheme not found
error: resource android:attr/lStar not found
res/values/themes.xml:12:5: error: style attribute 'attr/colorPrimary' not foundThose messages point to different problems.
The most efficient fix is to read the first specific AAPT2 error, identify what type of resource failed, and then correct that exact issue.
Start With the First Real Error
When the build ends with:
Android resource linking failedscroll upward in Build Output.
Look for the first line that names:
- a resource
- an attribute
- a style
- an XML file
- a line number
- an Android framework attribute
For example:
app/src/main/res/layout/activity_main.xml:18: error:
resource drawable/ic_profile not foundThat is the error to fix first.
Later errors can be side effects of the first broken resource.
Match the Error to the Cause
| Error pattern | Most likely cause |
|---|---|
resource ... not found | Missing resource, wrong name, wrong folder |
attribute ... not found | Theme or library mismatch |
style ... not found | Missing style or unavailable parent theme |
android:attr/... not found | compileSdk or dependency compatibility |
| File and line number shown | XML or value error at that location |
| Error appeared after adding a library | Dependency requirement or Gradle issue |
This is much more reliable than cleaning the project repeatedly.
resource ... not found
Example:
error: resource color/app_background not foundCheck the XML reference:
android:background="@color/app_background"Then confirm that the resource actually exists.
For a color, that could be in:
<color name="app_background">#FFFFFF</color>inside a file under:
res/values/For a drawable reference:
android:src="@drawable/ic_profile"the matching file should exist in a valid drawable resource directory.
Check the name carefully
Android resource names should use lowercase letters, numbers, and underscores.
Good:
ic_profile.xml
button_background.xml
main_screen.xmlBad:
IcProfile.xml
button-background.xml
Main Screen.xmlIf you renamed the resource, search the project for old references.
AAPT2 Names an XML File and Line
Example:
res/values/themes.xml:12:5: error:
style attribute 'attr/colorPrimary' not foundOpen that exact file and line.
Look for:
- a missing resource
- an invalid attribute
- malformed XML
- an unavailable theme parent
- an incorrect namespace
- a wrong value type
When AAPT2 gives you a file and line number, start there before touching Android Studio caches or Gradle settings.
Fix Malformed XML
AAPT2 cannot link resources correctly when the XML itself is invalid.
Example: unclosed element
Incorrect:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content">For a self-contained view, close it properly:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />Also check for:
- missing closing tags
- invalid nesting
- malformed attributes
- duplicated XML elements
- values placed in the wrong resource file
attribute ... not found
Example:
error: attribute colorPrimary not foundThis usually means the project expects an attribute that is not available from the current theme or dependency set.
Common causes include:
- AppCompat theme code in a project that no longer uses AppCompat
- Material Components resources without the Material library
- code copied from a project using a different theme system
- a missing dependency
Before adding random libraries, ask:
- Which theme is active?
- Which library should provide this attribute?
- Did the error start after changing themes or dependencies?
Fix the mismatch instead of forcing the attribute into an unrelated setup.
style ... not found
Example:
error: resource style/AppTheme not foundCheck whether the style exists:
<resources>
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
</style>
</resources>Then check where it is referenced:
<application
android:theme="@style/AppTheme">The names must match exactly.
A missing style can mean:
- the style was renamed
- the file containing it is broken
- the parent theme is unavailable
- the required dependency is missing
Check the Parent Theme
This can fail even when your own style exists.
Example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">If the project does not include the library that provides that parent theme, resource linking can fail.
Do not copy a theme name from an old tutorial without checking which UI library your project actually uses.
android:attr/... not found
Example:
error: resource android:attr/lStar not foundThis usually points to a compatibility issue between your dependencies and the Android SDK used to compile the project.
Check the app module’s Gradle configuration.
Kotlin DSL:
android {
compileSdk = 36
}Groovy:
android {
compileSdk 36
}Do not confuse:
compileSdkminSdktargetSdk
compileSdk determines which Android framework APIs and resources are available at compile time.
If a dependency expects a framework attribute that your current compileSdk does not provide, AAPT2 can fail during linking.
After increasing compileSdk:
- make sure that SDK platform is installed
- sync Gradle
- rebuild the project
Do not change SDK versions blindly. Your Android Gradle Plugin and dependencies must also be compatible.
The Error Started After Adding a Dependency
This is a useful clue.
Inspect the dependency you just added or updated.
Check its documentation for:
- minimum
compileSdk - required Android Gradle Plugin version
- required supporting libraries
- theme requirements
- migration notes
A library can introduce resources that your project did not previously need.
That can include:
- styles
- attributes
- colors
- drawables
- framework resources
If the failure began immediately after adding a dependency, investigate that dependency before changing unrelated XML.
Check AndroidX and Material Dependencies
Some resource errors come from copied theme code that assumes a library is already installed.
For example:
dependencies {
implementation("androidx.appcompat:appcompat:...")
implementation("com.google.android.material:material:...")
}Use versions appropriate for your project.
Do not copy arbitrary version numbers from an old Stack Overflow answer or tutorial.
After changing dependencies, sync Gradle and read the sync output before rebuilding.
Check @ Versus ?
Android resource references use different syntax depending on what you are referencing.
Direct resource:
android:background="@color/black"Theme attribute:
android:textColor="?attr/colorOnSurface"Do not swap @ and ? randomly.
Check whether the value should come from a concrete resource or from the active theme.
Check XML Namespaces
A custom prefix needs a matching namespace declaration.
Typical declarations include:
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 a layout uses app: or tools: without declaring that namespace, fix the root element.
Check the Resource Folder
A file can exist under res/ and still be in the wrong place.
Common folders include:
res/layout/
res/drawable/
res/mipmap/
res/values/
res/menu/
res/xml/
res/font/If Android says a drawable is missing, verify both:
- the file name
- the folder that contains it
Resource type is determined partly by the directory.
Do Not Fix R Before Fixing AAPT2
When resource compilation fails, generated R references can disappear or show as unresolved.
That is usually a secondary symptom.
Fix the resource error first.
Also check that you have not accidentally imported:
android.Rwhen your code should use your app’s generated R.
A bad import can cause confusion, but it will not repair broken XML or a missing resource.
Clean and Rebuild After the Real Fix
Once you correct the actual resource problem, rebuild.
macOS or Linux:
./gradlew clean
./gradlew assembleDebugWindows:
gradlew.bat clean
gradlew.bat assembleDebugIf you are unsure where to run the Windows commands, Windows PowerShell vs Command Prompt explains the difference between the shells. Run the build command from your project directory.
Cleaning removes stale build output.
It does not:
- create missing resources
- install missing dependencies
- repair XML
- make an unavailable framework attribute exist
If the same error returns after a clean build, go back to that error.
When Gradle Sync Matters
Sync the project after changing:
- dependencies
- SDK versions
- plugin versions
- module configuration
If Gradle cannot resolve the library that provides a style or attribute, AAPT2 will not have that resource later in the build.
Read Gradle sync errors before trying another resource fix.
When to Invalidate Android Studio Caches
A frozen editor is a separate issue from an AAPT2 error. Save your work if possible; if Android Studio will not respond on Windows, use How to Force Quit on Windows to close it before reopening the project.
Use cache invalidation only when the project configuration appears correct but Android Studio behaves inconsistently.
Consider it when:
- the resource definitely exists
- XML is valid
- Gradle sync succeeds
- command-line builds behave differently from the IDE
- Android Studio appears to show stale indexing errors
Cache invalidation will not fix:
- a missing
@color - an unavailable theme parent
- a missing dependency
- an outdated
compileSdk - malformed XML
Treat it as an IDE-state fix, not an AAPT2 fix.
Three Realistic Debugging Examples
Missing drawable
Build output:
activity_profile.xml:22: error:
resource drawable/ic_profile not foundBest response:
- confirm
ic_profileexists - confirm the file name is valid
- confirm it is in a drawable resource directory
- confirm the XML reference is spelled correctly
Do not change Gradle unless that drawable is supposed to come from a library.
Missing theme
Build output:
themes.xml:4: error:
resource style/Theme.AppCompat.Light.NoActionBar not foundBest response:
- confirm AppCompat is actually included
- confirm the parent theme name is valid
- confirm the project was not migrated to another theme system
Do not create an empty style just to hide the error.
Missing Android framework attribute
Build output:
error: resource android:attr/... not foundBest response:
- identify which dependency introduced the attribute
- check the dependency’s SDK requirement
- check your
compileSdk - check Android Gradle Plugin compatibility
This is normally a build-configuration issue, not a missing file under your own res/ directory.


