【问题标题】:Using flutter google_mobile_ads package result in error使用颤振 google_mobile_ads 包导致错误
【发布时间】:2022-01-05 10:42:11
【问题描述】:

在我的颤振应用中,我尝试使用 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.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

关于 Stack Overflow 上的另一个问题 (How to fix "unexpected element <queries> found in <manifest>" error?) 我将 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 run 命令将循环运行,我在虚拟设备上看到的唯一内容是我的应用程序已停止的错误消息。 (Error on virtual device)

是否将MobileAds.instance.initialize();添加到我的代码中并没有什么不同。我总是收到上面的错误。

我已经尝试过的:

  • google_mobile_ads、gradle kotlin 和 distributionUrl 的各种版本
  • 创建一个新的 Flutter 项目
  • 在真实设备上

颤振医生:

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

【问题讨论】:

    标签: android flutter gradle googlemobileads


    【解决方案1】:

    在我再次在真实设备上启动我的应用程序后,我偶然发现了一条消息,即 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>
    

    【讨论】:

      猜你喜欢
      • 2021-09-17
      • 2022-11-11
      • 2021-07-04
      • 2021-01-20
      • 2022-06-14
      • 2022-09-23
      • 2020-08-30
      • 2018-10-30
      • 1970-01-01
      相关资源
      最近更新 更多