Mobile hybrid development framework + Android native modularization/componentization

1 background

    The Android native framework can be developed in a modular/component manner, whether it is a handwritten routing framework or an integrated open source framework such as ARouter. So can the hybrid development framework achieve component development?

2 implementation

   Based on my experience in mobile terminal development, I think there are two types of modularization: one is shared process among multiple modules; the other is cross-process between multiple modules. In Android, the cross-process access of each module is not understood in detail. As far as I know, the current way of jumping between modules is to share processes.

2.1 Process sharing

   The so-called shared process means that each module shares the same application sandbox, the same set of file storage, the same set of storage keys, and the same set of resource files (/res in Android).

2.2How to modularize the cordova framework

   The www folder in the Android native framework is the running directory of H5. The modularization of the cordova framework means splitting multiple business modules. Splitting includes two types:
(1) H5 side splitting: split the front-end cordova project into multiple independent projects
(2) Native side componentization: the native framework running in Android studio is divided into modules, each Each module corresponds to an independent H5 project, that is, each module has its own www package.

   The ultimate goal of modularization is to split a main app module into multiple business modules. When packaging, the main module depends on other submodules. Submodules share resource files under the main module.

Cordova modularization requires the following work:

   1. Split the front-end project into multiple projects according to project needs. The main app serves as a portal and integrates other business modules in the portal. Each front-end project may have different login logic, different interface styles, etc.
   2. The Android native framework integrates the routing framework, which can achieve routing jumps between modules.
   3. Integrate the cordova dependency packages and separate the dependency packages common to each module.
   4. Handwritten H5 side routing plug-in, used to trigger the sub-module menu in the portal and jump to the sub-module application.
   5. Configure different config.xml files for each module. Each module startup or loading requires regenerating the entire cordova environment, that is, each module has a different cordova context environment.
    6. Resources are shared between modules. For example, drawIds in different modules are consistent. If you want to have your own resource files, you can put them all under res under the main module.
    7. Configure the www structure under the submodule. Since the submodule will eventually be loaded into the www folder under the main module after compilation, this will result in multiple identical index files under the www folder of the main module. In this case, you need to add one to the www structure of the submodule. Module folder to identify this folder as H5 content under a certain sub-module.
    8. Modify the reference path of the Cordova js file in index.html. Each module shares the same Cordova js environment, so the path under the index.html file under the sub-module needs to be modified to ".../cordova.js".

www file path is as shown below

Insert image description here

How to upgrade and package the hybrid framework after it is modularized?

How to package the H5 resource files under www, how to dynamically upgrade them, and how to upgrade the version?
1. The H5 code of the main module still performs dynamic upgrade, and can also perform full update (for the entire apk).
2. The www of the sub-module can be dynamically pulled on the server. After the pulling is completed, it will be placed in the running directory of the main module and merged with the www file of the main module.

How to store multiple sqlite databases in the same application sandbox

Examples:
1. The main module is applied to the sqlite database and creates the database DataBase.
2. Other sub-modules also apply the sqlite database and create the database app_database_h.
Please tell me, how are DataBase1 and DataBase2 stored under the application's packageName?
Insert image description here
Analyzing the simulator application, we can find that the main module database exists under app_webview/databases, where Databases.db is the database under the main application module and stores the database index of the main module. app_webview/databases/file__0/1 is the data of the main module database

The database name of the submodule is app_database_h. Its path is /package name/databases/. The data will be placed in the file__0 folder in the current directory.

Summarize

1. Hybrid mobile development component development needs to consider front-end H5 page splitting. Different modules can be split into different H5 projects based on complexity. Each H5 project has different back-end service support.
2. The componentization method of the hybrid development model is consistent with the componentization method of the native Android framework.
3. Componentization needs to consider the dynamic pulling and upgrading of each module code.
4. When componentization involves local databases, you need to consider creating different databases for each module.
5. Componentization needs to consider resource sharing issues, and some problems need to be avoided in actual development.

Guess you like

Origin blog.csdn.net/superzhang6666/article/details/125789433