Android 13+应用首次启动时广告加载失败(No Fill)的问题求助
Android 13+应用首次启动时广告加载失败(No Fill)的问题求助
大家好,我遇到了一个非常棘手的广告加载问题,想向各位请教:
在Android 13及以上版本的设备上,应用首次启动时,即使用测试广告ID加载广告,也会在onAdFailedToLoad()中抛出No Fill错误,但后续启动再加载就完全正常。
我已经在Manifest里添加了AD_ID权限:
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
我的核心代码如下:
广告加载与展示逻辑:
fun load( context: Context, adUnitId: String, screenAdsId: String, callback: (InterstitialAd?) -> Unit ) { val adRequest = AdRequest.Builder().build() InterstitialAd.load( context, adUnitId, adRequest, object : InterstitialAdLoadCallback() { override fun onAdLoaded(ad: InterstitialAd) { Log.i("mLogAds", "$screenAdsId onAdLoaded") callback(ad) } override fun onAdFailedToLoad(adError: LoadAdError) { Log.e("mLogAds", "$screenAdsId onAdFailedToLoad: $adError ${adError.code} ${adError.message}") } } ) } fun show( interstitialAd: InterstitialAd?, context: Context, screenAdsId: String, onAdClosed: () -> Unit ) { interstitialAd?.let { ad -> ad.fullScreenContentCallback = object : FullScreenContentCallback() { override fun onAdDismissedFullScreenContent() { Log.i("mLogAds", "$screenAdsId onAdDismissedFullScreenContent") onAdClosed() } override fun onAdFailedToShowFullScreenContent(adError: AdError) { Log.e("mLogAds", "$screenAdsId onAdFailedToShowFullScreenContent: $adError") onAdClosed() } override fun onAdShowedFullScreenContent() { Log.i("mLogAds", "$screenAdsId onAdShowedFullScreenContent") } } ad.show(context as androidx.activity.ComponentActivity) } ?: onAdClosed() }
Consent与初始化逻辑:
我会先检查用户Consent再初始化广告SDK:
consentInformation.requestConsentInfoUpdate(this, params, { if (consentInformation.isConsentFormAvailable) { UserMessagingPlatform.loadAndShowConsentFormIfRequired(this) { formError -> Log.i("mLogAdsTest", "CONSENT SUCCESS") viewModel.updateInitState(true) if (consentInformation.canRequestAds()) { Log.d("mLogAdsTest", "googleMobileAdsConsentManager.canRequestAds") initializeMobileAdsSdk() } } } else { if (consentInformation.canRequestAds()) { initializeMobileAdsSdk() } } })
只有确认初始化完成后才会开始加载广告:
private fun initializeMobileAdsSdk() { val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable -> println(throwable.message) } val backgroundScope = CoroutineScope(Dispatchers.Main + coroutineExceptionHandler) MobileAds.setRequestConfiguration( RequestConfiguration.Builder() // .setTestDeviceIds(listOf(TEST_DEVICE_HASHED_ID)) .build() ) backgroundScope.launch { MobileAds.initialize(this@MainActivity) { Log.e("mLogAdsTest", "INIT") it.adapterStatusMap.forEach { s, adapterStatus -> if (adapterStatus.initializationState.toString() == "READY") { Log.i("mLogAdsTest", "READY") viewModel.updateInitState(true) } } } } }
我已经尝试过的解决方案:
- 切换Coroutine的Dispatcher为IO,结果没有变化
- 新建一个极简测试项目(只保留广告加载和展示逻辑),问题依然存在
- 将
MobileAds.initialize(this)移到Application类中初始化,无效 - 在
onAdFailedToLoad()中重试加载,首次启动内无论重试多少次都还是No Fill,第二次启动就正常 - 测试了插屏广告以外的其他广告类型,同样存在首次启动加载失败的问题
- 更换了多个AdMob SDK版本:23.6.0、24.0.0、24.0.1、24.0.2,问题都一致
- 甚至在Google官方的AdMob示例项目中也复现了同样的问题
想请教各位:有没有人遇到过类似的情况?这是我的代码哪里有问题,还是Google那边的问题?有没有什么可行的解决办法?
内容来源于stack exchange
相关产品推荐
相关产品推荐

