Android¶
Scope: native Android apps in Kotlin, including Jetpack Compose.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
Google's official architecture guidance is comprehensive. Follow it as-is. This file only highlights the core rules.
- 10 Guide to app architecture: the baseline.
- 9 Recommendations for Android architecture: a prioritised checklist of strongly recommended and recommended practices. Use it for reviews.
- 9 Now in Android: the official, fully featured reference app.
- 8 Guide to Android app modularization and common modularization patterns.
- 7 Architecture samples: smaller samples of the recommended architecture.
Key rules¶
Architecture¶
- 9
ANDROID-1Use a UI layer and a data layer, and add a domain layer only when logic is complex or reused. (Guide to app architecture, Domain layer) - 9
ANDROID-2Keep a single source of truth for each data type, and use unidirectional data flow: state flows down, events flow up. (Guide to app architecture) - 9
ANDROID-3Expose UI state from ViewModels as observable streams, and keep UI elements free of business logic. (UI layer, ViewModel overview) - 8
ANDROID-4Access data only through repositories in the data layer. (Data layer) - 8
ANDROID-5Use dependency injection (Hilt). (Dependency injection in Android, Hilt) - 7
ANDROID-6Follow the coroutine best practices: inject dispatchers, make suspend functions main-safe, and don't expose mutable state. (Best practices for coroutines) - 6
ANDROID-7Build offline-first where possible, with the local database as the source of truth. (Guide to app architecture, Build an offline-first app) - 5
ANDROID-8Modularise by feature and layer as the app and team grow. (Modularization guide)
Accessibility¶
- 7
ANDROID-9Make every screen usable with TalkBack and Switch Access: describe each meaningful image and icon with acontentDescription, passnullfor decorative ones, expose the role and state of custom components through Compose semantics, and make each touch target at least 48dp by 48dp. Material components such asButtonandIconButtonalready have the minimum size and built-in semantics, but custom elements need both set by hand; scan each screen with the Accessibility Scanner app as well. This appliesA11Y-9andA11Y-10. (Android, Make apps more accessible, Compose, Semantics, Android, Test your app's accessibility) - 6
ANDROID-10Set text sizes insp, and test every screen at the largest font size, which is 200% since Android 14, so that text follows the user's setting without being cut off. Don't usespfor padding or fixed heights, and convert betweenspand pixels withTypedValue.applyDimension()andTypedValue.deriveDimension()instead of calculating withfontScale, because the scaling is nonlinear. This appliesA11Y-12. (Android 14, Non-linear font scaling to 200%)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 6 Konsist, architecture assertions: Kotlin tests that check which layers may depend on which; set the direction to match the Android guide. Its Android snippets also check that ViewModel properties are
Flows and that repositories live in a repository package. Partly checksANDROID-1,ANDROID-3andANDROID-4. - 6 Compose accessibility checks: with the
ui-test-junit4-accessibilitydependency,enableAccessibilityChecks()on theAndroidComposeTestRuleruns the Accessibility Test Framework on each test action and fails the test on missing labels, small touch targets, low contrast and traversal order problems. For Views, Espresso'sAccessibilityChecks.enable()runs the same checks. Partly checksANDROID-9. - 5 detekt, coroutines rules:
InjectDispatcherflags hard-coded dispatchers, following the same Android best-practices page. Partly checksANDROID-6. - 5 Android Lint, ContentDescription: flags images and image buttons without a
contentDescriptionin layout files, and SpUsage flags text sizes indp. Both check XML layouts only, not Compose code. Partly checksANDROID-9andANDROID-10. - 4 Slack compose-lints: Android Lint checks for Jetpack Compose.
ComposeViewModelForwardingflags ViewModels passed down the UI tree, which breaks unidirectional data flow. Partly checksANDROID-2. - 4 Module Graph Assert: a Gradle plugin that fails the build when a module depends on one it isn't allowed to. It guards the module structure but doesn't create it. Partly checks
ANDROID-8.
Tutorials and further reading¶
- 8 Android Basics with Compose: Google's free course, which teaches the recommended architecture.
- 7 Architecting your Compose UI.
- 7 Fundamentals of testing Android apps.