Maaz Zindani

Loading the index…

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

Android build fails: unexpected element <receiver> found in <manifest>

Your error

AndroidManifest.xml:12: error: unexpected element <receiver> found in <manifest>2 more lines it can show

Fix it fast

Most common cause, 1 of 2

The receiver was pasted above or below <application>

Cut the whole <receiver> block, including its intent-filter, and paste it just before </application>.

Fix
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:label="my_app">
        <activity android:name=".MainActivity" android:exported="true">
            ...
        </activity>
        <receiver
            android:name=".BootReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

AAPT2 reports unexpected element <receiver> found in <manifest> because it only accepts <receiver> as a direct child of <application>. The tag was pasted above <application>, below </application>, or inside an <activity>. Move it between <application> and </application>, next to the activity, and rebuild. Applies to AAPT2 in Android Gradle plugin 9.5 and Flutter Android builds.

  • Applies to Android Gradle plugin 9.5.0, AAPT2 (bundled with AGP), Flutter Android builds (android/app/src/main/AndroidManifest.xml)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Read the element path at the end of the error. It lists the parents AAPT2 saw around the tag. Only <manifest> means the receiver is outside <application> (cause 1); a longer path such as <manifest><application><activity> means it sits inside another component (cause 2). Then open the line number it gives.

Run this first
grep -n -E "<application|</application>|<activity|</activity>|<receiver" android/app/src/main/AndroidManifest.xml

Then find the line you see in this list and open its fix:

  1. 1The receiver was pasted above or below <application>The error path is only <manifest>, and grep shows the <receiver> line before <application or after </application>
  2. 2The receiver sits inside an <activity> or <service>The error path ends in <activity> or <service>, for example found in <manifest><application><activity>

What does the error look like?

  • AndroidManifest.xml:12: error: unexpected element <receiver> found in <manifest>
  • error: unexpected element <receiver> found in <manifest><application><activity>
  • unexpected element <service> found in <manifest>

Cause 1 of 2

The receiver was pasted above or below <application>

You seeThe error path is only <manifest>, and grep shows the <receiver> line before <application or after </application>

Check

Unexpected element <receiver> found in <manifest> appears when the tag is a direct child of <manifest>. The Android manifest reference lists <application> as the only parent of <receiver>, and AAPT2's manifest checker registers receiver only under application, so any other place fails the build by default.

Check
awk '/<application/{a=1} /<\/application>/{a=0} /<receiver/{print NR": inside application = "a}' android/app/src/main/AndroidManifest.xml

Fix

Cut the whole <receiver> block, including its intent-filter, and paste it just before </application>. Plugin setup guides that show a receiver snippet expect it there.

Fix
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:label="my_app">
        <activity android:name=".MainActivity" android:exported="true">
            ...
        </activity>
        <receiver
            android:name=".BootReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

Verify

The build passes the resource linking step, and the awk check prints inside application = 1 for every receiver.

Verify
cd android && ./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

The receiver sits inside an <activity> or <service>

You seeThe error path ends in <activity> or <service>, for example found in <manifest><application><activity>

Check

When the reported path is longer than <manifest>, AAPT2 found the receiver nested one level too deep. It prints every parent it walked through, so the last name in that path is the element that wrongly contains it. A receiver block dropped just above </activity> is the usual case.

Check
grep -n -B2 "<receiver" android/app/src/main/AndroidManifest.xml

Fix

Move the block out of the activity so that it closes after </activity> and before </application>. Components are siblings under <application>, never children of each other.

Fix
<application ...>
    <activity ...>
        ...
    </activity>   <!-- close the activity first -->
    <receiver android:name=".AlarmReceiver" android:exported="false" />
</application>

Verify

assembleDebug finishes, and the output no longer contains the unexpected element error.

Verify
cd android && ./gradlew :app:assembleDebug

Confirmed by android.googlesource.com

Did this fix it?

How do I stop it coming back?

  • Paste plugin snippets with the closing </application> visible on screen, so you can see which parent they land in.
  • Keep receivers, services and providers grouped at the end of <application> in the same order in every project.
  • Run ./gradlew :app:assembleDebug in CI on every manifest change; it fails fast on nesting mistakes.

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 on the same stack: TaxiDex, QistLock, Dispatch Pro.

Next step

Want this handled for good?

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