Files
leakcanary/docs/dev-env.md
pblundell 58a5c1cc67 Fix COMPOSITION_IMPL inspector for new Compose state field structure
Fixes NullPointerException when analyzing heap dumps from newer Compose versions
where CompositionImpl uses "state" int field instead of "disposed" boolean field.

The inspector now gracefully handles both field structures:
- Old Compose: disposed boolean field (backward compatibility)
- New Compose: state int field with values RUNNING=0, DISPOSED=3, etc.
- Edge case: neither field exists (graceful fallback)

Before: NullPointerException at AndroidObjectInspectors$COMPOSITION_IMPL$inspect line 792
After: Analysis completes successfully with proper state detection

Fixes: https://github.com/square/leakcanary/issues/2781

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-25 16:40:02 +00:00

2.4 KiB

Dev Environment for LeakCanary contributors

Setup

  • Download Android Studio.
  • We use two spaces code indentation, use SquareAndroid code style settings from https://github.com/square/java-code-styles.
  • Build with ./gradlew build.
  • Running the failing UI tests to confirm leak detection correctly fails UI tests: ./gradlew leakcanary-android-sample:connectedCheck.
  • Normal UI tests: ./gradlew leakcanary-android-core:connectedCheck.

Static Code Analysis

  • LeakCanary uses Detekt for static Code analysis.
  • Analyze the entire project with ./gradlew check or particular modules with ./gradlew :module-name:check. Detekt will fail the build if any ruleset violations are found. You should fix all issues before pushing the branch to remote.
    • There's also a git pre-push hook that will run analysis automatically before pushing a branch to the remote. If there are any violations - it will prevent the push. Fix the issues!
    • You can bypass the git hook though; Travis CI will still run checks and will fail if any violations are found.
  • Detekt report will be printed in the console and saved to /moduleDir/build/reports/.

Unit Testing with Synthetic Heap Dumps

When testing heap analysis functionality, create synthetic heap dumps programmatically instead of committing binary .hprof files:

val heapDump = dump {
  "com.example.MyClass" watchedInstance {
    field["fieldName"] = BooleanHolder(true)
  }
}
  • Requires testImplementation(projects.shark.sharkHprofTest).
  • See LeakStatusTest or AndroidObjectInspectorsTest for examples.

Deploying locally

To deploy LeakCanary to your local maven repository, run the following command, changing the path to the path of your local repository:

./gradlew uploadArchives -PSNAPSHOT_REPOSITORY_URL=file:///Users/py/.m2/repository

Then add the SNAPSHOT dependency and mavenLocal() repository to your project:

dependencies {
  debugImplementation 'com.squareup.leakcanary:leakcanary-android:{{ leak_canary.next_release }}-SNAPSHOT'
}

repositories {
  mavenLocal()
}

Deploying the docs locally

Installing or updating the docs dependencies:

pip install --requirement docs/requirements.txt

Deploying locally

mkdocs serve