English README.md 中文 README_zh.md
TraceFix 是一个编译期字节码插桩插件,会在方法前后自动插入 android.os.Trace.beginSection/endSection。
| 你的目标 | 选择 | 看这一节 |
|---|---|---|
| 在业务 App 里接入 TraceFix | 远程插件(推荐) | 「远程插件用法」 |
| 在本仓库开发/调试插件 | 本地插件(mavenLocal) |
「本地插件用法」 |
| 验证高低版本兼容性 | 2x2 Demo 矩阵 | 「兼容性验证」 |
已发布版本:io.github.gracker:TraceFix:0.1.0
Maven Central 仓库地址:https://repo1.maven.org/maven2/io/github/gracker/TraceFix/0.1.0/
- 在
gradle.properties配置版本:
TRACEFIX_VERSION=0.1.0- 在 module 或 root 的
build.gradle添加插件 classpath:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("io.github.gracker:TraceFix:${TRACEFIX_VERSION}") { changing = true }
}
}- 在 app module 应用插件:
apply plugin: 'auto-add-systrace'- 编译后用 Perfetto 查看结果:
https://ui.perfetto.dev/#!/viewer。
- 配置 Central Portal Token(任选一种来源):
- 环境变量:
export OSSRH_USERNAME=... # https://central.sonatype.com/usertoken 的 token username
export OSSRH_PASSWORD=... # https://central.sonatype.com/usertoken 的 token password- 或根目录
local.properties:
ossrhUsername=...
ossrhPassword=...- 配置签名(任选一种):
- 内存私钥:
export SIGNING_KEY='-----BEGIN PGP PRIVATE KEY BLOCK-----...'
export SIGNING_PASSWORD=...
export SIGNING_KEY_ID=... # 可选- Gradle 传统签名配置(
~/.gradle/gradle.properties或local.properties):
signing.keyId=...
signing.password=...
signing.secretKeyRingFile=/path/to/secring.gpg- 或使用系统 GPG:
useGpgCmd=true- 确认 namespace(当与
publishedGroupId不一致时再配置):
export TRACEFIX_CENTRAL_NAMESPACE=io.github.gracker- 先做配置检查:
./gradlew :android-systrace-plugin:verifyReleasePublishConfig- 按最新流程发布:
./gradlew :android-systrace-plugin:publishReleaseToCentral兼容别名命令:
./gradlew :android-systrace-plugin:publishReleaseToSonatype- 先发布到本地 Maven:
./gradlew :android-systrace-plugin:publishToMavenLocal- 使用本地 Demo 模块验证:
- 低版本 AGP 本地插件 Demo:
android-systrace-sample-local-debug - 高版本 AGP 本地插件 Demo:
android-systrace-sample-high-local-debug
一条命令跑完高低版本 × 本地/远程插件:
LOW_AGP_VERSION=7.4.2 HIGH_AGP_VERSION=8.3.2 ./scripts/verify-compatibility.sh脚本会检查:
- 已插入
Trace.beginSection。 - 已插入
Trace.endSection。 - 异常路径可配对(变换后
traceExceptionDemo存在athrow路径)。
| AGP | 本地插件 | 远程插件 |
|---|---|---|
| 7.4.2 | android-systrace-sample-local-debug |
android-systrace-sample-low-remote-debug |
| 8.3.2 | android-systrace-sample-high-local-debug |
android-systrace-sample-remote-debug |
远程 Demo 额外注意:
- 同步/构建时需要开启远程 Demo 模块:
-PTRACEFIX_ENABLE_REMOTE_DEMOS=true- 需要指定远程插件版本和仓库地址:
-PTRACEFIX_VERSION_REMOTE=1.0 -PTRACEFIX_REMOTE_REPO_URL=file://$PWD/build/tracefix-remote-repo- 用
TRACEFIX_AGP_VERSION切换仓库构建使用的 AGP。 - 用
TRACEFIX_AGP_API_VERSION指定插件编译期gradle-api版本(默认跟随TRACEFIX_AGP_VERSION,兜底7.4.2)。 - 对于更老的 AGP(只有 Transform API),建议单独维护 legacy 分支或 artifact。