Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Android build stops with 'resource linking failed' from AAPT2

ErrorAndroid resource linking failed

Short answer

AAPT2 links your XML resources and manifest into one package, and it fails on the first thing it cannot resolve. The output after the error names a file and line. In practice it is a misplaced manifest element, a missing or extra @ in a resource reference, or an item name written with a resource type.

  • Applies to Android Gradle plugin 8.x, Android Studio, AAPT2 from SDK Build Tools 36
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The summary line is useless. Run the failing task with the stack trace and read the 'error:' lines above it, because each carries a file path and a line number.

    ./gradlew :app:processDebugResources --stacktrace
  2. 2Match what you see, then jump to its fix

    1. 1AndroidManifest.xml:NN: error: unknown element <action> found.A manifest element sits in the wrong parentFix
    2. 2expected color but got (raw string) color/colorPrimaryA resource reference is missing its @ or has one it should not haveFix
    3. 3style attribute 'attr/attr/my_attr (aka my.package:attr/attr/my_attr)' not foundA style item names a resource type inside its nameFix

What does the error look like?

  • Android resource linking failed
  • AAPT2 aapt2-x.x.x-xxxxxxx-linux Daemon #0: Command failed
  • AndroidManifest.xml:15: error: unknown element <action> found.
  • error: style attribute 'attr/...' not found

Cause 1 of 3

A manifest element sits in the wrong parent

1Check

AAPT2 is strict about manifest nesting. An <action> must be inside an <intent-filter>, not directly inside <activity>. Open the line number the error gives.

sed -n '1,60p' app/src/main/AndroidManifest.xml

2Fix

Move the element into its correct parent, as the manifest documentation shows.

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

3Verify

Run the resource task again.

./gradlew :app:processDebugResources

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

A resource reference is missing its @ or has one it should not have

1Check

In a style item, a reference to your own resource starts with @. A reference to the android namespace is written without a leading @ in the item name.

grep -rn "<item name=" app/src/main/res/values*/ | head -40

2Fix

Add the @ to the value, and remove the @ from the item name when it points at the android namespace.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:windowEnterAnimation">@anim/slide_in</item>
</style>

3Verify

Rebuild the debug variant.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

A style item names a resource type inside its name

1Check

AAPT2 no longer accepts a resource type written in the name attribute, such as name="attr/my_attr".

grep -rn 'name="attr/' app/src/main/res/

2Fix

Declare the type with the type attribute instead.

<style name="childStyle" parent="parentStyle">
    <item type="attr" name="my_attr">@color/pink</item>
</style>

3Verify

Run the resource task and confirm the error is gone.

./gradlew :app:processDebugResources

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Treat the file and line in the 'error:' line as the fix location, not the Gradle summary.
  • Run ./gradlew assembleDebug before pushing any change to the manifest or to styles.
  • Keep style items in the documented form: @type/name for values, android: prefix for framework attributes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.