📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Overview

Android Components Architecture in a Modular Word

CircleCI Codecov Codacy CodeStyle Kotlin Version Gradle API License

Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 approach to Android application development using Kotlin and latest tech-stack.

The goal of the project is to demonstrate best practices, provide a set of guidelines, and present modern Android application architecture that is modular, scalable, maintainable and testable. This application may look simple, but it has all of these small details that will set the rock-solid foundation of the larger app suitable for bigger teams and long application lifecycle management.

Table of Contents

Mentions

The project received different mentions/reference from Android Developer Community:

  • Android Weekly Newsletter that helps you to stay cutting-edge with your Android Development.
  • AndroidSweets Fresh news from Droid zone.
  • Android Awesome A curated list of awesome Android libraries and resources.
  • Droidcon Blog posts from leading authorities and video archive from droidcons around the world.
  • DroidconKE The official DroidconKE 2020 conference App.
  • Github trending See what the GitHub community is most excited about today.
  • KotlinBy A curated list of awesome Kotlin related stuff.
  • Reddit: Discussion about Kotlin, a statically typed programming language for the JVM, Android, JavaScript, and native.

Development

Environment setup

First off, you require the latest Android Studio 4.1.0 (or newer) to be able to build the app.

You need to supply keys for Marvel API. You can find information about how to gain access by using the link.

When you obtain the keys, you can provide them to the app by putting the following in the local.properties project root file:

#Marvel API KEYS
marvel.key.public = <insert>
marvel.key.private = <insert>

Code style

To maintain the style and quality of the code, are used the bellow static analysis tools. All of them use properly configuration and you find them in the project root directory .{toolName}.

Tools Config file Check command Fix command
detekt /.detekt ./gradlew detekt -
ktlint - ./gradlew ktlint ./gradlew ktlintFormat
spotless /.spotless ./gradlew spotlessCheck ./gradlew spotlessApply
lint /.lint ./gradlew lint -

All these tools are integrated in pre-commit git hook, in order ensure that all static analysis and tests passes before you can commit your changes. To skip them for specific commit add this option at your git command:

git commit --no-verify

The pre-commit git hooks have exactly the same checks as CircleCI and are defined in this script. This step ensures that all commits comply with the established rules. However the continuous integration will ultimately be validated that the changes are correct.

Design

App support different screen sizes and the content has been adapted to fit for mobile devices and tablets. To do that, it has been created a flexible layout using one or more of the following concepts:

In terms of design has been followed recommendations android material design comprehensive guide for visual, motion, and interaction design across platforms and devices. Granting the project in this way a great user experience (UX) and user interface (UI). For more info about UX best practices visit link.

Moreover, has been implemented support for dark theme with the following benefits:

  • Can reduce power usage by a significant amount (depending on the device’s screen technology).
  • Improves visibility for users with low vision and those who are sensitive to bright light.
  • Makes it easier for anyone to use a device in a low-light environment.
Mode Characters list Characters favorite Character detail
Light
Dark

Architecture

The architecture of the application is based, apply and strictly complies with each of the following 5 points:

Modules

Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing the following dependence between them:

The above graph shows the app modularisation:

  • :app depends on :core and indirectly depends on :features by dynamic-features.
  • :features modules depends on :commons, :core, :libraries and :app.
  • :core and :commons only depends for possible utils on :libraries.
  • :libraries don’t have any dependency.

App module

The :app module is an com.android.application, which is needed to create the app bundle. It is also responsible for initiating the dependency graph, play core and another project global libraries, differentiating especially between different app environments.

Core module

The :core module is an com.android.library for serving network requests or accessing to the database. Providing the data source for the many features that require it.

Features modules

The :features module are an com.android.dynamic-feature is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module.

features

Commons modules

The :commons modules are an com.android.library only contains code and resources which are shared between feature modules. Reusing this way resources, layouts, views, and components in the different features modules, without the need to duplicate code.

ui views

Libraries modules

The :libraries modules are an com.android.library, basically contains different utilities that can be used by the different modules.

Architecture components

Ideally, ViewModels shouldn’t know anything about Android. This improves testability, leak safety and modularity. ViewModels have different scopes than activities or fragments. While a ViewModel is alive and running, an activity can be in any of its lifecycle states. Activities and fragments can be destroyed and created again while the ViewModel is unaware.

Passing a reference of the View (activity or fragment) to the ViewModel is a serious risk. Lets assume the ViewModel requests data from the network and the data comes back some time later. At that moment, the View reference might be destroyed or might be an old activity that is no longer visible, generating a memory leak and, possibly, a crash.

The communication between the different layers follow the above diagram using the reactive paradigm, observing changes on components without need of callbacks avoiding leaks and edge cases related with them.

Build variants

The application has different product flavours: Dev, QA, Prod. Each variant has a specific target environment and to make easier to distinguish them the app uses a specific icon colour for debug and release build variant with descriptive app name. In this case and given that it's a sample, all variants have the same Marvel API endpoint. But the idea is to have different environments target for Development and QA respectively, what doesn't affect the production environment. This is applicable to any tool, platform, service what is being used. For more information about build variant, check this link.

Types DEV QA PROD
Debug


MarvelDEV


MarvelQA


Marvel

Release


MarvelDEV


MarvelQA


Marvel

Documentation

The documentation is generated following KDoc language (the equivalent of Java's JavaDoc) via documentation engine for Kotlin Dokka.

To consult it check this link or open the project /docs directory.

Tech-stack

This project takes advantage of many popular libraries, plugins and tools of the Android ecosystem. Most of the libraries are in the stable version, unless there is a good reason to use non-stable dependency.

Dependencies

  • Jetpack:
    • Android KTX - provide concise, idiomatic Kotlin to Jetpack and Android platform APIs.
    • AndroidX - major improvement to the original Android Support Library, which is no longer maintained.
    • Benchmark - handles warmup, measures your code performance, and outputs benchmarking results to the Android Studio console.
    • Data Binding - allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.
    • Lifecycle - perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
    • LiveData - lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.
    • Navigation - helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer.
    • Paging - helps you load and display small chunks of data at a time. Loading partial data on demand reduces usage of network bandwidth and system resources.
    • Room - persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.
    • ViewModel - designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
  • Coroutines - managing background threads with simplified code and reducing needs for callbacks.
  • Dagger2 - dependency injector for replacement all FactoryFactory classes.
  • Retrofit - type-safe HTTP client.
  • Coil - image loading library for Android backed by Kotlin Coroutines.
  • Moshi - makes it easy to parse JSON into Kotlin objects.
  • Timber - a logger with a small, extensible API which provides utility on top of Android's normal Log class.
  • Stetho - debug bridge for applications via Chrome Developer Tools.
  • and more...

Test dependencies

  • UIAutomator - a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
  • Espresso - to write concise, beautiful, and reliable Android UI tests
  • Robolectric - industry-standard unit testing framework for Android.
  • JUnit - a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
  • Mockk - provides DSL to mock behavior. Built from zero to fit Kotlin language.
  • AndroidX - the androidx test library provides an extensive framework for testing Android apps.
  • and more...

Plugins

  • Ktlint - an anti-bikeshedding Kotlin linter with built-in formatter.
  • Detekt - a static code analysis tool for the Kotlin programming language.
  • Spotless - a code formatter can do more than just find formatting errors.
  • Versions - make easy to determine which dependencies have updates.
  • SafeArgs - generates simple object and builder classes for type-safe navigation and access to any associated arguments.
  • Jacoco - code coverage library
  • and more...

Resources

Projects

This is project is a sample, to inspire you and should handle most of the common cases, but obviously not all. If you need to take a look at additional resources to find solutions for your project, visit these interesting projects:

Articles

A collection of very interesting articles related last android community tendencies and recommendations for start to take in consideration for your current/next project:

Libraries

The open-source community create and maintains tons of awesome libraries making your job more easy, giving the opportunity to use them in your developments. Here are a very important collection of them:

Best practices

Avoid reinventing the wheel by following these guidelines:

Codelabs

Google Developers Codelabs provide a guided, tutorial, hands-on coding experience. Most codelabs will step you through the process of building a small application, or adding a new feature to an existing application. They cover a wide range of android concepts to learn and practice:

Contributions

All contributions are welcome! Please feel free to post questions, recommendations, ideas, bugs by create new issue following the template or if you want create directly new pull request.

Authors

Madalin Valceleanu

Linkedin Twitter Medium Web

License

Copyright 2019-2020 vmadalin.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • fix to create a release apk

    fix to create a release apk

    Description

    A fix to allow assign and run successfully production apk, obfuscation need to be optimized

    Fixes #10

    Type of change

    • added coil as a dependency on app module
    • dynamic features are declared not instant so
    • added proguard rule on app module

    How Has This Been Tested

    • [ ] to generate an universal apk run this gradle task: packageProdReleaseUniversalApk (I don't know why but in my case the traditional step by step release project from the IDE generate an apk that does not include all the features)

    Checklist

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] My changes generate no new warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] New and existing unit tests pass locally with my changes
    • [ ] Any dependent changes have been merged and published in downstream modules
    opened by tidoemanuele 3
  • Add projectDependencyGraph Gradle

    Add projectDependencyGraph Gradle

    Description

    Add a new Gradle task to the project, which generates image with dependency graph from the project modules structure. Implementation by Jake Wharton https://github.com/JakeWharton/SdkSearch/blob/master/gradle/projectDependencyGraph.gradle

    Type of change

    Please delete options that are not relevant.

    • [ ] New feature (non-breaking change which adds functionality)

    How Has This Been Tested

    • [ ] Readme file contains a new generated picture

    Checklist

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] My changes generate no new warnings
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    • [x] Any dependent changes have been merged and published in downstream modules
    opened by michalharakal 3
  • Update build.gradle.kts

    Update build.gradle.kts

    Description

    This will fix a build error. 0.6.0-SNAPSHOT doesn't exist anymore, it's been replaced by 0.7.0-SNAPSHOT. More : https://github.com/vanniktech/gradle-dependency-graph-generator-plugin

    Fixes # (issue)

    Type of change

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)

    How Has This Been Tested

    Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

    • [ ] With a build

    Test Configuration

    • Firmware version :
    • Hardware :
    • Toolchain :
    • SDK :

    Checklist

    • [ ] My code follows the style guidelines of this project
    • [ ] I have performed a self-review of my own code
    • [ ] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation
    • [ ] My changes generate no new warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] New and existing unit tests pass locally with my changes
    • [ ] Any dependent changes have been merged and published in downstream modules
    opened by rvasseur31 2
  • Update dependencies #26

    Update dependencies #26

    Description

    Fixes https://github.com/VMadalin/android-modular-architecture/issues/26

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [x] This change requires a documentation update
    opened by vmadalin 2
  • Removed deprecated fabric #2

    Removed deprecated fabric #2

    Description

    Fixes: https://github.com/VMadalin/android-modular-architecture/issues/2

    Type of change

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [x] This change requires a documentation update
    opened by vmadalin 2
  • Question about code coverage

    Question about code coverage

    Description

    Can you elaborate on how you exclude the app directory from your code coverage in codecov?

    Basic Information

    • Device type: Android
    • OS version:
    • App version: latest

    Details

    I see that in your diagram you don't have things like SampleMainActivity tested because they are excluded from the graph?

    image

    I was wonder how you did this because I see no ignore flags in your codecov/config.yml nor are there any exclusions in your jacoco configurations, at least that I can find!

    Thanks!

    question 
    opened by Stegnerd 2
  • Question about using plugin in the id of plugins

    Question about using plugin in the id of plugins

    Description

    In regards to this project it is a great learning tool and I was curious to walk through it! My question is in the BuildPlugins file you set all the plugins to use plugins.xxxx. for example BuildPlugins.detekt, yet when I try to build it says that it cannot find a plugin with an id plugin.detekt. But if I use the following: io.gitlab.arturbosch.detekt it is found and moves to the next error in the build. Can you elaborate on that?

    Thank you so much

    opened by Stegnerd 2
  • Question: Migration to koin or Gson

    Question: Migration to koin or Gson

    Is there any ongoing thinking to refractor/migrate the project to Koin/ Moshi. As Moshi seems to be GSON 3.0 and possibly Koin will replace dagger in the near future.

    opened by mwshubham 2
  • How to create a release apk that can be installed on device

    How to create a release apk that can be installed on device

    Description

    I'm trying to use this project as a sort of bootstrap for a new android project, when a signed release apk is created by android studio and installed it crashes instantly due to being unable to find the dynamic module fragments.

    Basic Information

    • OS version: Linux
    • App version: android studio 3.5.3

    Details

    Using android studios Build -> generate signed apk -> normal apk If you install that generated apk it will crash with a classpath issue with Coil, if you fix that (I added it to core's dependencies) then you get

    Process: com.vmadalin.android, PID: 18602
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vmadalin.android/com.vmadalin.android.SampleMainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
            at android.os.Handler.dispatchMessage(Handler.java:112)
            at android.os.Looper.loop(Looper.java:216)
            at android.app.ActivityThread.main(ActivityThread.java:7625)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
         Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
         Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
         Caused by: androidx.fragment.app.Fragment$e: Unable to instantiate fragment com.vmadalin.dynamicfeatures.home.ui.HomeFragment: make sure class name exists
    

    I assumed as all dynamic modules are set to install time delivery a monolith apk should work. I also tried creating an aab, using bundletool to create a universal apk and installing that but I ended up with the same error.

    What is the correct way to do a release APK?

    bug 
    opened by bobthekingofegypt 2
  • Project doesn't compile and give 6 errors

    Project doesn't compile and give 6 errors

    Description

    Downloaded the latest Master branch and got a marvel API key. Then I was prompted to update to Android Studio 4.0 which is still in early phases. After that I got 6 compile errors and tried to downgrade gradle. This project is not compiling!

    Basic Information

    • Device type: Mac
    • OS version: OSX Catalina
    • App version:

    Details

    https://imgshare.io/images/2020/01/05/123.png

    bug 
    opened by JimClermonts 2
  • Passing NavController to ViewModel issue

    Passing NavController to ViewModel issue

    Passing NavController to ViewModel is probably a wrong approach in here: https://github.com/VMadalin/android-modular-architecture/blob/master/features/home/src/main/kotlin/com/vmadalin/dynamicfeatures/home/ui/HomeViewModel.kt#L43 My opinion is this and the listener should be exists in the Fragment and viewModel when it is needed

    suggestion 
    opened by hulkdx 1
  • Repository is not glued to Interface

    Repository is not glued to Interface

    Thank you for the great sample. I wonder why You do not have an interface for MarvelRepository or any other Repositories in your core module. You are following SOLID principles, and that is D is SOLID to follow dependency inversion.

    High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g., interfaces)

    Using interfaces will also simplify unit testing.

    Were there any specific reason that you did not use interface for Repository?

    opened by alirezaeiii 1
  • Why not Hilt?

    Why not Hilt?

    Why don't you use Hilt? Google says

    Dagger and Hilt code can coexist in the same codebase. However, in most cases it is best to use Hilt to manage all of your usage of Dagger on Android.

    enhancement good first issue 
    opened by Piasy 7
Owner
Madalin Valceleanu
Mobile Software Developer @Vonage Enthusiast and passionate about clean code, modular architecture, design patterns and automation. 🇷🇴 - 🇪🇸 - 🇬🇧
Madalin Valceleanu
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

Yassin AJDI 189 Nov 26, 2022
The Rick And Morty - MVVM with a clean architecture approach using some of the best practices in Android Development.

Rick-and-Morty The Rick And Morty - App consuming a Rick and Morty API to display Characters it has been built with clean architecture principles, Rep

Akhilesh Patil 61 Jan 7, 2023
Shreyas Patil 2.1k Dec 30, 2022
An advanced Kotlin (Android Native) application that uses SOLID architectural principles, consumes a RESTFUL Service, downloads & images using best practices

Dog-Playground Kotlin An advanced Kotlin (Android Native) application that uses SOLID architectural principles, consumes a RESTFUL Service, downloads

Amose Suwali 1 Jan 10, 2022
NoteApp - A note taking app illustrating Android best practices with Jetpack Compose.

NoteApp - A note taking app illustrating Android best practices with Jetpack Compose.

Ömer Karaca 23 Dec 20, 2022
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Jan 8, 2023
This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

Saul Molinero 165 Nov 10, 2022
AudioNotes 📙 An open source simple audio note taking app built to demonstrate android development best practices.

AudioNotes ?? A simple open source audio note-taking ?? Android application built to describe the use of Modern Android development tools. ?? . Made w

Samson Achiaga 47 Dec 15, 2022
Samples showing best practices for MIDI on Android.

MIDI Samples This repository contains a set of individual Android Studio projects to help you write apps using MIDI APIs. Android MIDI 2.0 API samples

Android 23 Dec 19, 2022
Movie Android App written in Kotlin, MVVM, RxJava, Coroutine (Upcoming), Android Architecture Components and Jetpack Compose (Upcoming).

MovieHunt MovieHunt is a sample Android project using The Movie DB API based on MVVM architecture. It showcases the latest Android tech stacks with we

Engine Bai 596 Dec 31, 2022
To Do List App is built in Kotlin using Material 3, Data Binding, Navigation Component Graphs, Room persistence library, Kotlin coroutines, LiveData, Dagger Hilt, and Notifications following MVVM Architecture.

ToDoListApp ToDoList App demonstrates modern Android development with Hilt, Coroutines, LiveData, Jetpack (Room, ViewModel), and Material 3 Design bas

Naman Garg 10 Jan 8, 2023
A simple android app written in Kotlin to get defination of word entered from Free Dictionary API.

FlashCard A simple android app written in Kotlin to get defination of word entered from Free Dictionary API. Problem Statement Many of students don't

RITEK ROUNAK 3 Jan 20, 2022
A modular and portable open source XMPP client library written in Java for Android and Java (SE) VMs

Smack About Smack is an open-source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android. Being a

Ignite Realtime 2.3k Dec 28, 2022
A modular and portable open source XMPP client library written in Java for Android and Java (SE) VMs

Smack About Smack is an open-source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android. Being a

Ignite Realtime 2.3k Dec 21, 2021
An android app built using Kotlin following Multi-Module Clean Architecture MVVM

Notflix ??️ Work In Progress ?? An android app built using Kotlin that consumes TMDB API to display current trending, upcoming and popular movies ?? a

Victor Kabata 290 Dec 30, 2022
GithubBrower - Github Browser Sample with Android Architecture Components

Github Browser Sample with Android Architecture Components This is a sample app

KuanTing 0 Jan 6, 2022
Vaibhav Jaiswal 57 Jan 3, 2023
Weather application example with Android Architecture components and Clean Architecture

Weather application example with Android Architecture components and Clean Architecture Weather app that shows how to architect an android app in a cl

null 2 Dec 3, 2021