DEV Community

Cover image for HarmonyOS Development: Project Initialization and Construction of Information Project Actual Combat
程序员一鸣
程序员一鸣

Posted on

HarmonyOS Development: Project Initialization and Construction of Information Project Actual Combat

Foreword

this project API>= 13, this chapter is very simple, experienced developers can skip.

In the previous article, we briefly summarized the framework and code architecture design of this information project. In this article, we directly entered the code writing stage and first determined which modules need to be implemented. Although it is said that it is modeled on today's headline, today's headline has so many functions. If all of them are implemented one by one, time and energy will not keep up. After all, this project is only for learning, as long as the relevant technical points are covered in place.

I have roughly divided into four modules, the home page information module, the video module, the message module and my Module. The final effect is presented. At present, I have found a prototype of information App, which is roughly as follows. The final effect is also as close to the prototype design as possible.

The above are only the main modules, and there are many sub-modules under each module. This can only be implemented when it is implemented. For some specific functions, such as Carousel diagrams, such as video sliding up and down viewing, although not in the prototype, it will also be implemented in specific projects.

All things are difficult before they begin. The first step is to create a project and select an empty Ability. There is not much to say about how to create a project. If you don't, it is recommended to read the articles I shared before, or check the official videos or documents.

Module Creation

in the preface, we divided four modules, so in the created project, we can directly create four modules. The type is dynamic shared package. Why do we choose dynamic shared package? First, it is convenient for us to run in componentization. Second, when there are multiple installation packages that need resource sharing, we can also use HSP to reduce public resources and code duplication packaging.

Click on the created Project, select the project, and right-click new->Module to create the Module.

Image description

Select the dynamic Shared package Shared Library.

Image description

Enter the module name, four modules, divided into home module, video module, message module message, my module mine; Device type, according to their own needs to choose.

Image description

After one by one creation, our project, plus the main module entry, has five modules, and the effect is as follows:

Image description

although there are many modules, they are ultimately dependent by the entry, and there is only one final entry. Of course, each module can be run during the test run.

After the module is created, we can rely on it in the oh-package.json5 of the main module entry:

Image description

middle layer (common)

why is there a middle layer? The purpose is to reuse, when we component split, each module will have the same function calls, such as network requests, such as resource acquisition, in order to avoid code redundancy, we can put some common resources or tools together, which is the reason for the middle layer.

Of course, the middle layer also needs specific analysis of specific problems. After all, componentization is for reuse. With the existence of the middle layer, the middle layer also needs to be reused in future project reuse. If you want to realize pure single module reuse, you can also not use this middle layer. The advantage is that it is easy to introduce and give some people the permission of a certain module in a huge project, the disadvantage is code redundancy.

Here, we choose the mode development of the middle layer. After all, each module is not only the reuse of resources and tools, but also a link for data transmission. Therefore, we continue to create a common module.

Image description

After the creation is completed, let the four modules home, video, message, and mine depend on the common module respectively.

Image description

Related Summary

at present, our information project has only taken a small step forward, only realizing the creation of the project. Although the step is small, there is a lot of conceptual knowledge, which is also the original intention of this project, so that everyone can not only master the daily technology development, but also let everyone understand the actual project development knowledge.

In the next article, we will still not involve code writing, because although we have already created each module, there is still a problem in front of us, that is, how each module runs independently, which is also one of the core elements of our component-based development. If the module cannot run independently, it is modular development, not component-based development in the true sense.

The next article will explain how modules run independently and how to switch between running packages and dynamic shared packages. Please look forward to it!

This article label: Hongmeng News Information Application

Top comments (0)