You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

集成play-services-ads后应用崩溃无法显示的问题求助

Fixing Crashes After Integrating Google Play Services Ads

Hey there, sorry to hear your app's crashing after adding the Ads SDK—let's break down the most common issues and fixes based on your project setup.

First, Check Your AndroidManifest.xml (Most Likely Culprit)

From Ads SDK version 17.0.0 onwards, Google requires you to declare your AdMob App ID in the manifest. Missing this is the #1 cause of crashes right after integration. Here's what you need to add:

  1. Add Required Permissions (put these outside the <application> tag):

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    

    The ACCESS_NETWORK_STATE permission helps the SDK check connectivity before loading ads, preventing unnecessary errors.

  2. Declare Your AdMob App ID (inside the <application> tag):

    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    

    Replace the value with your actual App ID from the AdMob console (this is not your ad unit ID—don't mix them up!).

Upgrade Your Ads SDK Version

You're using play-services-ads:18.1.1, an older 2019 release that might have compatibility issues with Android 10 (API 29, your target SDK). Try upgrading to a more recent, API 29-compatible version. For example:

implementation 'com.google.android.gms:play-services-ads:19.8.0'

This version fixes several Android 10-related bugs and is a stable middle ground between old and latest releases.

Get & Analyze Your Crash Log

Without the actual crash stack trace, it's hard to pinpoint exact issues. Here's how to get it:

  • Open Android Studio's Logcat tab
  • Filter logs by Error level
  • Look for entries starting with AndroidRuntime—this will show you the exception type (e.g., IllegalStateException for missing App ID, ClassNotFoundException for broken dependencies)

If you see something like:

java.lang.IllegalStateException: The Google Mobile Ads SDK was initialized incorrectly.

That confirms the missing App ID issue we covered earlier.

Other Quick Checks

  • Sync & Rebuild: Click File > Sync Project with Gradle Files, then do a Build > Clean Project followed by Build > Rebuild Project—this fixes cached dependency issues.
  • Kotlin Version Compatibility: Ensure your kotlin_version in the project-level build.gradle matches the version of kotlin-stdlib-jdk7 you're using. Mismatched versions can cause unexpected crashes.

If you try all these steps and still have issues, share your crash log and we can dig deeper!

内容的提问来源于stack exchange,提问作者Dang Hoang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:16:20