93

I'm trying to upgrade my project to AGP 8.3.0 but I'm getting the error:

Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:21.5.1] AndroidManifest.xml:32:13-58
    is also present at [com.google.android.gms:play-services-ads-lite:22.6.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config).
    Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.

Any idea on how to fix this?

I don't have anything related to AD_SERVICES_CONFIG in my manifest file.

1
  • 1
    I did as suggested. Created a new property with tools:replace="android:resource" <property android:name="android.adservices.AD_SERVICES_CONFIG" android:resource="@xml/gma_ad_services_config" tools:replace="android:resource" />
    – YogeshM
    Commented Mar 1 at 6:28

7 Answers 7

139

Problem is definitely not with your AndroidManifest.xml file, but rather the files that are bundled with the external Google services libraries that you have implemented in your application. Yes, sometimes they may conflict with each other (as all manifests are merged during app build) and this seems to be the case.

Eventually, Google will address this issue, but for now you can either downgrade your dependencies (need to figure out which ones, but AGP 8.2.2 didn't have this problem AFAIK).

Or, just do as suggested by the error log, and solve the conflict by adding this block to your AndroidManifest.xml file:

<manifest
    ...

    <application
        ...

        <property
            android:name="android.adservices.AD_SERVICES_CONFIG"
            android:resource="@xml/gma_ad_services_config"
            tools:replace="android:resource" />
        
        ...
    </application>

    ...
</manifest>

Note: I would still recommend going back to AGP 8.2.2 if your project is important, since new releases are always risky and this might not be the only problem in the updated Gradle plugin

16
  • 9
    thanks! I ended keeping 8.2.2, which was the version I had before. Agree with you, can't risk it. Commented Mar 2 at 0:51
  • 2
    Wait why does it occur? Is it a bug on some version of the dependency or gradle ? Is it a known bug? Or is it documented anywhere that I need to do this? Commented Mar 17 at 14:55
  • 2
    @androiddeveloper seems like a bug, a version conflict between latest agp and firebase/gms libs Commented Mar 18 at 13:27
  • 8
    @SergeyEmeliyanov Maybe this: issuetracker.google.com/issues/327696048 ? Commented Mar 19 at 8:11
  • 7
    it's been a while and Google didn't fix it yet...
    – user924
    Commented Apr 6 at 13:20
18

I fix this error by adding this tag to the tag in the manifest.

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="@string/APP_NUMBER" />
    <property
        android:name="android.adservices.AD_SERVICES_CONFIG"
        android:resource="@xml/gma_ad_services_config"
        tools:replace="android:resource" />
0
10

Note that you have to give a version number when importing the play-services-ads, it doesn't work like Analytics which takes the version from the BOM.

(App-Level) gradle for example:

implementation(platform("com.google.firebase:firebase-bom:32.7.3"))
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-crashlytics")
implementation("com.google.android.gms:play-services-ads:22.6.0")

Add this property to your Manifest file (inside application - above or below activities):

<property
            android:name="android.adservices.AD_SERVICES_CONFIG"
            android:resource="@xml/gma_ad_services_config"
            tools:replace="android:resource" />

Sync the project and run it. Don't forget to init the library (Better to do it in the application class - with the Application Context):

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        MobileAds.initialize(this);
    }
}
3
  • 1
    Why "Better to do it in the application class - with the Application Context" ??
    – ikmazameti
    Commented Mar 20 at 21:17
  • It is probably because the application context is a singleton that wouldn't leak any memory. The onCreate method in the application class is called only once so you would know the initialization happens only once time.
    – Efe Budak
    Commented Apr 3 at 21:06
  • Adding below code to my manifest helped me solve the problem, "<property android:name="android.adservices.AD_SERVICES_CONFIG" android:resource="@xml/gma_ad_services_config" tools:replace="android:resource" />" Commented Jul 10 at 8:14
8

Adding

<property
        android:name="android.adservices.AD_SERVICES_CONFIG"
        android:resource="@xml/gma_ad_services_config"
        tools:replace="android:resource" />

really works.

But if you have another problem like

  • What went wrong: Execution failed for task ':app:processDebugMainManifest'. com.android.manifmerger.ManifestMerger2$MergeFailureException: Error parsing ...\android\app\src\main\AndroidManifest.xml

You have to add

xmlns:tools="http://schemas.android.com/tools"

to the manifest tag, like

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

Problem: Manifest merger failed with multiple errors, see logs

Added below lines in manifest.xml -> application tag

<property
 android:name="android.adservices.AD_SERVICES_CONFIG"
 android:resource="@xml/gma_ad_services_config"
 tools:replace="android:resource" />
4

Checking the affected libraries, actually the correct behavior is this and not the previous one from IDE/AGP standpoint.

I do not recommend to use the previous version of AGP that compiled the app without report this problem as it may cause undesired overrides.

One of the conflicting config files(gma_ad_services_config.xml) allows both Attribution API and Topics API the other one (ga_ad_services_config.xml) just Attribution API.

1
  • Athough you gave no solution on how to fix this, at least this is the only answer that doesn't offer a superficial workaround in guise of a proper solution.
    – SpaceBison
    Commented May 7 at 8:25
0

I think the real problem is the version of the play-services-ads library, go to this page and try to see which version is suitable for your app (For me upgrading to 23.0.0 caused this error so I downgraded to 22.2.0 and it works fine)

play services ads link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.