Thinking triggered by ARouter, what exactly is componentization and modularization?

This article may be controversial, and bigwigs may have different opinions. The following content is only my personal opinion. If it is inappropriate, please point it out in time.

The reason is that I want to review ARouter recently, but I just read it but don’t write it, so it will be abandoned sooner or later, so I started to write a demo. It doesn’t matter if I don’t write it, because it will expose many problems.

Speaking of ARouter, it must be a cross-module jump . In this case, let’s build two modules and let the interface between the two modules jump. Will such a simple demo be completed in a while?
insert image description here
Jump from the app module to The im module, after writing, found that there is no route match the path error, no matching path was found.

Here we first sort out the ups and downs we have experienced in order to solve this problem (there is no way to find a matching path)

  1. Is the annotation format correct like @Route(path = "/qqq/test1/second1") at least two paths
  2. Whether the names of the first paths under different modules are the same, and the first paths of different modules should not be the same
  3. Whether annotators are introduced under each module
    Java:  annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
    Kotlin:  kapt  'com.alibaba:arouter-compiler:1.2.2'
  1. Whether to obtain the module name operation under each module, it should be noted here that Java and Kotlin have different writing methods
    android – defaultConfig
     JAVA
     javaCompileOptions {
    
    
            annotationProcessorOptions {
    
    
                //注解处理器需要的模块名,作为路径映射的前缀
                arguments = [AROUTER_MODULE_NAME: project.getName()]
            }
        }
     Kotlin
     android上方添加:
     apply plugin: 'kotlin-android'
     apply plugin: 'kotlin-kapt'
     apply plugin: 'kotlin-android-extensions'
     
     kapt {
    
    
            arguments {
    
    
                arg("AROUTER_MODULE_NAME", project.getName())
            }
        }

If there is no trick above, there is another test method, look in the run log to search

LogisticsCenter has already been loaded
LogisticsCenter has already been loaded, GroupIndex[4], InterceptorIndex[0], ProviderIndex[2][ ] 

If GroupIndex[ ] is greater than 1, it means that the registration is successful. If there is no accident: if the report does not find the path, then GroupIndex[1]

Don't panic at this time, since there must be a reason for the failure to register successfully, there is a high possibility that we have encountered the same problem-there is a problem with the project structure .

Same title, what I encountered here was a "misunderstanding" of cross-module jumps. Since it is a cross-module jump, I created two modules for jumping, and there is nothing wrong with it. Connect the preceding and the following through interrogative sentences to lead to the following ->

What are components? What is componentization? What are modules? What is modularity?

Before writing this article, I did a lot of Baidu questions

Many bloggers use modularization as the title, but the so-called "module" is referenced in the form of components in the project framework. Of course, this is not a problem, but it will give people a trance illusion

Here I will sort out with my own understanding, for reference only

Components and modules are two physical things, while componentization and modularization are two virtual things

After we build the project, the default app is a module, and the newly created module is also a module. The module can be run as an independent project, which is equivalent to two apps. From the perspective of the project structure I created, it is equivalent to what you want to pass It is impossible for the QQ friend space icon to jump to the WeChat Moments interface, so ARouter reported that the relevant path was not found

And components are just like the literal meaning, the parts that make up the project, just said above that a module (module) is equivalent to an independent project, can be converted into components that make up the parts of the moudle

Summary: A component is a part that makes up a project, a module is a separate project

Modularization is an abstract concept, which is actually not necessarily related to modules, so it can be understood as the same name

Modularization : I divide a project into homepage modules. My modules are equivalent to dividing a plate of melon seeds into the original flavor on the left half and the jujube flavor on the right half.

Module : I divide a project into two projects Homepage project, my project is equivalent to dividing a plate of melon seeds into two plates: one plate of original flavor and one plate of red date flavor

At this time, the Arouter is like a worm in the plate, trying to get from one bad melon seed to another bad melon seed. When you divide the melon seeds into two plates, the worm cannot go to the other plate.

Componentization : I have a Lamboniki at home, and my friend wants to borrow it for a few days to drive. It’s too far away to drive, so I’ll send it by post. It’s not cost-effective to send it as a whole. I’ll split it into several parts and develop it separately. Coupon, I disassembled the front, the rear, and the body, and I made my car into components

Components : front, body and rear

Then coming to the project is to classify a project by module (modularization), and then apply these modules to the project in the form of components (componentization) instead of in the form of modules, which is why we will com.android Change .application to com.android.library

Then Arouter's cross-module jump is actually a cross-component jump (because a component is a module), so I modified my project architecture to

insert image description here
At this time, im and library are two components of the app, and the interface between them can be redirected normally through ARouter, but the Intent cannot be skipped, and the relevant interface cannot be found.

If you don't understand the above, it doesn't matter, let's illustrate it!
insert image description here
insert image description here

I put the homepage module of this project and my module in these two components, can this also be called a jump between modules?

Supongo que te gusta

Origin blog.csdn.net/As_thin/article/details/123896704
Recomendado
Clasificación