广告加载错误

如果广告加载失败,系统会调用 回调 ,该回调会提供 LoadAdError对象。

对于 AdView,系统会调用以下内容:

以下示例展示了广告加载失败时可用的信息:

Kotlin

override fun onAdFailedToLoad(error: LoadAdError) {
  // Gets the domain from which the error came.
  val errorDomain = error.domain
  // Gets the error code. See
  // https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdRequest#constant-summary
  // for a list of possible codes.
  val errorCode = error.code
  // Gets an error message.
  // For example "Account not approved yet". See
  // https://support.google.com/admob/answer/9905175 for explanations of
  // common errors.
  val errorMessage = error.message
  // Gets additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // information.
  val responseInfo = error.responseInfo
  // Gets the cause of the error, if available.
  val cause = error.cause
  // All of this information is available using the error's toString() method.
  Log.d("Ads", error.toString())
}

Java

@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
  // Gets the domain from which the error came.
  String errorDomain = adError.getDomain();
  // Gets the error code. See
  // https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdRequest#constant-summary
  // for a list of possible codes.
  int errorCode = adError.getCode();
  // Gets an error message.
  // For example "Account not approved yet". See
  // https://support.google.com/admob/answer/9905175 for explanations of
  // common errors.
  String errorMessage = adError.getMessage();
  // Gets additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // information.
  ResponseInfo responseInfo = adError.getResponseInfo();
  // Gets the cause of the error, if available.
  AdError cause = adError.getCause();
  // All of this information is available using the error's toString() method.
  Log.d("Ads", adError.toString());
}
对于网域 MobileAds.ERROR_DOMAIN下的错误, 您可以在 解决常见的新用户引导问题一文 中查找相应消息,以获取更详细的说明,并了解在解决问题时可以采取的措施。

调试常见错误日志记录消息

Google Mobile Ads SDK 的 23.5.0 版中,详细日志记录功能得到了增强,现在 包含广告加载失败位置的堆栈轨迹。这些消息并不表示崩溃,而是用于标识错误的唯一来源。 下表提供了常见错误日志、说明和建议的解决方案:

错误日志 说明 操作建议
com.google.android.gms.ads.nonagon.render.cp: * 广告服务器未返回广告或任何中介广告来源来请求。 如需详细了解此类常见新手入门问题,请参阅解决常见的新手入门问题
com.google.android.gms.ads.nonagon.render.e: * 中介广告瀑布流中的所有广告来源均未能加载。具体错误表示未能加载的最后一个广告来源。 如需详细了解如何记录每个中介广告来源的失败原因,请参阅 响应信息
com.google.android.gms.ads.internal.util.*: Unable to obtain a JavascriptEngine. 广告请求失败,因为 WebView 在特权进程中 不允许。
  • 检查您的互联网设置。
  • 移除 android:sharedUserId="android.uid.system",然后将应用安装为系统应用。
广告请求失败,因为网络连接速度较慢。 尝试改善您的互联网 连接,然后重试。
com.google.android.gms.ads.nonagon.load.a 广告请求超时。
com.google.android.gms.ads.internal.util.*: Error while connecting to ad server: Unable to resolve host "pubads.g.doubleclick.net": No address associated with hostname 广告请求失败,因为网络连接存在问题。
com.google.android.gms.ads.internal.util.*: Error building request URL: Cannot determine request type. Is your ad unit id correct? 广告单元 ID 与预期正则表达式不匹配。 检查您的广告单元 ID 是否正确。
com.google.android.gms.ads.internal.render.bt: Unable to instantiate mediation adapter class. Google Mobile Ads SDK 找不到中介适配器。
  • 使用广告检查器中的 查看可用 适配器来诊断 Google Mobile Ads SDK 找不到哪些适配器。
  • 将缺少的适配器添加到您的项目中。如需了解如何 完成此步骤(针对每个广告来源),请参阅 网络详细信息
com.google.android.gms.internal.ads.*: Received error HTTP response code: 403 AdMob 服务器拒绝了该请求。 请稍后重试。如果可以始终重现此问题,请使用广告检查器捕获请求网址,然后与支持团队联系。