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

解决Android项目Google Play服务测量类重复编译错误

解决Google Play服务测量模块重复类编译异常

核心问题分析

你遇到的org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException本质是不同版本的Google Play测量模块存在重复类冲突——比如play-services-measurement-base:21.1.0和play-services-measurement-impl:19.0.0版本不匹配,导致同一类被多次打包,触发编译错误。

具体解决方案

1. 强制统一测量模块版本

在根目录build.gradle中添加版本强制配置,确保所有测量相关模块使用同一版本:

allprojects {
    repositories {
        // 保留你的原有仓库配置
    }
    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-measurement-base:21.1.0'
            force 'com.google.android.gms:play-services-measurement-impl:21.1.0'
            // 按需添加其他测量子模块,比如measurement-api、measurement-sdk等,统一为21.1.0版本
        }
    }
}

2. 排查依赖树定位冲突来源

执行Gradle命令生成完整依赖树,找出引入旧版本测量模块的第三方库:

./gradlew app:dependencies --configuration releaseRuntimeClasspath

搜索play-services-measurement相关条目,定位到问题依赖后,在模块build.gradle中排除冲突模块:

dependencies {
    implementation('存在问题的第三方库坐标') {
        exclude group: 'com.google.android.gms', module: 'play-services-measurement-impl'
    }
}

3. 彻底清理Gradle缓存

执行命令清理缓存并刷新依赖,避免旧版本文件残留:

./gradlew clean build --refresh-dependencies

也可手动删除本地Gradle缓存目录:

  • macOS/Linux:~/.gradle/caches
  • Windows:C:\Users\<你的用户名>\.gradle\caches

4. 处理Catalon插件自带依赖

如果是Catalon插件引入了冲突依赖,尝试更新插件版本,或在模块build.gradle中排除插件内的测量模块:

dependencies {
    implementation('com.catalon:对应插件坐标:版本号') {
        exclude group: 'com.google.android.gms', module: 'play-services-measurement-base'
        exclude group: 'com.google.android.gms', module: 'play-services-measurement-impl'
    }
}

验证步骤

  1. 执行./gradlew clean清理项目
  2. 重新编译项目,检查异常是否消除

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 13:48:22