Source-Driven Development
Overview
Every framework-specific decision must be backed by official documentation. Don't guess at APIs, don't rely on outdated patterns, don't trust Stack Overflow answers for current behavior. Fetch the source, read it, implement from it, and cite it.
When to Use
- Implementing any Jetpack library feature (Compose, Room, Navigation, WorkManager, etc.)
- Using Android platform APIs (permissions, intents, lifecycle)
- Configuring Gradle plugins or build system features
- Integrating third-party libraries (Retrofit, Hilt, Coil, etc.)
- Unsure about the correct API for a given Android version
Skip when: Using internal project code that doesn't touch framework APIs.
Source Authority Hierarchy
| Priority |
Source |
Example |
| 1 (highest) |
Official Android docs |
developer.android.com, kb:// URIs from android docs fetch |
| 2 |
Official library docs |
Kotlin docs, Hilt docs, Retrofit docs |
| 3 |
AndroidX release notes |
developer.android.com/jetpack/androidx/releases |
| 4 |
Official blog posts |
android-developers.googleblog.com |
| 5 |
Material Design docs |
m3.material.io |
| 6 |
Source code (AndroidX, AOSP) |
cs.android.com, GitHub mirrors |
| Never |
Stack Overflow, tutorials, AI summaries, Medium posts |
— |
Core Process
Step 1: Detect Stack and Versions
- Read
build.gradle.kts to determine:
compileSdk, minSdk, targetSdk
- Compose compiler version and BOM version
- Library versions (Room, Hilt, Navigation, etc.)
- Kotlin version
// Example: build.gradle.kts
android {
compileSdk = 37 // Android 17; requires AGP 9.1.1+
defaultConfig {
minSdk = 26
targetSdk = 37
}
}
dependencies {
implementation(platform("androidx.compose:compose-bom:2025.01.00"))
implementation("androidx.room:room-runtime:2.7.0")
}
Step 2: Fetch Official Documentation
Go to the source for every framework API:
- Compose: developer.android.com/develop/ui/compose
- Room: developer.android.com/training/data-storage/room
- Hilt: dagger.dev/hilt/
- Navigation: developer.android.com/guide/navigation
- WorkManager: developer.android.com/develop/background-work/persistent
- Kotlin: kotlinlang.org/docs
- Material 3: m3.material.io/develop/android
- Coroutines: kotlinlang.org/docs/coroutines-guide.html
Check version-specific docs — APIs change between versions:
- Room 2.7 has different migration APIs than Room 2.5
- Compose BOM releases change APIs — check the BOM mapping for your date
- Navigation 3 (back-stack-as-state) is a different API surface from Navigation 2.x type-safe routes
Never guess versions — resolve them. When the android CLI and a running Android Studio are available:
android studio version-lookup agp kotlin compose # toolchain keywords
android studio version-lookup androidx.room:room-runtime # Maven coordinates
The output is authoritative and current — accepted at priority 1 in the source hierarchy, same as kb:// URIs. Fallback: the official release-notes pages (developer.android.com/build/releases/gradle-plugin, AndroidX release pages).
- When available, use
android docs for cite-able URIs:
android docs search "compose recomposition"
android docs fetch kb://android/topic/compose/performance/recomposition
The returned kb:// URI is a stable citation — prefer it over a plain developer.android.com URL when both point to the same topic. See references/android-cli-reference.md.
Step 3: Implement Matching Documented Patterns
- Match the official example pattern, not your memory:
// Official Room pattern (verify against docs for your version)
@Entity(tableName = "users")
data class UserEntity(
@PrimaryKey val id: String,
@ColumnInfo(name = "display_name") val displayName: String,
@ColumnInfo(name = "created_at") val createdAt: Long
)
@Dao
interface UserDao {
@Query("SELECT * FROM users WHERE id = :userId")
suspend fun getById(userId: String): UserEntity?
@Upsert
suspend fun upsert(user: UserEntity)
}
- Surface conflicts with existing code:
- "The docs recommend
@Upsert but the project uses @Insert(onConflict = REPLACE) — which should I follow?"
- "Navigation Compose 2.8+ uses type-safe routes but the project is on 2.7 — should I upgrade or use string routes?"
Step 4: Cite Sources
- Include source references in code comments for non-obvious patterns:
// Using rememberLauncherForActivityResult per:
// developer.android.com/training/permissions/requesting#kotlin
val permissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted ->
if (isGranted) onPermissionGranted()
}
- In PRs, link to documentation that justifies the approach.
Common Rationalizations
| Shortcut |
Why It Fails |
| "I know how this API works" |
APIs change between versions. What you remember may be deprecated. |
| "Stack Overflow has the answer" |
SO answers are often outdated, use deprecated APIs, or apply to different versions. |
| "The tutorial shows this pattern" |
Tutorials simplify and may skip error handling, lifecycle awareness, or edge cases. |
| "I'll check docs later" |
Code written from memory will have subtle bugs caught only in production. |
Red Flags
- Framework code written without checking official docs
- "I think this is how it works" (instead of citing a source)
- Code without source citations for non-obvious patterns
- Using deprecated APIs when current alternatives exist
- Patterns that don't match the project's library versions
- Mixing patterns from different library versions
Verification
1---2name: source-driven-development3description: Use when implementing framework-specific code (Jetpack Compose, Room, Hilt, Navigation, etc.). Every API usage must be backed by official documentation, not memory or Stack Overflow.4---56# Source-Driven Development78## Overview910Every framework-specific decision must be backed by official documentation. Don't guess at APIs, don't rely on outdated patterns, don't trust Stack Overflow answers for current behavior. Fetch the source, read it, implement from it, and cite it.1112## When to Use1314- Implementing any Jetpack library feature (Compose, Room, Navigation, WorkManager, etc.)15- Using Android platform APIs (permissions, intents, lifecycle)16- Configuring Gradle plugins or build system features17- Integrating third-party libraries (Retrofit, Hilt, Coil, etc.)18- Unsure about the correct API for a given Android version1920**Skip when:** Using internal project code that doesn't touch framework APIs.2122## Source Authority Hierarchy2324| Priority | Source | Example |25|----------|--------|---------|26| 1 (highest) | Official Android docs | developer.android.com, `kb://` URIs from `android docs fetch` |27| 2 | Official library docs | Kotlin docs, Hilt docs, Retrofit docs |28| 3 | AndroidX release notes | developer.android.com/jetpack/androidx/releases |29| 4 | Official blog posts | android-developers.googleblog.com |30| 5 | Material Design docs | m3.material.io |31| 6 | Source code (AndroidX, AOSP) | cs.android.com, GitHub mirrors |32| **Never** | Stack Overflow, tutorials, AI summaries, Medium posts | — |3334## Core Process3536### Step 1: Detect Stack and Versions37381. **Read `build.gradle.kts`** to determine:39 - `compileSdk`, `minSdk`, `targetSdk`40 - Compose compiler version and BOM version41 - Library versions (Room, Hilt, Navigation, etc.)42 - Kotlin version4344```kotlin45// Example: build.gradle.kts46android {47 compileSdk = 37 // Android 17; requires AGP 9.1.1+48 defaultConfig {49 minSdk = 2650 targetSdk = 3751 }52}5354dependencies {55 implementation(platform("androidx.compose:compose-bom:2025.01.00"))56 implementation("androidx.room:room-runtime:2.7.0")57}58```5960### Step 2: Fetch Official Documentation61622. **Go to the source** for every framework API:63 - **Compose:** developer.android.com/develop/ui/compose64 - **Room:** developer.android.com/training/data-storage/room65 - **Hilt:** dagger.dev/hilt/66 - **Navigation:** developer.android.com/guide/navigation67 - **WorkManager:** developer.android.com/develop/background-work/persistent68 - **Kotlin:** kotlinlang.org/docs69 - **Material 3:** m3.material.io/develop/android70 - **Coroutines:** kotlinlang.org/docs/coroutines-guide.html71723. **Check version-specific docs** — APIs change between versions:73 - Room 2.7 has different migration APIs than Room 2.574 - Compose BOM releases change APIs — check the BOM mapping for your date75 - Navigation 3 (back-stack-as-state) is a different API surface from Navigation 2.x type-safe routes76774. **Never guess versions — resolve them.** When the `android` CLI and a running Android Studio are available:7879```bash80android studio version-lookup agp kotlin compose # toolchain keywords81android studio version-lookup androidx.room:room-runtime # Maven coordinates82```8384The output is authoritative and current — accepted at priority 1 in the source hierarchy, same as `kb://` URIs. Fallback: the official release-notes pages (`developer.android.com/build/releases/gradle-plugin`, AndroidX release pages).85865. **When available, use `android docs` for cite-able URIs:**8788```bash89android docs search "compose recomposition"90android docs fetch kb://android/topic/compose/performance/recomposition91```9293The returned `kb://` URI is a stable citation — prefer it over a plain `developer.android.com` URL when both point to the same topic. See `references/android-cli-reference.md`.9495### Step 3: Implement Matching Documented Patterns96976. **Match the official example pattern**, not your memory:9899```kotlin100// Official Room pattern (verify against docs for your version)101@Entity(tableName = "users")102data class UserEntity(103 @PrimaryKey val id: String,104 @ColumnInfo(name = "display_name") val displayName: String,105 @ColumnInfo(name = "created_at") val createdAt: Long106)107108@Dao109interface UserDao {110 @Query("SELECT * FROM users WHERE id = :userId")111 suspend fun getById(userId: String): UserEntity?112113 @Upsert114 suspend fun upsert(user: UserEntity)115}116```1171187. **Surface conflicts** with existing code:119 - "The docs recommend `@Upsert` but the project uses `@Insert(onConflict = REPLACE)` — which should I follow?"120 - "Navigation Compose 2.8+ uses type-safe routes but the project is on 2.7 — should I upgrade or use string routes?"121122### Step 4: Cite Sources1231248. **Include source references** in code comments for non-obvious patterns:125126```kotlin127// Using rememberLauncherForActivityResult per:128// developer.android.com/training/permissions/requesting#kotlin129val permissionLauncher = rememberLauncherForActivityResult(130 ActivityResultContracts.RequestPermission()131) { isGranted ->132 if (isGranted) onPermissionGranted()133}134```1351369. **In PRs, link to documentation** that justifies the approach.137138## Common Rationalizations139140| Shortcut | Why It Fails |141|----------|-------------|142| "I know how this API works" | APIs change between versions. What you remember may be deprecated. |143| "Stack Overflow has the answer" | SO answers are often outdated, use deprecated APIs, or apply to different versions. |144| "The tutorial shows this pattern" | Tutorials simplify and may skip error handling, lifecycle awareness, or edge cases. |145| "I'll check docs later" | Code written from memory will have subtle bugs caught only in production. |146147## Red Flags148149- Framework code written without checking official docs150- "I think this is how it works" (instead of citing a source)151- Code without source citations for non-obvious patterns152- Using deprecated APIs when current alternatives exist153- Patterns that don't match the project's library versions154- Mixing patterns from different library versions155156## Verification157158- [ ] `build.gradle.kts` versions checked before implementation159- [ ] Official documentation consulted for every framework API used160- [ ] API patterns match the documented version (not outdated tutorials)161- [ ] Deprecated API usage flagged with migration path162- [ ] Source URLs cited in comments for non-obvious patterns (`developer.android.com/...` or `kb://...`)163- [ ] Conflicts with existing code surfaced (not silently overridden)