Skip to content
:tech
← Handbook

AI-translated. Read the original in Korean

Android Modules

This document describes considerations when building Android modules. These are recommendations; individual projects and modules may use different structures.

Guidelines

  • Write new modules in Kotlin wherever possible.
  • Make active use of dependency injection.
  • Create new modules in buzz-android, Buzzvil’s Android monorepo.

Creating a Module

Consider creating a new module when functionality forms a meaningful unit and is likely to be reused by multiple modules.

Before creating a module, complete a design and review process and produce a design document. Based on that document, place the module in the appropriate layer and configure its README, core libraries, versioning, publishing, and Proguard settings.

App Modules

This layer contains modules that form an application or SDK. At the top of the system, it assembles modules and their dependencies; it contains no business logic.

App modules can access feature and library modules and manage dependency injection across the system.

Create app modules in /app.

Feature Modules

This layer provides discrete, user-facing features. Each module contains the business logic for its feature, implemented directly or using library modules.

Feature modules may reference other feature modules and library modules. References between modules in the same layer are generally discouraged. If necessary, make sure they do not create circular dependencies.

Create feature modules in /feature.

Library Modules

Extract units of logic reused by multiple feature modules into library modules. The distinction between feature and library modules can be difficult to formalize, but the main consideration is generally whether the functionality represents a feature from the user’s perspective.

Library modules may reference other library modules. References between modules in the same layer are generally discouraged. If necessary, make sure they do not create circular dependencies.

Create library modules in /lib.

Module Configuration

build.gradle Guidelines

Use variables defined in rootProject.ext for dependency versions. This keeps dependencies consistent across modules and helps avoid dependency hell.

When adding dependencies, understand the differences between configurations such as implementation and api, and choose appropriately. Hiding internal dependencies can improve build performance and make modules less complex to use. See Dependency configurations for details.

Core Libraries

RxJava / RxKotlin

implementation "io.reactivex.rxjava2:rxkotlin:$rootProject.ext.rxKotlinVersion"

RxJava combines ideas from the observer pattern, iterator pattern, and functional programming to make asynchronous operations easier to build.

RxJava can also help avoid callback hell. Use Single to manage data streams from asynchronous operations such as network requests. See ReactiveX for usage details.

Dagger 2

implementation "com.google.dagger:dagger:$rootProject.ext.daggerVersion"
implementation "com.google.dagger:dagger-android-support:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.ext.daggerVersion"

Dagger is a dependency injection library for Java and Android. It makes dependency injection easier to implement and test. See the linked references for dependency injection and the dependency inversion principle.

Dependency Injection Within a Module

Use Dagger’s @Component, @Subcomponent, or @Module, as appropriate, to configure dependencies used within a module.

Feature Layer

Feature modules generally use @Component or @Subcomponent so they can manage dependencies independently.

@Component(modules = [LibraryModule::class])
interface FeatureComponent {
    fun inject(view: View)
}
@Subcomponent(modules = [LibraryModule::class])
interface FeatureSubcomponent {
    fun inject(view: View)
}
Library Layer

Unless a library module needs its own scope management, providing a @Module is sufficient.

@Module
object LibraryModule {
    @Provides
    fun provideSome() = Some()
}
All guides
Handbook

Multi-Module Android SDKs

Introduction When an app is modularized, it can reference each module as a local library. You can then version only the app and distribute the APK without managing separate module…

Handbook

Android Testing

This document provides Android testing methods and guidelines, including recommended libraries and how to use them. These are recommendations only; projects are free to adopt or pr…