Skip to content

Commit bd29fac

Browse files
committed
README.md
1 parent 6d36b28 commit bd29fac

2 files changed

Lines changed: 132 additions & 107 deletions

File tree

.idea/workspace.xml

Lines changed: 2 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 130 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
# ⚠️ Not Working On Android Im Working On It
2-
# Dead Code Detector Gradle Plugin
1+
# Dead Code Detector Gradle Plugin (Android Edition)
32

4-
**Dead Code Detector** is a Kotlin-based Gradle plugin that analyzes compiled classes, resources, and dependencies, generating a human-readable report of unused (dead) code, resources, and libraries in your project.
3+
> ⚠️ Android support is in progress
4+
5+
**Dead Code Detector** is a Kotlin-based Gradle plugin that analyzes compiled classes, Android resources, and dependencies, generating a report of unused (dead) code and libraries in your project.
56

67
---
78

8-
## Table of contents
9+
## Table of Contents
910

1011
* [Why use this plugin?](#why-use-this-plugin)
1112
* [Features](#features)
12-
* [Quickstart (install & run)](#quickstart-install--run)
13+
* [Quickstart](#quickstart)
1314
* [Configuration](#configuration)
1415
* [Tasks](#tasks)
1516
* [Report format & example](#report-format--example)
1617
* [CI integration](#ci-integration)
17-
* [How it works (brief)](#how-it-works-brief)
18+
* [How it works](#how-it-works)
1819
* [Limitations & notes](#limitations--notes)
1920
* [Contributing](#contributing)
2021
* [License](#license)
@@ -23,102 +24,144 @@
2324

2425
## Why use this plugin?
2526

26-
Keeping a codebase tidy improves maintainability, build times, and developer confidence. This plugin helps you find:
27+
Maintaining a clean Android codebase improves build times, maintainability, and developer confidence. This plugin helps you detect:
2728

28-
* Unreferenced top-level functions and fields
29-
* Unused classes
30-
* Dead resources
29+
* Unused classes, top-level functions, and fields
30+
* Dead resources (layouts, drawables, etc.)
3131
* Unused dependencies
3232

33-
It produces a plain-text report you can read locally or archive in CI.
33+
---
3434

3535
## Features
3636

37-
* Detects unused classes, top-level functions, and top-level fields in Kotlin/Java projects
38-
* Detects unused dependencies in your Gradle build
39-
* Detects unused resources (optionally scanning `src/main/resources` and `src/test/resources`)
40-
* Grouped, human-readable reports (method signatures, field types, dependency notations)
41-
* Configurable to keep public API, include/exclude tests, scan/exclude resources, exclude packages
42-
* Support for ignoring elements annotated with specific annotations
43-
* Optionally fail the build when dead code is detected
44-
* Can run manually or be attached to `check` for CI
37+
* Detects unused classes, methods, and fields in Kotlin/Java Android projects
38+
* Detects unused Android resources (`res/`)
39+
* Detects unused dependencies
40+
* Generates grouped, human-readable reports
41+
* Configurable: keep public API, include/exclude tests, scan/exclude resources, ignore packages or annotations
42+
* Optionally fail the build if dead code is detected
4543

46-
## Quickstart (install & run)
44+
---
4745

48-
Apply the plugin in your module's `build.gradle.kts`:
46+
## Quickstart
47+
48+
Apply the **Android-specific plugin** in your `app/build.gradle.kts`:
4949

5050
```kotlin
5151
plugins {
52-
id("io.github.arya458.dead-code-detector") version "0.0.5"
52+
alias(libs.plugins.android.application)
53+
alias(libs.plugins.kotlin.android)
54+
alias(libs.plugins.kotlin.compose)
55+
id("io.github.arya458.dead-code-detector-android")
5356
}
54-
```
5557

56-
Then run the detector manually:
58+
android {
59+
namespace = "io.github.arya458.testandroidjetpack"
60+
compileSdk = 36
61+
62+
defaultConfig {
63+
applicationId = "io.github.arya458.testandroidjetpack"
64+
minSdk = 24
65+
targetSdk = 36
66+
versionCode = 1
67+
versionName = "1.0"
68+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
69+
}
70+
71+
buildTypes {
72+
release {
73+
isMinifyEnabled = false
74+
proguardFiles(
75+
getDefaultProguardFile("proguard-android-optimize.txt"),
76+
"proguard-rules.pro"
77+
)
78+
}
79+
}
80+
81+
compileOptions {
82+
sourceCompatibility = JavaVersion.VERSION_11
83+
targetCompatibility = JavaVersion.VERSION_11
84+
}
85+
86+
kotlinOptions {
87+
jvmTarget = "11"
88+
}
89+
90+
buildFeatures {
91+
compose = true
92+
}
93+
}
5794

58-
```bash
59-
./gradlew deadCodeDetector
95+
dependencies {
96+
implementation(libs.androidx.core.ktx)
97+
implementation(libs.androidx.lifecycle.runtime.ktx)
98+
implementation(libs.androidx.activity.compose)
99+
implementation(platform(libs.androidx.compose.bom))
100+
implementation(libs.androidx.ui)
101+
implementation(libs.androidx.ui.graphics)
102+
implementation(libs.androidx.ui.tooling.preview)
103+
implementation(libs.androidx.material3)
104+
testImplementation(libs.junit)
105+
androidTestImplementation(libs.androidx.junit)
106+
androidTestImplementation(libs.androidx.espresso.core)
107+
androidTestImplementation(platform(libs.androidx.compose.bom))
108+
androidTestImplementation(libs.androidx.ui.test.junit4)
109+
debugImplementation(libs.androidx.ui.tooling)
110+
debugImplementation(libs.androidx.ui.test.manifest)
111+
}
112+
113+
// Dead Code Detector Configuration
114+
115+
deadCodeDetector {
116+
failOnDeadCode = true
117+
includeResources = true
118+
keepPublicApi = true
119+
}
60120
```
61121

62-
Or include it in your verification pipeline:
122+
Run the detector manually:
63123

64124
```bash
65-
./gradlew check
125+
./gradlew deadCodeDetectorDebug
126+
./gradlew deadCodeDetectorRelease
66127
```
67128

68-
By default the plugin writes its output to:
129+
Default report location:
69130

70131
```
71-
build/reports/dead-code-detector/report.txt
132+
app/build/reports/dead-code-detector/report.txt
72133
```
73134

74-
(You can override this in the configuration: see below.)
135+
---
75136

76137
## Configuration
77138

78-
Configure the plugin with the `deadCodeDetector` extension in your module's `build.gradle.kts`:
79-
80139
```kotlin
81140
deadCodeDetector {
82-
// Fail the build if any dead code is detected
83-
failOnDeadCode = true
84-
85-
// Scan test classes + test resources when true
86-
includeTests = false
87-
88-
// If true, public API (public functions/fields) are ignored from detection
89-
keepPublicApi = false
90-
91-
// (Planned) Automatically clear all dead code — not yet implemented
92-
// clearAllDeadCode = true
93-
94-
// Resource scanning
95-
includeResources = false
96-
resourceDir = "src/main/resources"
97-
testResourceDir = "src/test/res"
98-
99-
// Add package prefixes (or regex-like entries) to exclude from scanning
100-
excludePackages.add("com.mycompany.generated")
101-
102-
// Ignore elements annotated with these annotations
103-
keepAnnotations.add("javax.inject.Inject")
141+
failOnDeadCode = true // Fail the build if dead code is detected
142+
includeResources = true // Scan Android resources (res/)
143+
keepPublicApi = true // Ignore public API from detection
144+
excludePackages.add("com.mycompany.generated") // Exclude packages
145+
keepAnnotations.add("javax.inject.Inject") // Ignore elements with annotations
104146
}
105147
```
106148

107-
### Notes about configuration
149+
**Notes:**
108150

109-
* If you want to detect unused public API, set `keepPublicApi = false`. Be careful: this may flag intentionally public functions used by other modules or reflective consumers.
110-
* If you enable `includeResources`, the plugin will scan your resource directories (`resourceDir`, `testResourceDir`) for unused entries.
111-
* If you want to detect unused dependencies, simply run the plugin — unused dependency detection is included in the report.
112-
* If the plugin cannot find compiled classes, run `./gradlew classes` (or your module's compile tasks) before running the detector.
151+
* Run after building the app (`./gradlew assembleDebug`) so compiled classes and resources exist.
152+
* If `keepPublicApi = false`, public functions/classes may be flagged even if used by other modules.
153+
154+
---
113155

114156
## Tasks
115157

116-
* `deadCodeDetector` — main task that scans compiled classes, resources, and dependencies, producing the report
117-
* Integration with `check` — if wired in the plugin, `./gradlew check` will run the detector (depending on configuration)
158+
* `deadCodeDetectorDebug` — scans the debug variant
159+
* `deadCodeDetectorRelease` — scans the release variant
160+
* Integration with `check` can be added for CI pipelines
118161

119-
## Report format & example
162+
---
120163

121-
The report is a plain text file grouped by dead classes, methods, fields, resources, and dependencies. A typical (shortened) example looks like this:
164+
## Report format & example
122165

123166
```
124167
# Dead Code Detector Report
@@ -127,7 +170,7 @@ Summary:
127170
* Dead methods: 2
128171
* Dead fields: 1
129172
* Dead classes: 1
130-
* Dead resources: 1
173+
* Dead resources: 3
131174
* Unused dependencies: 1
132175
133176
Dead Classes:
@@ -140,17 +183,18 @@ Dead Fields:
140183
Class: com.example.MainKt • unusedValue : String
141184
142185
Dead Resources:
143-
* src/main/resources/old_config.json
186+
* res/layout/old_layout.xml
187+
* res/drawable/old_icon.png
144188
145189
Unused Dependencies:
146190
* implementation("com.squareup.retrofit2:retrofit:2.9.0")
147191
```
148192

149-
The plugin attempts to present readable signatures, resource paths, and dependency notations.
193+
---
150194

151-
## CI integration
195+
## CI Integration
152196

153-
Example GitHub Actions workflow:
197+
GitHub Actions example:
154198

155199
```yaml
156200
name: CI
@@ -165,42 +209,35 @@ jobs:
165209
with:
166210
java-version: '17'
167211
- name: Run Gradle build + dead-code-detector
168-
run: ./gradlew check --no-daemon
212+
run: ./gradlew assembleDebug deadCodeDetectorDebug --no-daemon
169213
```
170214
171-
If you prefer the detector not to fail CI, set `failOnDeadCode = false` in the extension.
215+
Set `failOnDeadCode = false` if you don’t want CI to fail.
172216

173-
## How it works (brief)
217+
---
174218

175-
The plugin analyzes compiled class files, resources, and dependency references to determine which items are never referenced. Bytecode-level analysis makes detection reliable for compiled artifacts, but reflection or generated code may cause false positives.
219+
## How it works
176220

177-
If you plan to use this in multi-module projects, run the detector in modules where compiled classes are available; otherwise, point to the compiled class directories if supported by the plugin configuration.
221+
The plugin scans compiled class files, Android resources, and dependency references to detect unused elements. Reflection, generated code, or annotation processors may create false positives.
178222

179-
## Limitations & notes
223+
---
180224

181-
* **Local variables** are not detected (Kotlin compiler may remove them in bytecode).
182-
* **Reflection, dynamic calls, annotation processors, and dependency injection** can create false positives — code/resources/dependencies used only reflectively might appear unused.
183-
* **Public API**: if your project exposes public functions/classes used by external consumers, set `keepPublicApi = true` to avoid false positives.
184-
* Run the plugin after building the classes (`./gradlew classes`) so compiled output is present.
185-
* `clearAllDeadCode` is currently a planned feature and not implemented.
225+
## Limitations & Notes
186226

187-
## Contributing
227+
* **Local variables** are ignored (removed by Kotlin/Java compiler).
228+
* **Reflection/dynamic calls** may appear unused.
229+
* **Public API**: enable `keepPublicApi = true` to avoid false positives.
230+
* Run after compiling the project to ensure class files exist.
188231

189-
Contributions and issues are welcome.
232+
---
190233

191-
Ideas for improvements:
234+
## Contributing
192235

193-
* Implement `clearAllDeadCode` option
194-
* Add HTML output or colored console output
195-
* Add more fine-grained ignore rules (annotations, regex, resource types)
196-
* Add integration with Detekt or other static analysis tools
236+
* Ideas: HTML/colored reports, integration with Detekt, more annotation rules
237+
* Pull requests and issues are welcome
197238

198-
Please open issues or PRs against this repository.
239+
---
199240

200241
## License
201242

202-
MIT License — feel free to use and modify the code.
203-
204-
---
205-
206-
*Generated by a friendly README polish to make the repository easier for others to use.*
243+
MIT License

0 commit comments

Comments
 (0)