Android Studio error: "Manifest merger failed: Apps targeting Android 12"
To swiftly fix the Android 12 Manifest Merge Error, ensure that intent-filter components in your AndroidManifest.xml
have an explicit android:exported
attribute. This attribute should be set to true
to allow external access and false
to restrict it. Here is an example of using android:exported
for an activity:
Inspect your manifest carefully and assign android:exported
to every relevant component to dodge this error.
Decoding the 'android:exported' attribute
The android:exported
attribute is critical for intent-filter components when targeting Android 12+. Whenever your Activity
, Service
, or BroadcastReceiver
is designed to interact with other apps or be accessed by them, you must explicitly declare whether or not the component can be exported (true
or false
).
Count instances when android:exported="true"
- An
Activity
that's a launching point or can be initialized by other apps Services
that allow binding by external appsBroadcastReceivers
such asBOOT_COMPLETED
that should listen to broadcasts from outside the app
Instances when android:exported="false"
is needed
- Components only used internally and aren't intended to interact with other apps
- Security-sensitive components requiring encapsulation to prevent potential breaches
Tampering with dependencies
- Dependencies need updating to adapt newer standards, including
android:exported
declaration - Utilize
tools:node="merge"
to smoothly merge any conflicting manifests
Integrating with Gradle
- Use the power of Gradle tasks to automatically insert missing
android:exported
attributes - Find Gradle scripts examples on GitHub for auto-fixing your Android 12 target issues
Debugging 'Manifest merger failed' errors
Here are practical steps to debug and overcome manifest merger issues:
Inspect the merged manifest
Use Android Studio's "Merged Manifest" tab for diagnosing issues, like missing android:exported
declarations.
Scrutinize dependencies
Third-party libraries can create conflict when not updated properly. Keep an eye for updates especially related to android:exported
.
Validate your build setup
Update to the latest SDK and emulator versions to deter any outdated tooling conflicts.
Limit access
Exercise caution with android:exported="true"
. Use it sparingly, alongside suitable permissions, to keep your application's data secure.
Was this article helpful?