广告加载错误

如果广告加载失败,系统会调用一个回调,该回调会提供一个 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(LoadAdError error) {
  // Gets the domain from which the error came.
  String errorDomain = error.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 = error.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 = error.getMessage();
  // Gets additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // for more information.
  ResponseInfo responseInfo = error.getResponseInfo();
  // Gets the cause of the error, if available.
  AdError cause = error.getCause();
  // All of this information is available using the error's toString() method.
  Log.d("Ads", error.toString());
}
对于网域 MobileAds.ERROR_DOMAIN 下的错误,可在解决常见的初始配置问题一文中查询相应消息,以获取更详细的说明并了解在解决问题时可以采取的措施。

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

在 Google 移动广告 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 移动广告 SDK 找不到中介适配器。
  • 使用广告检查器中的查看可用适配器功能,诊断 Google 移动广告 SDK 找不到哪些适配器。
  • 向您的项目添加缺少的适配器。如需查看有关如何为每个广告来源完成此步骤的说明,请参阅 广告联盟详细信息
com.google.android.gms.internal.ads.*: Received error HTTP response code: 403 AdMob 服务器拒绝了请求。 请稍后再试。如果问题可以稳定重现,请使用广告检查器捕获请求网址,然后与支持团队联系。