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

升级AGP与Gradle版本后使用Hugo插件报错求助

解决Hugo插件在AGP 7.0+及Gradle 7.2+下的适配错误

错误根源

你遇到的Could not find method debugCompile()错误,本质是Hugo 1.2.1插件内部仍使用已被AGP 7.0+彻底移除的旧依赖配置debugCompile。AGP从3.0版本开始就推荐用debugImplementation替代debugCompile,到7.0版本直接删除了该方法,导致插件执行时找不到对应逻辑。

可行解决方法

方案1:改用社区维护的适配版Hugo插件

原Hugo仓库已停止更新,社区有fork版本完成了对Gradle 7.x和AGP 7.x的适配。修改项目根目录build.gradle中的插件依赖:

buildscript {
    repositories {
        // 确保添加mavenCentral和jitpack仓库,用于拉取适配版本
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
        // 其他仓库保持不变...
    }
    dependencies {
        // 替换原Hugo插件依赖为适配版本
        classpath 'com.github.triplet.gradle:hugo-plugin:2.0.0'
        // 其他依赖(AGP、google-services等)保持不变...
    }
}

方案2:手动修复插件依赖配置(不推荐,繁琐)

如果坚持使用原Hugo 1.2.1版本,可通过自定义Gradle脚本绕过插件的错误逻辑:

  1. 在项目根目录创建hugo-fix.gradle文件,写入以下内容:
gradle.projectsEvaluated {
    project.android.applicationVariants.each { variant ->
        if (variant.buildType.name == 'debug') {
            variant.dependencies.add('implementation', 'com.jakewharton.hugo:hugo-runtime:1.2.1')
        }
    }
}
  1. 打开App模块的build.gradle,注释掉原Hugo插件引用,改为应用自定义脚本:
// apply plugin: 'com.jakewharton.hugo'
apply from: rootProject.file('hugo-fix.gradle')
  1. 移除根目录buildscript中的classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'依赖。

方案3:替换为官方工具(长期推荐)

若无需依赖Hugo,建议改用Android官方的方法追踪工具:

  • 使用Android Studio Profiler中的Method Tracing,可视化追踪方法耗时
  • 接入Firebase Performance Monitoring,实现更全面的性能监控
    这些工具适配最新AGP和Android版本,且有官方持续维护。

额外适配建议

  • AGP 7.0+建议将jcenter()替换为mavenCentral(),因为JCenter已停止维护,部分依赖可能无法获取
  • 确保Gradle版本与AGP版本匹配:AGP 7.0.2对应Gradle 7.0及以上版本(你当前使用的7.2符合要求)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 10:17:38