Skip to main content
The project uses Gradle with Kotlin DSL for build configuration. Build settings are centralized in buildSrc for consistency across all modules.

Project structure

The project is organized as a multi-module Gradle project with the following structure:
CPT/
├── app/                    # Main application module
├── buildSrc/               # Centralized build configuration
├── common/                 # Common Kotlin code
├── commonAndroid/          # Common Android code
├── data/                   # Data layer modules
│   ├── local/
│   ├── remote/
│   ├── repository/
│   ├── session/
│   └── source/
├── domain/                 # Domain layer modules
│   ├── gateway/
│   ├── model/
│   └── useCase/
├── feature/                # Feature modules
│   ├── articledetail/
│   ├── home/
│   └── launcher/
└── navigation/             # Navigation logic

Build configuration

Centralized configuration

Build settings are defined in AppConfig.kt located in buildSrc/src/main/java/es/mobiledev/buildsrc/AppConfig.kt:1:
object AppConfig {
    const val applicationId = "es.mobiledev.cpt"
    const val namespace = "es.mobiledev.cpt"
    const val applicationName = "CPT"
    const val versionCode = 1
    const val versionName = "0.0.1"
    const val compileSdkVersion = 36
    const val targetSdkVersion = 36
    const val minSdkVersion = 26
    const val testRunner = "androidx.test.runner.AndroidJUnitRunner"
}
This centralized approach ensures all modules use consistent SDK versions and configuration.

Version catalog

The project uses Gradle version catalogs (gradle/libs.versions.toml:1) for dependency management:
  • Android Gradle Plugin: 8.13.0
  • Kotlin: 2.2.20
  • Compose BOM: 2025.10.00
  • Hilt: 2.56.2
  • Room: 2.8.4
  • Retrofit: 3.0.0
  • KtLint: 13.1.0

Build types

The app module defines two build types in app/build.gradle.kts:26:
buildTypes {
    debug {
        // Default configuration
        // Minification disabled for faster builds
        // Full debugging enabled
    }
}
ProGuard is currently disabled in release builds. Enable isMinifyEnabled = true for production to reduce APK size and obfuscate code.

Building the project

Prerequisites

Before building, ensure you have:
1

Install Java 11

The project requires Java 11 for compilation. Verify your installation:
java -version
2

Set up Android SDK

Install Android SDK 36 through Android Studio or command line tools.
3

Configure environment

Set ANDROID_HOME environment variable:
export ANDROID_HOME=$HOME/Android/Sdk

Build commands

./gradlew assembleDebug

Clean builds

When experiencing build issues, perform a clean build:
./gradlew clean build
Clean builds remove all previous build artifacts and can take significantly longer than incremental builds.

Gradle tasks

The project includes several custom Gradle tasks:

Pre-build tasks

The app module automatically runs code quality checks before building (app/build.gradle.kts:48):
tasks.named("preBuild").configure {
    dependsOn("ktlintFormat")
    dependsOn("ktlintCheck")
}
This ensures code is formatted and validated before compilation.

Common tasks

  • ./gradlew assemble - Build all variants
  • ./gradlew assembleDebug - Build debug APK
  • ./gradlew assembleRelease - Build release APK
  • ./gradlew bundle - Build Android App Bundle (AAB)
  • ./gradlew bundleRelease - Build release AAB
  • ./gradlew check - Run all checks and tests
  • ./gradlew lint - Run Android Lint checks
  • ./gradlew test - Run unit tests
  • ./gradlew connectedAndroidTest - Run instrumented tests
  • ./gradlew ktlintCheck - Check code style
  • ./gradlew ktlintFormat - Auto-format code
  • See Code style for more details

Parallel builds

Enable parallel builds for faster compilation by adding to gradle.properties:13:
org.gradle.parallel=true
The project is configured with decoupled modules, making it suitable for parallel execution.

Compilation settings

Java compatibility

All modules target Java 11 (app/build.gradle.kts:32):
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

kotlin {
    compilerOptions {
        jvmTarget = JvmTarget.JVM_11
    }
}

Kotlin compiler options

The project uses the official Kotlin code style (gradle.properties:19):
kotlin.code.style=official

Compose compiler

Jetpack Compose is enabled through the Kotlin Compose plugin:
plugins {
    alias(libs.plugins.kotlin.compose)
}

buildFeatures {
    compose = true
}

Build optimization

JVM arguments

The project allocates 2GB of heap memory for Gradle (gradle.properties:9):
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
Increase this value for larger projects:
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8

Non-transitive R classes

The project enables non-transitive R classes (gradle.properties:23) to reduce R class size:
android.nonTransitiveRClass=true

Build cache

Enable Gradle build cache for faster builds:
org.gradle.caching=true

Module configuration

Application module

The main app module (app/build.gradle.kts:1) uses:
  • Android Application plugin
  • Kotlin Android plugin
  • Kotlin Compose plugin
  • KSP for annotation processing
  • Hilt for dependency injection

Feature modules

Feature modules (feature/home/build.gradle.kts:1) use:
  • Android Library plugin
  • Same Kotlin and Compose plugins as app
  • Share the centralized AppConfig for SDK versions

Type-safe project accessors

The project uses type-safe project accessors (settings.gradle.kts:18) for cleaner dependency declarations:
dependencies {
    implementation(projects.commonAndroid)
    implementation(projects.feature.home)
    implementation(projects.data.repository)
}
This provides compile-time safety and IDE autocompletion.

Troubleshooting

Build fails after pulling changes

./gradlew clean build --refresh-dependencies

Gradle daemon issues

./gradlew --stop
./gradlew build

KSP compilation errors

Clean the KSP generated sources:
./gradlew clean cleanBuildCache

Out of memory errors

Increase heap size in gradle.properties:
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m

Next steps

Testing

Learn how to run unit and instrumented tests

Code style

Configure KtLint and code formatting

Build docs developers (and LLMs) love