Componentization step by step (1)

Put the project address first: GitHub - iblue007/SmartRouter: Build a componentized framework step by step

Everyone will look at componentized things, and you must know the advantages of componentization, so I won’t go into details here.

To write componentization, first we need to build a componentized structure,

For example, how can components and plug-ins run independently? Let’s implement a simple variable control first (later blog posts will introduce other implementation methods)

This version first controls the switching between the component and the main project by configuring custom parameters, that is, switches. When it is opened, it is a plug-in in the componentization, and when it is closed, it is an independent app. The switch is as follows:

 

gradle can add additional custom properties through the ext property. Create a new config.gradle file first , and customize the isRelease property for dynamic switching: component mode/integration mode

 

So how to use this config file?  The config.gradle file needs to be referenced in the root build.gradle file of the project through  apply from

 

 

Then we have to make some judgments (there are two modules in the demo, one is app and the other is my)

1. In the case of componentization, the main project app should refer to the module my. If it is not componentized, the my module is not referenced.

 

2. Similarly, in my module, when my module is a component module, my module cannot have the package name applicationId, and build.gradle should refer to com.android.library. When my is an independent app module, it should Refer to an independent minifest.xml file, build.gradle should refer to com.android.application

 

So far, the most basic componentized project can be realized. If you want to see the code of this part, you can locate the following log cycle through the github log, and you can see the code as the most basic componentized project up.

 

If you like it, please give it a like, thank you

In the next article, let's talk about some dry goods, and realize project access in componentization through annotation, auto_service, javapoet and other technologies.

 

 

 

Guess you like

Origin blog.csdn.net/iblue007/article/details/109160919