首页 > 解决方案 > Android Admob:缺少 google_app_id

问题描述

我正在尝试使用谷歌开发指南herehere实施奖励广告,在模拟器上使用测试广告单元时,广告会显示并正常调用回调ca-app-pub-3940256099942544/5224354917,然后我用我的测试广告单元替换了测试广告单元,在物理设备,广告不会加载并调用函数onRewardedVideoAdFailedToLoad

在我发现的日志中

GoogleService 初始化失败,状态:10,名称为 google_app_id 的字符串资源中缺少 google 应用程序 ID 值。

我继续创建了一个 firebase 帐户,只是为了下载google-services.json并获取mobilesdk_app_id.然后我将它添加到字符串资源中。现在,当它启动时,广告无法再次加载,我在日志中发现了这一点

禁用数据收集。在 strings.xml 中找到了 google_app_id,但缺少 Google Analytics for Firebase。删除此值或添加 Google Analytics for Firebase 以恢复数据收集。

我正在使用com.google.gms:google-services:4.3.0 我在指南中找不到任何帮助

标签: androidadmob

解决方案


你加了加吗

apply plugin: 'com.google.gms.google-services'

到你的模块 build.gradle 的底部?

您的 app_id 也需要转到您的 AndroidManifest.xml

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

见这里:https ://developers.google.com/admob/android/quick-start#update_your_androidmanifestxml


推荐阅读