Big line

Detail the history of mobile developmentCopy the code

Big technology

Componentized development component Routing component configuration dynamic loading component skeleton architecture plug-in development static plug-in dynamic plug-in detail optimization of network layer and implementation of architecture dynamic burying point technology layer architecture (MVP, MVVM and other modes)Copy the code

Big scope

Follow up to share the technical points in a simple way, please subscribe to follow.Copy the code

preface

This article takes 8 minutes to read. What you might get: An understanding of the company's mobile development baselines and mainlines learn about problems and solutions encountered by the mobile development team Learn about the nit-grins of the mobile development process and hopefully give readers some insight into the development projectsCopy the code

The body of the

I understand that technology developers, in addition to their love of business and technology, also need to have the ability to think independently.Copy the code

In this high-speed transformation of the two-dimensional mobile development era, many products and companies to catch up with the rapid changes are racing against time to conquer the city and land, accompanied by the mobile research and development is also entered along with ‘beating drums to create the world’.

Therefore, it is necessary for us to analyze and think about the current cycle of mobile development. As far as personal understanding is concerned, the mobile development life cycle is divided into four cycles, which accompany the whole process of company development synchronously.

The four life cycles are named:

1. Growth stage 2. Chaos stage 3. Unification stage 4. Chaos period is generally in the second to third years of the company; The period of unification and differentiation is after the third year of the company; The unification and differentiation stages may be repeated iterations.Copy the code

The so-called growth period is also the legendary savage development. At this time, the leading direction of the company is to follow up the market quickly and iteratively, which is a process from scratch as a research and development milestone and the number of personnel. Its purpose is to develop catch-up products and realize the rapid launch process.

At this time, the selection of development technology is based on personal factors, so the selection and architecture of the early project are dominated by personal technology preference. The technology and framework I am familiar with are the fastest and most effective, and I can quickly catch up with the online progress. Like RXJava, like MVP mode will soon dominate the solution and technical architecture in this project. There are even some developers who directly blame the web for so-called well-structured, off-the-shelf projects. At this time, the only purpose of the company is to produce products in the first market, rapid iteration occupies the mind of every developer, details and so on can be ignored, what bicycle.

Then, with the company’s first performance shot, financing also came down, began to recruit, personnel supply, began to appear confusion and run-in period, the new staff feel that the old code is a piece of shit, all kinds of heart contempt and uncomfortable; Older employees think new employees are pushy and don’t know anything and like to act pushy. But the purpose of the company’s support staff is to iterate projects more quickly, and the company is also prone to some kind of agile development ghost model of iterating a release in a week or two.

The need to continue to develop the code has to iterate, and the new and old developers write code according to the gourds, slowly (can N), slowly over a period of time found that the code is full of all kinds of coupling, non-standard code, file package chaos, business interludes, a word of chaos, a variety of online bugs pop out; The online bug statistics showed that the FUCK index exceeded 5-10%, and the whole group began to meditate and reflect, producing the unified idea of published book reconstruction and iteration.

At this time, there are generally two waves of people, one group of people to continue business iteration and another wave of people to carry out project reconstruction; The core of this matter is to reduce the number of online bugs and achieve the target of online bugs not exceeding 3% as required by the company. At this time, the reconstruction focuses on dimensionality analysis based on online bugs and divides problems according to the number. The problems at this time are as follows:

1. Visual real-time monitoring and statistics of bugs; 2, reference memory is not released causing crash bug; 3. Memory leak causes crash bug; 4. Bugs caused by models entering the market; 5. Feedback of slow network access; 6. Strange and unknown bugs; 7.Copy the code

Question 1, the introduction of third-party systems, such as Bugly, etc

In problem 2, Eventbus is introduced to solve the problem of callback hell and the problem of leak not released caused by callback.

Question 3 thinking, the introduction of LeakCanary memory leak detection, and Prof analysis method based on each problem breakthrough;

Problem 4 thinking, no solution, can solve one is another, the main company models can not keep up with the online model provider to test the problem, expensive not to say and feel useless;

Thinking about question 5, slightly;

As for the online bug index specified by the company, whether it has been completed can only be counted after the operation of the live network with multiple iterations. Since it is a live network bug, there is a degree of severity. If major bugs are generally updated immediately, and minor bugs are repaired iteratively in the next version, there must be a live network bug hot fix scheme. There are mature third-party libraries such as Tinker.

After working overtime to solve the above problems, with the development of the company’s business and the strong promotion of the market, many business lines have mushroomed and started projects. Looking at the current project architecture mode (see Figure 1),

                                

Figure (a)

With a long sigh, the hidden hidden danger and anxiety in my heart slowly emerged. The project is still full of code coupling and confusion, plus the “chaotic code plus new code is still chaotic code” theorem has been pressing on the top of my head, the project framework is certain
Unable to keep up with the company’s new business line development and planning; When there is pressure, there is motivation. After careful consideration, a hierarchical Module structure emerges. Each line of business is a Module, and then each line of business is copied and pasted in accordance with the pattern of this Module and then we start to report on the business. Generally this kind of situation need to continue into the basic module will occur after three business lines between chaos calls, resource files to fly everywhere, all kinds of repetitive and code to add access control is less than based library so that everyone has access to write various business down to the base library public code is bloated, hybrid compilation of the module as well as the extremely slow problem a lot of come out, Looking back at the status of the project, I go, here we go again, endless work. If you think you’re a Virgo, you’ll go nuts and either fire your boss or get your head down and analyze.

Figure (2)

After analysis, the following problems need to be solved urgently.

2. It is time to add code permission management 3. 4. Solve the problem of slow compilation speed 5. Automated packaging problems 6.Copy the code

Question 1: Since decoupling is implemented and hot-pull scheme is implemented at the same time, the white point is that the current module switch is off, and other referenced modules cannot sense that this module is closed, that is, the code referenced by other modules must not hardcode the methods and reference classes of this module, etc., and the scheme is component routing. The caller queries the module’s services and functionality through the string PATH.

In consideration of question 2, code permission management is generally implemented through Git or SVN.

Problem 3 thinking, you can use Gradle scripts to achieve module packaging upload private server.

In consideration of question 4, the problems of Gradle itself and the number of modules lead to the slow compilation speed. According to the independence of the business line, we can implement App mode for this module when writing the business module to reduce the compilation and running of other unnecessary codes. The implementation scheme is as follows:

Compiling scripts in modules gradle uses identifiers to distinguish between modules and apps that can run independently

sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
            if ("true".equals(FINANCE_IS_APPLICATION)) {
                manifest.srcFile 'src/main/diff/appmodule/AndroidManifest.xml'
                java.srcDirs = ['src/main/java'.'src/main/diff/appmodule/java']
                res.srcDirs = ['src/main/res'.'src/main/diff/appmodule/res']
                assets.srcDirs = ['src/main/assets'.'src/main/diff/appmodule/assets']}else {
                manifest.srcFile 'src/main/diff/libmodule/AndroidManifest.xml'
                java.srcDirs = ['src/main/java'.'src/main/diff/libmodule/java']
                res.srcDirs = ['src/main/res'.'src/main/diff/libmodule/res']
                assets.srcDirs = ['src/main/assets'.'src/main/diff/libmodule/assets']}}}Copy the code

So we need to run the module separately, setting FINANCE_IS_APPLICATION to true in gradle.properies
Compilation then enables business code to be written and run. Someone said, if I need to implement a new business in the main App, then you can shut down other irrelevant modules for fast compilation to improve development efficiency.

Question 5: With the expansion of the project and multi-channel packaging, business services surrounding the project need to be considered at this time, such as packaged testing for testers, release of official version and other automation output issues.

General automation services can be built by Jenkins services, or with Python scripts to achieve automatic packaging function, the function of the script varies from company to company.

                     

(3)

There is an urgent need for someone familiar with gradle, Python, etc. (Gradle itself is grovvy). It takes at least half a year (except for large companies) to reconstruct and perfect the whole process under the condition of ensuring the development of new business.

Gradually found that the componentized architecture quietly emerged, isn’t it amazing? Turn back to find that the component architecture has been carried out a small part, full of confidence, continue to do, at this time must sacrifice MAO Grandpa’s red book, read out loud, I love programming, skin good!!

We found that we have done business modularization code separation and module routing intermodulation communication and Gradle componentation script;

Your growth is based on the growth of the company. With the development of the company’s business, there will be independent branches for various reasons. Some sub-business lines need to be independent from App to provide professional services and experience. You need to sow seeds and bear fruit, the original sub-module may become a standalone App, so you find the current architecture is not possible, yes, come here, please think under the bodhi tree; The fundamental reason is incomplete componentization. The biggest problem is the main project module involves a large number of the earliest business code and function before, now the most urgent problem is the need to take additional qualifications to peel into a business module and a pure project skeleton, become the new main projects including project skeleton must rise level modules, the main module contains common business projects. To put it bluntly, the skeleton of the project within other submodules is a separate App that can be run; As a comparison, Figure 4 is the original architecture diagram, and Figure 5 is the architecture diagram of the skeleton of the main project module

The main project skeleton must contain the following functions:

1. Project upgrade and downgrade function; 2. Reference and initialization of third-party libraries; 3. Implement sub-module loading, introduction and initialization; 4. Introduction and initialization of peripheral services or plug-ins; Such as Tinker and Bugly, etc.Copy the code

               

Figure (4)

                   

Figure (5)

At this time, the componentization has been basically completed. Now the only thing to do is to make the glue through gradle script. The script works with Jenkins to dynamically realize the combination between modules and the skeleton of the main project. The componentized forming mentioned above means that the main skeleton is complete, but it needs to be further decoupled and separated according to its own business. Generally, as follows:

1. Separate the global configuration file, for example, separating the configuration of the network address from the network request address. 2. Service configuration files are separated to realize modular separation together with the server. 3. Common business dynamic loading blocks of each sub-module; 4. Separation and reconstruction of coupling code; 5....Copy the code

This process should achieve various decoupling and separation of project modules and code, and look very clean and clean. Do not feel and began to sing: I love programming, skin good!!

Suddenly one day you hear someone say “plug-in”, you secretly smile, our project has already achieved hot pull plug-in; A discussion found that the original is not what you think of plug-in, they said that plug-in is the business module dynamically stored on the Internet, when the need to load in; Wow ka ka, the original plug-in divided into two types, has been static plug-in and dynamic plug-in; We’ve implemented static plugins, and that’s what it’s all about. Oh, it’s natural; The premise of dynamic plug-in must be that the project has formed the component before dynamic plug-in function can be realized.

At present, each sub-module can be packaged into AAR, JAR and APK independently. The next step is to add a dynamic plug-in to the main project skeleton; There are a lot of mature schemes on the market of dynamic plug-in perfect now, because this is not like componentization process, componentization itself and business and project have a lot of relevance, need to process and architecture according to their own business and the existing business framework; while

Dynamic plug-in implementation mechanism has nothing to do with the business system and its own architecture, it can boldly introduce mature third-party plug-ins; For example, the dynamic plug-in of Meituan and Ali.

In fact, the aftertaste of the whole process, found that these are step by step to go down, can not be a step in place, this is life; This is just the first few steps of the long march. In the future, details and technology need to be further refined. The improvement of peripheral services and the implementation of supporting facilities such as security need to be realized by you. Lu Yao boundless…

Details carved casually enumerate a few:

1. For example, in the bug mentioned above, the network performance is slow, which can be further explored. For example, Tencent has implemented the Mars open source framework for this small point; 2. Encapsulation of business UI framework (reduce repetitive development and performance issues); 3. Performance monitoring; 4. Configure the management center. 5, dynamic buried point; 6. Optimized the core points of each business; 7. Componentized reconstruction and optimization of writing; Technical layer architecture (MVP, MVVM, etc.) 9. Distributed architecture; 10)...Copy the code

In the end, you will find that many functions can be implemented only after componentization or plug-in completion to achieve twice the result with half the effort, achieve centralized optimization change distribution minimization, greatly reduce the risk and change
Risk;

In fact, the above process is a long time will be divided into the process. When the project goes to the extreme, it is still unable to cope with the huge user group and business group, please switch to pig farming...Copy the code


Plug-in routing implementation, see the source code, feel good please click star: my routing