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

Gradle Spoon任务报NoSuchMethodError:LogCatMessage.getTag()错误

问题根因

java.lang.NoSuchMethodError: 'java.lang.String com.android.ddmlib.logcat.LogCatMessage.getTag()'是典型的依赖版本冲突问题:

  • 你引入的com.jaredsburrows:gradle-spoon-plugin:1.6.0传递依赖了低版本com.android.tools.ddms:ddmlib,低版本中LogCatMessage类没有和高版本Android Gradle Plugin(AGP)匹配的getTag()方法签名
  • 原生Android测试流程不会加载spoon插件带入的低版本ddmlib,所以常规运行测试不会触发报错
解决步骤

1. 移除重复的spoon插件声明

你同时在buildscript.dependencies和plugins块重复声明了spoon插件,会导致类加载冲突,直接删掉buildscript块内的spoon相关classpath配置,仅保留plugins块的声明即可。

2. 强制指定匹配当前AGP的ddmlib版本

在app模块build.gradle的android块同级位置,添加如下配置,强制覆盖spoon插件传递依赖的低版本ddmlib:

configurations.all {
    resolutionStrategy {
        // 对应compileSdk 32配套的AGP 7.2.x版本,后续升级AGP时替换为对应大版本号即可
        force 'com.android.tools.ddms:ddmlib:27.2.0'
    }
}

3. 对齐AndroidX测试依赖版本

你当前注释掉了部分核心测试依赖,容易出现隐性版本不匹配问题,将androidTest相关依赖统一对齐版本,修改dependencies块的测试依赖部分如下:

dependencies {
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
    testImplementation 'junit:junit:4.13.2'

    // 统一对齐AndroidX测试依赖版本
    androidTestImplementation 'androidx.test:core:1.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.1'
}

4. 清理缓存重新执行任务

先执行命令清理旧构建缓存,再重新运行spoon任务:

./gradlew clean
./gradlew spoon
版本校验

如果执行后仍有同类报错,运行如下依赖排查命令,确认ddmlib实际解析版本为你强制指定的版本,没有被其他低版本覆盖即可:

./gradlew app:dependencies | grep ddmlib

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.01 00:24:21