Using flutter google_mobile_ads package result in error

170

After I started my app on a real device again i stumbled across a message that the google_mobile_ads packages isn´t set up correctly. I found out that I added the meta data in the manifest.xml file at the wrong place. See the code below to get the right place:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.remote">
<application>
    <activity>
        <meta-data/>
        <meta-data>
            **Where I added it**
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713"
        <meta-data/>
        <intent-filter/>
    </activity>
    <meta-data
        **Where it has to be added** 
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713" />
    <meta-data/>
</application>
<uses-permission/>
</manifest>
Share:
170
Admin
Author by

Admin

Updated on January 03, 2023

Comments

  • Admin
    Admin over 1 year

    In my flutter app I am trying to implement ads with the google_mobile_ads package. My app is completely working till I add the package in the pubspec.yml file. After adding the package and changing the AndroidManifest.xml file (currently using the Sample AdMob app ID):

            <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-3940256099942544~3347511713"/>
    

    I get following error:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:processDebugResources'.
    > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource linking failed
        C:\Users\<user>\.gradle\caches\transforms-2\files-2.1\4b972deff280dc86e6977f77fe6522be\play-services-ads-lite-20.4.0\AndroidManifest.xml:28:5-44:15: AAPT: error: unexpected element <queries> found in <manifest>.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 30s
    Running Gradle task 'assembleDebug'...                             31,9s
    Exception: Gradle task assembleDebug failed with exit code 1
    

    Regarding to another question on Stack Overflow (How to fix "unexpected element <queries> found in <manifest>" error?) I updated the classpath in build.gradle file to classpath("com.android.tools.build:gradle:3.5.4")

    To fixed the upcoming error (Your project requires a newer version of the Kotlin Gradle plugin) I also upgraded the kotlin version to 1.6.10.

    Because this step resulted in The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer I also updated the distributionUrl to https\://services.gradle.org/distributions/gradle-6.6.1-all.zip

    After all this fixes the flutter run command will run in a loop and the only thing I see on my virtual device is the error message that my app has stopped. (Error on virtual device)

    It doesn´t make a differance if I add MobileAds.instance.initialize();to my code or not. I always get the errors above.

    What I already tried:

    • Various verions of google_mobile_ads, gradle kotlin and distributionUrl
    • Creating a new flutter project
    • On a real device

    Flutter Doctor:

    [√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.19042.1415], locale de-DE)
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        X cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        X Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
    [√] Chrome - develop for the web
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.4)
    [√] Android Studio (version 3.5)
    [√] IntelliJ IDEA Ultimate Edition (version 2019.1)
    [√] VS Code (version 1.63.2)
    [√] Connected device (5 available)