Blame
| d6d981 | Melisha Dsouza | 2026-01-15 16:26:15 | 1 | # **Android Coding Standards** |
| 2 | ||||
| 3 | ### **1. Objective** |
|||
| 4 | To ensure all Android applications developed at Enovate follow a consistent, high-quality, and maintainable coding approach that aligns with organizational and industry best practices. |
|||
| 5 | ||||
| 6 | ### **2. Scope** |
|||
| 7 | Applies to all Android development projects using Kotlin or Java, developed in Android Studio, and maintained under Enovate’s repositories. |
|||
| 8 | ||||
| 9 | ### **3. Architecture & Project Structure** |
|||
| 10 | * Adopt MVVM or Clean Architecture. |
|||
| 11 | ||||
| 12 | Maintain a consistent project folder structure: |
|||
| 13 | ``` |
|||
| 14 | app/ |
|||
| 15 | ├── data/ |
|||
| 16 | │ ├── models/ |
|||
| 17 | │ ├── network/ |
|||
| 18 | │ ├── repository/ |
|||
| 19 | ├── ui/ |
|||
| 20 | │ ├── activities/ |
|||
| 21 | │ ├── fragments/ |
|||
| 22 | │ ├── adapters/ |
|||
| 23 | │ ├── composables/ |
|||
| 24 | │ ├── viewmodels/ |
|||
| 25 | ├── utils/ |
|||
| 26 | ├── di/ |
|||
| 27 | ├── resources/ |
|||
| 28 | ``` |
|||
| 29 | * Separate business logic from UI logic. |
|||
| 30 | * Avoid placing all logic inside Activities/Fragments/Composables. |
|||
| 31 | ||||
| 32 | ### **4. Naming Conventions** |
|||
| 33 | ||||
| 34 | | Element | Convention | Example | |
|||
| 35 | | -------------- | -------------------------- | --------------------------- | |
|||
| 36 | | Class names | PascalCase | `UserProfileActivity` | |
|||
| 37 | | Variable names | camelCase | `userName`, `isActive` | |
|||
| 38 | | Constants | UPPER_SNAKE_CASE | `MAX_RETRY_COUNT` | |
|||
| 39 | | XML IDs | lowercase_with_underscores | `btn_submit`, `tv_username` | |
|||
| 40 | | Packages | lowercase | `com.enovate.appname.ui` | |
|||
| 41 | ||||
| 42 | ### **5. Code Formatting & Style** |
|||
| 43 | * Indentation: 4 spaces |
|||
| 44 | * Maximum line length: 120 characters |
|||
| 45 | * Avoid unused imports, variables, or commented code. |
|||
| 46 | * Add KDoc/Javadoc for all public classes, methods, and complex logic. |
|||
| 47 | * Use `val` instead of `var` wherever possible for immutability. |
|||
| 48 | * Follow Kotlin official style guide: https://developer.android.com/kotlin/style-guide |
|||
| 49 | ||||
| 50 | ### **6. UI/UX & Resource Management** |
|||
| 51 | * Use Jetpack Compose for new apps |
|||
| 52 | * Use ConstraintLayout for flexible designs (if opting for XML). |
|||
| 53 | * Define colors, strings, and dimensions in XML resources (no hardcoding). |
|||
| 54 | * Use themes and styles consistently. |
|||
| 55 | * Follow accessibility guidelines (content descriptions, contrast). |
|||
| 56 | ||||
| 57 | ### **7. Networking & Data Handling** |
|||
| 58 | * Use Retrofit + OkHttp for REST APIs. |
|||
| 59 | * Use Room / DataStore for local storage. |
|||
| 60 | * Handle API responses using sealed classes or Result wrappers. |
|||
| 61 | * Centralize API endpoints and keys (e.g., in `Constants.kt`). |
|||
| 62 | * Avoid network calls on the main thread. |
|||
| 63 | ||||
| 64 | ### **8. Error Handling & Logging** |
|||
| 65 | * Use `try-catch` only where needed. |
|||
| 66 | Log using Timber: |
|||
| 67 | ``` |
|||
| 68 | Timber.d("Loading user profile...") |
|||
| 69 | Timber.e(exception, "Error loading user profile") |
|||
| 70 | ``` |
|||
| 71 | * Disable logs in production builds. |
|||
| 72 | ||||
| 73 | ### **9. Security & Performance** |
|||
| 74 | * Don’t store sensitive data in plain text or shared preferences. |
|||
| 75 | * Use ProGuard/R8 for code obfuscation. |
|||
| 76 | * Optimize image and JSON parsing. |
|||
| 77 | * Avoid memory leaks (use ViewBinding, avoid static context references). |
|||
| 78 | ||||
| 79 | ### **10. Testing** |
|||
| 80 | * Write Unit Tests for ViewModels and business logic. |
|||
| 81 | * Write UI Tests using Espresso. |
|||
| 82 | * Maintain at least 70% coverage for core modules. |
|||
| 83 | * Use MockK or Mockito for mocking. |
|||
| 84 | ||||
| 85 | ### **11. Automation & CI/CD Integration** |
|||
| 86 | * Integrate static analysis tools: |
|||
| 87 | * ktlint – Formatting and style. |
|||
| 88 | * Detekt – Code smell detection. |
|||
| 89 | * Android Lint – XML and resource validation. |
|||
| 90 | * CI/CD should fail the build if violations are detected. |
|||
| 91 | ||||
| 92 | ### **12. References** |
|||
| 890c84 | Melisha Dsouza | 2026-01-16 10:16:51 | 93 | - [Jetpack Compose](https://developer.android.com/compose) |
| 94 | - [Android Developers Style Guide](https://developer.android.com/kotlin/style-guide) |
|||
| 95 | - [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) |
|||
| 96 | - [Clean Architecture for Android](https://developer.android.com/topic/architecture) |
|||
| 97 | ||||
| 98 | **Document** - [Android](https://docs.google.com/document/d/1mvS2f5DUxEfFvKJQYY_xkMdi2hJXQjfbJZ-tTK3qol8/edit?usp=sharing) |