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

移除Android项目config.xml中AdMob相关标签后报错,求解决方案

Fixing Errors When Removing AdMob Config from Android Project

Hey there, fellow Android Studio newbie! No need to apologize—we’ve all been there when following docs doesn’t go as smoothly as expected. Let’s break down why you’re seeing errors when removing those AdMob string tags and how to fix it.

Why You’re Getting Errors

The most likely culprit is that your project’s code (Java/Kotlin files, layout XMLs, or other configs) is still referencing those AdMob string resources you removed. Android Studio’s compiler throws errors because it can’t find the resources the code is trying to access.

Step-by-Step Fix

  1. Find all references to the AdMob resources

    • In Android Studio, click on one of the string names (like banner_ad_unit_id) in your config.xml.
    • Press Alt+F7 (Windows/Linux) or Option+F7 (Mac) to bring up the "Find Usages" tool. This will show every place in your project that uses that resource.
    • Repeat this for interstitial_ad_unit_id, ad_app_id, and test_device_id.
  2. Remove or comment out all references

    • For example, if you see code like this in an Activity:
      MobileAds.initialize(this, getString(R.string.ad_app_id))
      
      Or code loading a banner ad:
      AdView adView = findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder().build();
      adView.loadAd(adRequest);
      
      Delete or comment out these blocks of code.
    • Check your layout XMLs too—if you have an AdView widget with app:adUnitId="@string/banner_ad_unit_id", delete that entire AdView element.
  3. Remove AdMob dependencies (optional but recommended)

    • Open your app module’s build.gradle file (look for the one labeled Module: app).
    • Find the line that looks like:
      implementation 'com.google.android.gms:play-services-ads:22.6.0'
      
      Delete this line, then click "Sync Now" at the top right of Android Studio.
  4. Clean and rebuild your project

    • Go to the top menu: Build > Clean Project
    • Then: Build > Rebuild Project
    • This clears any cached resources that might be causing leftover errors.

Example of a Cleaned config.xml

If you’re fully removing AdMob support, your file should look like this (empty resources tag is totally valid):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- No AdMob config left here -->
</resources>

Take it slow—check each reference one by one, and you’ll get those errors cleared up in no time!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:34:29