skills/rasy007/android-skills/android-gradle-doctor

android-gradle-doctor

Installation
SKILL.md

Android Gradle 构建诊断工具

分析 Gradle 构建问题,检测依赖冲突,生成优化建议。

适用场景

  • Gradle 构建失败(sync error、编译错误)
  • 依赖版本冲突(Duplicate class、版本不兼容)
  • 构建速度慢,需要优化
  • 检查 build.gradle 常见配置问题
  • 升级 AGP(Android Gradle Plugin)后出错

使用方式

脚本位置:scripts/gradle_doctor.py(相对于本 Skill 目录)

诊断构建问题

# 全面诊断(扫描 build.gradle + 检查依赖)
python3 <SKILL_DIR>/scripts/gradle_doctor.py diagnose <module_path>

# 仅扫描 build.gradle 配置问题
python3 <SKILL_DIR>/scripts/gradle_doctor.py scan <module_path>

# JSON格式输出
python3 <SKILL_DIR>/scripts/gradle_doctor.py diagnose <module_path> --json

分析依赖

# 分析 dependencies 输出,检测版本冲突
./gradlew :app:dependencies --configuration releaseRuntimeClasspath > deps.txt
python3 <SKILL_DIR>/scripts/gradle_doctor.py deps deps.txt

# 检查指定库的版本冲突
python3 <SKILL_DIR>/scripts/gradle_doctor.py deps deps.txt --filter okhttp

生成优化建议

# 构建加速建议
python3 <SKILL_DIR>/scripts/gradle_doctor.py optimize <project_root>

查看常见错误修复指南

# 列出所有常见错误
python3 <SKILL_DIR>/scripts/gradle_doctor.py errors

# 查看特定错误的修复方案
python3 <SKILL_DIR>/scripts/gradle_doctor.py error "duplicate class"
python3 <SKILL_DIR>/scripts/gradle_doctor.py error "could not resolve"

检测项

build.gradle 扫描

检测项 说明
过时 API compileimplementationtestCompiletestImplementation
重复依赖 同一库在不同 configuration 中重复声明
动态版本 1.+latest.release 等不确定版本
缺失配置 缺少 compileSdkVersionminSdkVersion
BuildConfig buildConfigField 格式检查
Kotlin 版本 检查 Kotlin 版本与 AGP 兼容性

依赖分析

检测项 说明
版本冲突 同一库的不同版本被依赖( 标记)
强制版本 被 Gradle 强制解析到其他版本的依赖
冗余依赖 已被传递依赖包含的直接依赖

构建优化

优化项 说明
gradle.properties 并行构建、构建缓存、JVM 参数
Configuration Cache AGP 7.0+ 支持
Build Cache 本地 + 远程缓存
Kotlin 增量编译 检查是否启用

AI 使用指南

当用户遇到以下情况时,自动使用本工具:

  • "构建失败" / "sync 报错" → diagnose 全面诊断
  • "依赖冲突" / "Duplicate class" → deps 分析依赖
  • "构建太慢" / "编译慢" → optimize 优化建议
  • "build.gradle 有什么问题" → scan 扫描配置
Weekly Installs
2
GitHub Stars
1
First Seen
6 days ago
Installed on
amp2
cline2
opencode2
cursor2
kimi-cli2
warp2