# Dead Code Detection for Android/Kotlin Projects

## The Problem

Simple file-name grepping against class names produces massive false positives in Android/Kotlin projects. Many classes are wired indirectly through the DI framework, Room, Retrofit, Compose navigation, or AndroidManifest.

## Correct Detection Flow

### 1. AndroidManifest.xml references
Services, broadcast receivers, and activities are declared in the manifest — they're alive even if no Kotlin file imports them.
```bash
grep "ClassName" app/src/main/AndroidManifest.xml
```

### 2. Hilt @Module classes
`@Module @InstallIn(SingletonComponent::class)` — Dagger auto-discovers these at compile time. They're alive.
```bash
grep "@Module" path/to/file.kt
```

### 3. @Inject @Singleton constructors
Classes with `@Inject constructor(...)` are auto-wired by Dagger. If ANY other `@Inject` class references them as a constructor parameter, they're alive.

### 4. Room annotations
`@Entity`, `@Dao`, `@Database` classes are wired through Room's compile-time code generation. The entity/DAO filename may never appear in a direct import.

### 5. Retrofit interfaces
`interface TraktApi { @GET(...) }` — Retrofit's `create()` resolves these at runtime. No compile-time import exists.

### 6. Compose NavHost composable entries
Screens are referenced by qualified name in `composable(Screen.X.route) { ... }`. The import is at the top of the NavHost file.

### 7. Compose @Composable functions
Shared composables may be imported locally. Check all files for `import <package>.ClassName`.

## The Reliable Check

Only delete files that pass ALL of the above AND show 0 references in:
```bash
grep -rn "\bClassName\b" /path/to/project --include="*.kt" --include="*.kts" --include="*.xml" --include="*.java" | grep -v "path/to/the/file/itself"
```

## May 2026 Audit Results (Unspooled)

### Files that looked dead but were alive:
- `NetworkTimeouts.kt`, `NetworkQualifiers.kt` — Hilt qualifier modules
- `CoilModule.kt`, `AddonModule.kt` — DI modules
- `UnspooledPlaybackService.kt` — Manifest-declared service
- `TvChannelBootReceiver.kt` — Manifest-declared receiver
- `CacheDao.kt`, `BridgeDao.kt`, etc. — Room DAOs
- All `*Provider.kt` files — Retrofit interfaces
- `ContinueWatchingSortMode`, `DiscoverLocation`, `ExperienceMode`, `HomeLayout` — 26-105 references each

### Files confirmed dead and removed:
- `TmdbRepository.kt` — replaced by `TmdbMetadataService` + `IdBridge`
- `TmdbService.kt` — redundant; `IdBridge` provides persistent Room-backed caching
- `ServiceConnectionState.kt` — 0 references across entire project
- `UiEffect.kt` — 0 references across entire project

## Anti-Patterns That Failed

1. **Filename grepping**: Misses Manifest, XML, Gradle references
2. **Import-only check**: Misses Hilt-wired, Room-wired, and Retrofit-wired classes
3. **Directory-specific scan**: Scanning only `src/main/java` misses `src/test`, XML resources, and AndroidManifest.xml
