来自official example :
<com.google.android.gms.ads.AdView
...
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
他们指定必须使用测试广告单元 ID。
When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.
如何将某处的测试和发布 ID 设置为常量?避免在每个 Activity 中复制/粘贴。
我应该为横幅创建布局吗?
但是,我仍然需要评论或手动替换 ID 以从测试切换到发布。
最佳答案
您可以使用字符串。创建两个分开的目录:
app/src/debug/res/values/strings.xml
app/src/release/res/values/strings.xml
将您的 banner_ad_unit_id
放在那里(用于调试和发布版本),然后在布局中使用它:
<com.google.android.gms.ads.AdView
...
ads:adUnitId="@string/banner_ad_unit_id">
更多详情可以查看here
关于android - 如何避免在 AdMob 的 XML 中复制/粘贴 adUnitId?用于测试和发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57207261/