Android project directory structure grouping realize Module

One, background

Frequent iteration project requirements, new product features are being added and extended, and brought that to enhance the technical complexity of the project.

In recent years, Android modular, component-based technology is related to speed the development of the project as a whole stratified, between different levels based on actual technical or business functions or business support module to divide the specific components or modules, is a component of or modular consistent course of action.

Complex product features, often bring the components or modules having a plurality of components or modules. For relatively steady, or with a multiplexing capability of the module, the module can be directly and independently formed and managed by independent Git repository or project in the form of modules, such as the introduction of external libraries, it is introduced in the form of an independent aar. But the main engineering project itself, eventually has a relatively complex modules directory. In actual use, which often may cause inconvenience view. At this point, we can be resolved by Module directory grouping.


Two, Module packet directory structure

2.1 module directory packet division

We can intuitively that feel for the project's main engineering Module view display, the corresponding figure below is an example.

 

Divided master module works relatively easy to understand, mainly includes three aspects:
1, the service module based on the division of a business perspective. Modules such as news, video module, operation ad module, login module register;
2, for a particular variant or construct basic functional configuration of the modules. Eguan module, Dev module;
3, module housing projects. The service module corresponding to each of the shell construction, to facilitate the development process to achieve a single module for installation and commissioning.

Only a relatively simple example of the main project directory structure, in some actual complex projects, the main project module will be more complicated. Between these modules, from the point of view of the positioning of its own responsibilities, having different levels it should be divided, corresponding Module should preferably have a different packet. Otherwise, the entire main project structure looks, there is a very messy feeling.

In this example, when the above-described "variant-specific or construct basic functional configuration of the module" and "module housing project", in fact, the actual program user-oriented body build, does not matter much. We can place a packet corresponding to Module.

Thus, we can create a corresponding two groups, corresponding in fact, two Directory, were called Extends and Module_App, are used to place the module under the responsibility of the two definitions above.

Ultimately, the main engineering modules directory view:

 

View of the expanded Extends and Module_App appear as:

 

 

Suddenly feel clear, there is wood there?

But this time, the project is not directly build success.


2.2 correction module reference configuration

Module directory structure has changed, the corresponding need for this Module configuration, but also the need to fix. Engineering settings.gradle file, for example, initially, the corresponding configuration is as follows:

include ':App', ':News', ':Videos', ':Message', ':Comments', ':Pictures', ':Personal', ':Base', ':LoginReg', ':ActAd', ':Main' include ':Dev', ':Eguan' include ':Main_App', ':News_App', ':ActAd_App', ':Message_App', ':Comments_App', ':LoginReg_App', ':Personal_App', ':Pictures_App', ':Videos_App' 复制代码

Each module in front of a name :, represents the root of the current with respect to the main works. Now change the directory path portion of the module, and the corresponding amended as follows:

include ':App', ':News', ':Videos', ':Message', ':Comments', ':Pictures', ':Personal', ':Base', ':LoginReg', ':ActAd', ':Main' include ':Extends:Dev', ':Extends:Eguan' include ':Module_App:Main_App', ':Module_App:News_App', ':Module_App:ActAd_App', ':Module_App:Message_App', ':Module_App:Comments_App', ':Module_App:LoginReg_App', ':Module_App:Personal_App', ':Module_App:Pictures_App', ':Module_App:Videos_App' 复制代码

Similarly, if other modules of the changed path Module dependent module, the corresponding need correction. The Main Module Dev dependent module, the initial configuration is as follows:

devImplementation project(':Dev')
复制代码

Now, we need to be amended as follows:

devImplementation project(':Extends:Dev')
复制代码

All correction is complete, we re-build the project, found modules.xml configuration files in the directory project .idea automatically updated.

 

At the same time, and Module_App Extens directory itself, automatically generated .iml corresponding file.

 

Meanwhile, the specific modules, IML module is configured automatically modified.

 

At this point, successfully constructed.

PS: If the actual project after changing into a Module packets and finished modifying the configuration, there are still build fails, you can try the following steps:
1, gradlew clear the cache:

./gradlew clean
复制代码

2, AS Clear cache:

File >> Invalidate Caches / Restart >> Invalidate And Restart
复制代码

3, delete the cache files in the root directory of the main project:

直接删除.idea目录,重启AS,会自动重新生成
复制代码

Third, the conclusion

Complex projects, often with complex module division. Depending on when the module functions, will be summarized into different Module packets that usually project development, there is a clear view of better structure, more attention can be focused on the development of a real project module body.

Change module directory structure, but in fact, with respect to the project root path changes. Correspondence, we only need to amend the corresponding configuration (.gralde file often corresponds to) the introduction of this module, the other without any changes.

In the actual project development, based on the actual situation, the appropriate grouping by Module, you can get a clearer view of the project structure.


end~

Author: HappyCorn
link: https: //juejin.im/post/5d5297db6fb9a06b0202b802
Source: Nuggets
copyright reserved by the authors. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

Guess you like

Origin www.cnblogs.com/lwbqqyumidi/p/11991773.html