English README.md 中文 README_zh.md
TraceFix instruments Android app bytecode at compile time and injects paired android.os.Trace.beginSection/endSection calls around methods. These sections show up in Perfetto or other platform trace viewers; TraceFix only adds app-side trace sections and does not replace capture tooling such as Perfetto, atrace, or ProfilingManager.
The Android Performance Ecosystem brings its navigation Hub and seven core projects into an optional path from instrumentation and capture to analysis, system knowledge, and reproducible cases.
| Stage | Project | Purpose | Address |
|---|---|---|---|
| Navigate | Android Performance Ecosystem | Maintain the shared project map, handoff metadata, generated README navigation, and drift checks. | GitHub |
| Instrument | TraceFix | Inject app-side android.os.Trace sections at build time so method work is visible at runtime. | GitHub |
| Capture and measure | Perfetto Tools | Capture repeatable Perfetto traces and collect FPS or Simpleperf measurements. | GitHub |
| Analyze | SmartPerfetto | Investigate traces with an AI-assisted Web UI, CLI, reports, sessions, comparisons, and evidence workflow. | GitHub |
| Agent analysis | Perfetto Skills | Give agents a portable Perfetto analysis Skill for Android, Linux, and Chromium, with selected assets synchronized through pinned workflows. | GitHub |
| Learn | Android Performance Blog | Teach Perfetto and Systrace analysis through articles, system explanations, and case studies. | AndroidPerformance.com · GitHub |
| System knowledge | Android Internal Wiki | An alpha knowledge base for Android mechanisms from App to Framework, Native, and Kernel. | GitHub |
| Reproduce | Trace for Blog (SystraceForBlog) | Provide the Perfetto, Systrace, and related case files used by articles for hands-on reproduction. | GitHub |
TraceFix 0.2.x targets the Android 17 / API 37 code base:
| Component | Version |
|---|---|
| Artifact | io.github.gracker:TraceFix:0.2.1 |
| Android Gradle Plugin | 9.1.1 |
| Gradle | 9.3.1 |
| Compile SDK / Target SDK | 37 |
| Java | 17 |
The 0.1.x line was the legacy AGP 7.4/8.3 compatibility line. Use 0.2.x for Android 17 / AGP 9.1.x projects, and keep 0.1.x only for older builds that still need the previous compatibility matrix.
| Your Goal | Choose | Use This |
|---|---|---|
| Integrate TraceFix into your app | Remote plugin | "Remote Plugin" |
| Develop or debug plugin in this repo | Local plugin (mavenLocal) |
"Local Plugin" |
| Verify Android 17 behavior | Trace regression script | "Compatibility Verification" |
Version 0.2.1 is available as a Maven repository ZIP on the GitHub release. Unzip it and add maven { url = uri('/path/to/extracted/repo') } inside buildscript.repositories, alongside Google and Maven Central. Use the directory containing io/ as the repository root. Central publication status is visible in the artifact index.
Gradle coordinate:
classpath("io.github.gracker:TraceFix:0.2.1")Example module or root build.gradle:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("io.github.gracker:TraceFix:0.2.1")
}
}
apply plugin: 'com.android.application'
apply plugin: 'auto-add-systrace'Optional configuration:
traceFix {
enabled = true
// Empty include lists mean "all"; excludes win over includes.
includedVariants = []
excludedVariants = []
includedBuildTypes = []
excludedBuildTypes = []
includedClassPrefixes = []
excludedClassPrefixes = [
'com.example.generated.'
]
traceConstructors = true
traceClassInitializers = true
traceSyntheticMethods = false
traceBridgeMethods = false
}TraceFix skips abstract and native methods because they have no instrumentable method body. Synthetic and bridge methods are skipped by default to avoid adding noisy sections for compiler-generated methods; enable them only when you intentionally want compiler-generated code in traces.
TraceFix instruments each module's project classes. Apply it to each application, Android library or dynamic feature you want to trace. A build type such as debug selects every matching product flavor. An enabled variant must match both configured include lists and pass both exclusions. Class prefixes accept dots or slashes. To match a package, include its trailing separator. Bridge methods have their own switch, including bridges marked synthetic.
Constructors open a section after their delegated constructor returns. For variants with minSdk below 18, generated code checks the device API before calling Trace. Variants targeting minSdk 18 or higher use direct calls.
Section names are readable method names with a stable hash suffix, capped to Android's 127 UTF-16 code-unit trace section limit.
Publish the plugin to local Maven:
./gradlew :android-systrace-plugin:publishTraceFixLocalPublicationToMavenLocalBuild local demo modules with:
./gradlew -PTRACEFIX_ENABLE_DEMOS=true \
:android-systrace-sample-high-local-debug:assembleDebug \
:android-systrace-sample-high-local-debug:assembleReleaseDemo modules are not included by default, so the plugin can build without pulling sample app configuration into normal development.
Run the Android 17 trace regression:
./scripts/verify-compatibility.shThe script verifies:
- Local Java fixture on AGP 9.1.1, debug and minified release.
- Remote Kotlin fixture through a file-backed Maven repository, debug and minified release.
- Method-level bytecode instrumentation via
javap, including normal returns and exception paths. - Edge cases: overloads, synchronized methods, long method names, interface default methods, concrete methods in abstract classes, skipped abstract/native methods, and skipped Kotlin synthetic
$defaultmethods.
The release check uses the SDK’s dexdump to confirm that both Trace calls survive R8 in the packaged APK. The regression also builds an Android library and a dynamic feature, exercises per-build-type selection and verifies the SDK guard. The plugin build runs JVM tests that load and execute transformed bytecode against a recording Trace stub.
To run the same plugin binary on another consumer toolchain, set AGP_VERSION and GRADLE_BIN before running the script. Set COMPILE_SDK to test another installed SDK. The producer uses the repository wrapper. The defaults are in gradle.properties.
Remote demo modules can be built manually with:
./gradlew -PTRACEFIX_ENABLE_REMOTE_DEMOS=true \
-PTRACEFIX_REMOTE_REPO_URL=file://$PWD/build/tracefix-remote-repo \
:android-systrace-sample-remote-debug:assembleDebug \
:android-systrace-sample-remote-debug:assembleReleaseA version tag matching TRACEFIX_VERSION (for example v0.2.1) runs the compatibility matrix and publishes its verified repository ZIP on GitHub Releases. The manual Central workflow uses its own credentials.
Maintainers can publish from GitHub Actions by opening the Publish TraceFix workflow and running it on the verified release commit’s branch. Configure these repository secrets first:
| Secret | Required | Notes |
|---|---|---|
OSSRH_USERNAME |
Yes | Central Portal token username. MAVEN_CENTRAL_USERNAME or SONATYPE_USERNAME also work. |
OSSRH_PASSWORD |
Yes | Central Portal token password. MAVEN_CENTRAL_PASSWORD or SONATYPE_PASSWORD also work. |
SIGNING_KEY |
Yes | ASCII-armored PGP private key for in-memory signing. |
SIGNING_PASSWORD |
Yes | Signing key password. SIGNING_PASSPHRASE also works. |
SIGNING_KEY_ID |
Optional | Required only when the in-memory key needs an explicit key id. |
Optional repository variables:
| Variable | Default |
|---|---|
TRACEFIX_CENTRAL_NAMESPACE |
io.github.gracker |
TRACEFIX_CENTRAL_PUBLISHING_TYPE |
automatic |
TRACEFIX_CENTRAL_SKIP_FINALIZE |
unset |
The workflow runs the Android 17 build and trace regression before publishing. Local manual publishing can use legacy keyring or system GPG, but the GitHub workflow intentionally uses in-memory signing because GitHub-hosted runners do not have your local GPG keyring.
Manual local publish is also supported:
- Configure Central Portal token credentials:
export OSSRH_USERNAME=... # token username from https://central.sonatype.com/usertoken
export OSSRH_PASSWORD=... # token password from https://central.sonatype.com/usertokenOr use root local.properties:
ossrhUsername=...
ossrhPassword=...- Configure signing:
export SIGNING_KEY='-----BEGIN PGP PRIVATE KEY BLOCK-----...'
export SIGNING_PASSWORD=...
export SIGNING_KEY_ID=... # optionalLegacy Gradle signing properties and system GPG are also supported:
signing.keyId=...
signing.password=...
signing.secretKeyRingFile=/path/to/secring.gpg
# or
useGpgCmd=true- Verify publish configuration:
./gradlew :android-systrace-plugin:verifyReleasePublishConfig- Publish release artifact:
./gradlew :android-systrace-plugin:publishReleaseToCentralCompatibility alias:
./gradlew :android-systrace-plugin:publishReleaseToSonatypeAfter publishing, verify Maven Central:
curl -I https://repo1.maven.org/maven2/io/github/gracker/TraceFix/0.2.1/TraceFix-0.2.1.pom