In very simple business scenarios, a single project can achieve a complete App, and maintenance and development are very simple. However, when an App involves many functions, a single Module is very difficult. If the whole project is a Module, the business logic is written in different packages in the APP Module: No matter how well the subcontracting is done, the sense of hierarchy will be lost with the increase of the project and it will be difficult to take over. In addition, the package name convention is too weak as a constraint, which leads to direct calls between different business packages and highly coupled codes. Joint development is prone to conflicts and code coverage issues in version management. Then it is easy to have the following scenario:
// when I wrote this, only god and I understood what I was doing
// Now, god only knows
Copy the code
This paper mainly focuses on what is componentization, why it is needed and how to carry out componentization. The important role of routing in Android componentized development, analysis of the implementation principle of routing framework, how to step by step to achieve a routing framework.
The reasons for the need for componentization have been explained above, but it is important to note that:
Don’t componentize just to use it! Don’t componentize just to use it! Don’t componentize just to use it!
A technology is meant to solve a real problem. If the software isn’t big enough to use componentization, then there’s no need to use componentization. It’s stupid to use technology just to show off!
What is Android componentization
Componentization refers to the process of separating and reorganizing multiple functional modules when decoupling complex systems. In terms of Android engineering performance, App is divided into different modules according to its business.
1, the realization of the function of each component concentration itself, high aggregation module code, only responsible for a task, which is often said that the single responsibility principle of 2, the research and development of the business can be mutual interference, improve cooperation efficiency 3, business component can be inserted, flexible 4, will no longer be directly between the business component references and dependencies, every business module components become more independent, Reduce coupling 5. Speed up compilation and improve development efficiency
App shell project: responsible for managing various business components and packaging APK, without specific business functions; Function component layer: Provides basic function services for the upper layer, such as login and log services. Basic library: contains various open source libraries and self-developed tool libraries irrelevant to services.
The difference between componentization and plug-in
Component development: It is to divide an app into multiple modules, and each Module is a component (it can also be a basic library for components to rely on). During the development process, we can debug some components separately. Components do not need to depend on each other, but can call each other. When the final release is made, all components are relied upon by the main App project as ARR packages and packaged into an APK.
Plug-in development: It is slightly different from componentized development. In plug-in development, the whole APP is divided into many modules, including one host and multiple plug-ins, and each module is an APK (each componentized module is an ARR package). In the final packaging, the host APK and plug-in APK (or other formats) are separated or combined.