移除Android项目config.xml中AdMob相关标签后报错,求解决方案
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
Find all references to the AdMob resources
- In Android Studio, click on one of the string names (like
banner_ad_unit_id) in yourconfig.xml. - Press
Alt+F7(Windows/Linux) orOption+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, andtest_device_id.
- In Android Studio, click on one of the string names (like
Remove or comment out all references
- For example, if you see code like this in an Activity:
Or code loading a banner ad:MobileAds.initialize(this, getString(R.string.ad_app_id))
Delete or comment out these blocks of code.AdView adView = findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); - Check your layout XMLs too—if you have an
AdViewwidget withapp:adUnitId="@string/banner_ad_unit_id", delete that entireAdViewelement.
- For example, if you see code like this in an Activity:
Remove AdMob dependencies (optional but recommended)
- Open your app module’s
build.gradlefile (look for the one labeledModule: app). - Find the line that looks like:
Delete this line, then click "Sync Now" at the top right of Android Studio.implementation 'com.google.android.gms:play-services-ads:22.6.0'
- Open your app module’s
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.
- Go to the top menu:
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

