使用 flutter google_mobile_ads 包导致错误

Using flutter google_mobile_ads package result in error

在我的 flutter 应用程序中,我正在尝试使用 google_mobile_ads 包实现广告。在我将包添加到 pubspec.yml 文件之前,我的应用程序完全正常工作。添加包并更改 AndroidManifest.xml 文件后(当前使用示例 AdMob 应用程序 ID):

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

我收到以下错误:

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.1b972deff280dc86e6977f77fe6522be\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

关于 Stack Overflow () 的另一个问题,我将 build.gradle 文件中的类路径更新为 classpath("com.android.tools.build:gradle:3.5.4")

修复即将出现的错误 (Your project requires a newer version of the Kotlin Gradle plugin) 我也升级了kotlin版本到1.6.10.

因为这一步导致 The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer 我也将 distributionUrl 更新为 https\://services.gradle.org/distributions/gradle-6.6.1-all.zip

在所有这些修复之后,flutter 运行 命令将 运行 循环,我在虚拟设备上看到的唯一内容是我的应用程序已停止的错误消息。 (Error on virtual device)

是否在我的代码中添加 MobileAds.instance.initialize(); 并没有什么区别。我总是得到上面的错误。

我已经尝试过的:

颤动医生:

[√] 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) 

再次在真实设备上启动我的应用程序后,我偶然发现了一条消息,指出 google_mobile_ads 包设置不正确。我发现我在错误的地方添加了 manifest.xml 文件中的元数据。请参阅下面的代码以获取正确的位置:

<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>