preface

I have been engaged in Android development for more than two years. When I started my internship in 2017, THE APP project was just established. At that time, the old MVC architecture of the old project was adopted in the new project. Since then it has been code without rules, based on erratic requirements.

Until 18 years, other project team to develop the APP require integrated into our APP, the project team from the project code for the first time at this point, the function of the APP, explosive increasing, the code itself are becoming very difficult to maintenance, debugging code often can’t find the old position, sometimes even need global searching with guess, from then on, I began to realize the importance of a good architecture and specification!

directory

  • Project introduction
  • An overview of the APP
  • The project structure
  • Component reuse
  • Follow-up prospects
  • conclusion
  • The resources

The body of the

I. Project Introduction

The content of this practice is based on Android JetPack component to achieve MVVM architecture, and combined with the current popular componentized development method, write a cookbook type small application. In the process of componentization, I combined the company’s APP componentization, gained some experience and lessons, and made some optimization and adjustment.

It should be emphasized that after using DataBinding in practice, I not only wanted to crash the computer during bug debugging, but also decided not to use DataBinding in this practice after reading Nanchen’s article “Talking about DataBinding pits from a Different Perspective”.

Project the current MVVM architecture design may not be ideal, and interface optimization also has certain problem, but it doesn’t matter, will follow-up to the project as a case, the systematic practice Android common start optimization, memory optimization and layout optimization and so on, practice process will be integrated into the article recorded, convenient learning, discussion in the future, Keep an eye out if you’re interested.

Data sources: Aggregate data – Recipe Book, Easy-Mock

Background server: Bmob (uses part of the Bmob API for user management, and uses easy-Mock for other data)

Development language: Kotlin (partially Java)

Main Jetpack components used: LiveData-Android Architecture Components Explore (1) -LiveData ViewModel-Android Architecture Components explore (2) -ViewModel Navigation-Android Architecture Components Explore (3) -Navigation Room, Lifecycle

To use third-party framework: the App USES a lot of third-party frameworks, here only list several, Tinker (hot repair), ARouter, Glide, RxJava, Retrofit, BaseRecyclerViewAdapterHelper, X5WebView and so on.

Open source: github.com/linux-link/…

2. APP Overview

Iii. Project structure

The conceptual structure of the project is shown in figure

The actual structure is shown in the figure

The functions of each module are explained below:

  • Library-Base

    The entire project base class, all third-party frameworks and custom View frameworks add dependencies here for unified management.

  • View_Xxx

    General custom View framework. Some app-specific view effects can be isolated into a Module. For example, this project uses a 3D page-turning effect library imitating Red Board newspaper, which can be independent into a module.

  • General_Xxx

    Generic framework for custom tools. Some frameworks that are common to all projects can be isolated into a module that is not associated with the business logic of the project for future use in other projects. For example, in this project, the network framework is packaged separately into a Module.

  • Library-Architecture

    General framework library. This typically includes BaseApplication, common utility classes, and architecture layer encapsulation such as BaseMvvmActivity.

    This module needs to be considered universal in packaging and, ideally, can be copied and used when starting a new project.

  • Library-Component

    Serves componentized Modules. Related to the business logic, mainly contains some componentalized encapsulation, and some common classes that the child components need to extract will also be placed here. Note that library-Component is the Library that all other child components must depend on.

  • Component_Xxx

    The child component. The specific implementation of each business logic in APP can be compiled as library, which can be used as a class library for other components, or compiled as Application, which can run debugging independently.

    Build. gradle in the project root directory controls whether or not each module needs to run independently using the xxx_isSingleCompile value.

  • app

    The entry point to the project, called the APP shell, is where all the sub-components are packaged into APK, mainly using runtimeOnly to speed up compilation.

Separately, each child component contains a gradle.properties file that sets the properties of the component when it is compiled into the AAR library, as well as the address and username and password of the private Maven repository.

Four, component reuse (2019-08-22 update)

An important purpose of componentization is to be able to reuse some of the components of the current APP in another project, just as we used Implementation to introduce some third-party libraries in the project that can also be used as a component. But for privacy, we mostly use nexus to build a private Maven repository on the company’s Intranet.

Will not be covered on how to build the maven warehouse, please make your own baidu, here I am on huawei cloud server set up a public maven repository (to build maven repositories, try to use host memory is greater than 2 gb), public address: http://119.3.215.243:9882, user name: Public, password: [email protected].

With the Maven repository, we can then try to package and upload components to the Maven repository for use by other projects.

1. Compile the AAR class library and upload the Maven repository

  • Select a Module and execute the build command to compile it into an AAR library. The compiled AAR file is generally under build->outputs-> AAR of the corresponding module

  • Configure the Maven repository address in gradle.properties, along with other properties of the component

  • Execute the upload script to upload the AAR library to the Maven repository

If successful is displayed on the console, the upload is successful

Next, how do you use the AAR library in your current or other projects

2. Use the AAR library

  • Add the address of your private Maven repository to version.gradle in the root directory
  • Introduce the AAR library using the unique project identity configured in gradle.properties
  • In setting.gradle, comment out the aar library modules that have been compiled

Through these steps, we realized the local reuse of components and reuse between different projects, and because a large number of components are compiled into aar class library, when the project is fully compiled, this part of the components do not need to be compiled, greatly improving the compilation efficiency of the project.

5. Future prospects

Currently, I am learning how to deploy and develop a simple background. In the future, I will gradually give up BMob, increase the complexity of the APP and introduce more development technologies, such as plug-in, NDK, React Native or Flutter, which I am most interested in. The ultimate goal is to practice the current mainstream development technology in an APP, and then choose a direction for in-depth research, but this is a story for the future. After all, the ideal is full, the reality is very backbone.

The 2019-08-22 update

  • Since version 1.0.3, a simple mall with an independent process has been integrated in APP. The mall is developed using H5 and the payment function is developed using Native. In essence, the mall is a multi-process component of Hybird architecture.

Part H5 is based on the source code used in a vue.js course on MOOCs, so the source code is not public. However, I also set up an address that can be accessed on the public network: http://118.24.197.176. Because the data needs to be obtained by the built-in network service of the APP, some data is missing when accessing this address in the browser.

Six, summarized

So that’s the overview of this project. In general, you can use it to learn component-based development, to learn how to use the Android Jetpack component in action, and to learn how to optimize an APP. But this will be in my next update, the memory optimization part, which has been released in advance. Please go to “Android Memory Optimization 1” -Android memory mechanism and management suggestions.

If you have any questions or suggestions, please leave a comment or submit an issue on Github. Thank you for reading, welcome to download experience.

The resources

How to Build an Android MVVM Application Framework

Best Practices for Android Componentization

The Practice of Componentized Architecture from an Ali Friend