Fix Manifest Merger Failed: AD_SERVICES_CONFIG in Android

Learn how to fix the Manifest Merger Failed (AD_SERVICES_CONFIG) error in Android Studio caused by AdMob and Firebase using tools:replace in 1 minute.

How to Fix Android Studio Error: Manifest Merger Failed (AD_SERVICES_CONFIG) in 1 Minute?

If you are an Android Developer integrating Google AdMob along with Firebase Analytics into your project, chances are you have encountered a very frustrating build error.

Android Studio Manifest Merger Failed AD_SERVICES_CONFIG Error Fix Code

The error typically looks like this in your build output:

Manifest merger failed : Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/gma_ad_services_config) from [com.google.android.gms:play-services-ads-lite:23.1.0] AndroidManifest.xml... is also present at [com.google.android.gms:play-services-measurement-api:22.0.2] AndroidManifest.xml... value=(@xml/ga_ad_services_config).
Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.

If you are stuck seeing this red error message, do not panic! This is not a coding mistake, but rather a very common "conflict" between libraries. Let's understand why this happens and how to fix it permanently in just 1 minute.


💡 Why Does This Error Occur? (The Reason)

In recent Android versions (especially Android 13 and above), Google introduced the "Privacy Sandbox" (Ad Services) to enhance user privacy.

When you add both AdMob (play-services-ads) and Firebase Analytics (firebase-analytics) dependencies in your build.gradle file, both libraries try to provide their own configuration file to the Android system:

  1. AdMob says: Use my file (@xml/gma_ad_services_config).
  2. Firebase says: Use my file (@xml/ga_ad_services_config).

Since both are trying to claim the exact same property (android.adservices.AD_SERVICES_CONFIG), the 'Manifest Merger' tool in Android Studio gets confused about which one to prioritize during the build process. This conflict causes the build to fail.

Also Read: Mastering Claude Design: Build Professional UI/UX in Minutes using AI


🛠️ 100% Working Solution: How to Fix It?

The solution is very straightforward. We just need to explicitly tell the Android system in our AndroidManifest.xml file to prioritize one file (mainly the AdMob one) and ignore the conflict.

There are only 2 easy steps to fix this:

Step 1: Add the tools Namespace to the Manifest

First, open your AndroidManifest.xml file. At the very top, where the <manifest> tag begins, add the xmlns:tools line.

Before:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

After:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"> 
          <!-- 👆 Adding this line is mandatory -->

Step 2: Use tools:replace inside the <application> Tag

Now, scroll down in the same file to where the <application> tag starts. Right inside it (before any <activity> or <meta-data> tags), paste the following <property> code:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.MyApp">

        <!-- 👇 Add this magic code to fix the Manifest Merger Error 👇 -->
        <property
            android:name="android.adservices.AD_SERVICES_CONFIG"
            android:resource="@xml/gma_ad_services_config"
            tools:replace="android:resource" />

        <!-- Your other activities and meta-data will remain here -->

    </application>

What Did This Code Do?

We used tools:replace="android:resource". This gives a direct instruction to Android Studio: "Whenever there is a conflict between Firebase and AdMob regarding AD_SERVICES_CONFIG, simply replace/set it with @xml/gma_ad_services_config (the AdMob file) by default."

Also Read: AI Crawlers: Should You Allow or Block Bots | Practical Guide


✅ Final Check

After pasting the code, go to the top menu in Android Studio:

  • Click on Build > Clean Project.
  • Then, Run or Rebuild your app again.

Congratulations! Your Manifest merger failed error is now gone forever, and your app will build successfully.

Did this information help you? If this small piece of code saved you hours of headache, be sure to share this post with your fellow Android Developers. Stay tuned to THE SMART ADVICE for more advanced and practical app development and SEO tips!

Post a Comment

Write your feedback or openion.

LATEST VISUAL STORIES