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

Android Manifest合并问题:移除谷歌广告Gradle依赖后节点未清除

解决移除Google Ads依赖后残留导致的构建报错问题

Hey there, let's work through this issue where removing the Google Ads dependency from your free flavor isn't fully clearing it out, leading to build errors in the merged manifest. Here are the actionable steps to fix this:

1. 彻底清理Gradle与IDE缓存

First, let's eliminate cached artifacts as the culprit:

  • In Android Studio, go to File > Invalidate Caches... > Invalidate and Restart to wipe IDE-level caches completely.
  • Run these commands in your project root to clear Gradle's build cache and intermediate files:
    ./gradlew clean
    ./gradlew cleanBuildCache
    
  • Manually delete the .gradle folder in your project root, plus the build folders in both your app module and project root. Then sync your project again.

2. 排查间接依赖

Even if you removed the direct freeCompile dependency, another library might be pulling in play-services-ads transitively. To check this:

  • Run this command to generate a detailed dependency tree for your free flavor:
    ./gradlew app:dependencies --configuration freeRuntimeClasspath
    
  • Scan the output for any entry of com.google.android.gms:play-services-ads. If you find it, identify which parent dependency is bringing it in, then exclude it using Gradle's exclude rule in your free flavor dependencies block:
    dependencies {
        // Your other free flavor dependencies
        implementation('some-third-party-library:1.0.0') {
            exclude group: 'com.google.android.gms', module: 'play-services-ads'
        }
    }
    

3. 清理风味特定的Manifest与配置

The error points to the merged manifest, so let's hunt for leftover Ads-related configs:

  • Navigate to src/free/AndroidManifest.xml and remove any Google Ads-related entries (like <meta-data> for ad app ID, <activity> for AdActivity, or ads-related permissions).
  • Check your app's main AndroidManifest.xml to ensure no Ads-related entries are merging into the free flavor.
  • If you used manifest placeholders for Ads, remove those from the free flavor's build.gradle block:
    productFlavors {
        free {
            // Remove any ads-related manifest placeholders here
            // manifestPlaceholders = [adAppId: "ca-app-pub-xxx"]
        }
        pro {
            // Pro flavor config
        }
    }
    

4. 验证合并后的Manifest

To pinpoint exactly what's lingering in the merged manifest for the free flavor:

  • Switch to the Project view in Android Studio, then navigate to app/build/intermediates/manifests/full/free/debug (or release, depending on your build variant).
  • Open the AndroidManifest.xml file and search for remaining Google Ads-related entries. The comments in the merged manifest will show you which source file they came from—go clean that file up.

After working through these steps, sync your project and rebuild it. This should fully remove all traces of the Google Ads dependency from your free flavor.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:33:33