blob: acf20054423a99426b4a179a68e4b54256867d2a [file] [view] [edit]
# Dev Environment for LeakCanary contributors
## Setup
* Download [Android Studio](https://developer.android.com/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 :samples:leakcanary-android-sample:connectedCheck`.
* Normal UI tests: `./gradlew :leakcanary:leakcanary-android-core:connectedCheck`.
## Static Code Analysis
* LeakCanary [uses](https://github.com/square/leakcanary/pull/1535) [Detekt](https://arturbosch.github.io/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; the GitHub Actions build 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:
```kotlin
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 (`~/.m2/repository`):
```
./gradlew publishToMavenLocal
```
Then add the SNAPSHOT dependency and `mavenLocal()` repository to your project:
```gradle
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
```