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

Gradle 2.3.0旧项目集成AdMob及依赖解析失败问题求助

解决AdMob依赖解析失败与旧Gradle项目集成问题

Hey there, let's work through these two AdMob integration headaches together—they're super common when dealing with older project setups, so we'll get you sorted out in no time!

问题1:无法解析com.google.android.gms:play-services-ads:15.0.0依赖

If clicking "Install Repository and sync project" didn't fix it, here are the most likely fixes to try:

  • Verify Google Maven Repository is configured
    Open your project's root build.gradle file and make sure the allprojects block includes the Google Maven repo. Older projects often miss this:

    allprojects {
        repositories {
            jcenter() // Or mavenCentral(), depending on your setup
            maven { url 'https://maven.google.com' } // This is critical for Google dependencies
        }
    }
    
  • Update SDK Components
    Open Android Studio's SDK Manager (Tools > SDK Manager), go to the "SDK Tools" tab, check "Show Package Details", then make sure:

    • Google Play Services is at least version 15.0.0 (or the latest compatible version)
    • Google Repository is updated to the version that supports play-services-ads:15.0.0
  • Clear Gradle Cache
    Sometimes cached files cause issues. Go to File > Invalidate Caches / Restart, select "Invalidate and Restart", then let Android Studio rebuild the project.

  • Check for Proxy/Network Issues
    If you're behind a proxy, make sure Android Studio is configured to use it correctly so it can reach the Google Maven repo. Also, double-check that offline mode is turned off (File > Settings > Build, Execution, Deployment > Gradle > uncheck "Offline work").

问题2:Gradle 2.3.0旧项目集成AdMob失败

Android Gradle Plugin (AGP) 2.3.0 is pretty outdated, and it has compatibility limits with newer AdMob dependency versions. Here's how to make it work:

  • Add Google Maven Repository
    Same as above, add the Google repo to your root build.gradle's allprojects block—AGP 2.3.0 doesn't include this by default.

  • Use a Compatible AdMob Version
    play-services-ads:15.0.0 requires a newer AGP version than 2.3.0. Instead, use a version that's compatible with AGP 2.3.0, like 12.0.1:

    dependencies {
        // For AGP 2.3.0, use 'compile' instead of 'implementation'
        compile 'com.google.android.gms:play-services-ads:12.0.1'
    }
    
  • Update AndroidManifest.xml
    Add the required permissions and AdMob app ID meta-data:

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <application ...>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/> <!-- Replace with your actual App ID -->
    </application>
    
  • Sync and Rebuild
    After making these changes, click "Sync Project with Gradle Files" and let the project rebuild. If you still get errors, try cleaning the project first (Build > Clean Project).

内容的提问来源于stack exchange,提问作者Harshit Agrawal

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 04:26:42