skip to Main Content

I added the google_mobile_ads sdk v5.0.0 in my flutter project. Now when I run the project I get the following error

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

I have tried using version 4.0.0, but the same error occur.
Also there is no property tag in my AndroidManifest.xml currently.

The following is my AndroidManifest.xml located in ‘androidappsrcmainAndroidManifest.xml’

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="<package-name>">
   <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="com.android.vending.BILLING"/>
   
   <application
        android:label="${appName}"
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon"
        >
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />            
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="<id>"/>
    </application>
</manifest>

2

Answers


  1. you should use your application d also here

    <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="<id>"/>
    
    Login or Signup to reply.
  2. When you wanted to add google_mobile_ads to you project, Do the following steps it will solve your problem.

    1- Add meta-data

    <manifest>
        <application>
            <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
            <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
        <application>
    <manifest>
    

    2- Initialize Mobiles ads instance

    Future<void> main() async{
      WidgetsFlutterBinding.ensureInitialized();
      MobileAds.instance.initialize();
      runApp(const MyApp());
    }
    

    3- Specify the minSdkVersion and targetSdkVersion version in build.grade file

    defaultConfig {
            applicationId "com.example.app"
            minSdkVersion 21
            targetSdkVersion 34
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search