当前位置: 首页 > 软件库 > 手机/移动开发 > >

android-modular-architecture

授权协议 Apache-2.0 License
开发语言 Kotlin
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 红鸿运
操作系统 Android
开源组织
适用人群 未知
 软件概览

Android Components Architecture in a Modular Word

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 Androidapplication architecture that is modular, scalable, maintainable and testable. This application may look simple, but ithas all of these small details that will set the rock-solid foundation of the larger app suitable for bigger teams andlong 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 orderensure 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

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.
  • 说明:转载自Android官网https://source.android.com/devices/architecture/hal,方便国内查看。   HAL Types In Android 8.0 and higher, the lower-level layers are re-written to adopt a new, more modular architecture. Devic

  • 一、NetworkAgent 和NetworkFactory的区别 NetworkAgent是被NetworkFactory创建的,这里的创建并不是说在NetworkFactory内部创建 NetworkAgent,而是说,在NetworkFactory这个环境就绪之后,网络提供者才可以创建 NetworkAgent。并且在一个NetworkFactory中可以创建不同的NetworkAgent,

  • [Android S] statsd 统计log信息流程 参考文档: https://source.android.google.cn/devices/architecture/modular-system/statsd https://www.dazhuanlan.com/ostrichmyself/topics/1301914 移动端 Statsd In android 9 (1) https

 相关资料
  • Nuxt is based on a powerful modular architecture. You can choose from more than 50 modules to make your development faster and easier. You don't have to reinvent the wheel to get PWA benefits, add Goo

  • 我在实际工作中发现很多类和模块是非常独立和相似的:它们一般都需要有初始化和反初始化的过程。一般做法是在程序初始化的位置对这些类和模块进行集中配置。比如程序中有ModuleA、ModuleE、ModuleF这三个模块,而且这三个模块之间有依赖顺序ModuleE<ModuleF<ModuleA,这时候的初始化过程就是: ModuleE.Init(); ModuleF.Init(); ModuleA.I

  • Click Modular Router(以下简称Click)是由加利福尼亚大学洛杉矶分校(UCLA)的Eddie Kohler等人设计的。Click是一种新的软件体系结构,它被用于建立灵活的和可配置的路由器。 Click路由器集成了被称为element的多个分组处理模块。每个element实现一个简单的路由功能,例如对分组分类、排队、调度,以及与网络设 备实现连接等。一个路由器的配置就是一张el

  • 模块化页面一开始很难理解,但一旦你了解它,它就会很容易使用。 它可以从其子页面创建单个页面。 它能够从模块化内容页面构建复杂的单页面布局。 模块化页面设置为不可路由,因为无法通过URL直接访问它们。 它们在文件夹名称之前由_(下划线)标识。 它是一组页面,每个页面都显示一个以获得单个页面。 例如, user/pages/home/_header. 。 文件夹结构 如果是单页骨架,您可以在01.ho

  • 我正在尝试对作业使用Spring批处理。我有两个作业tempJob和tempJob2在两个单独的配置中。当尝试使用命令行参数(-dspring.batch.job.names=tempJob)运行tempJob时,SpringBatch尝试运行tempJob两次,我得到以下错误 2018-06-15 11:36:37.956信息14436---[main]O.S.B.C.L.Support.Sim

  • Clean Architecture on Android: the Teamwork.com way! The purpose of this repository is to showcase, with a very simple (but hopefully clear) sample Android project, how we implement Uncle Bob's Clean