A method for loading lightweight OpenHarmony applications on Android system
By using the Activity component as the container of the OpenHarmony application on the Android system, the loading and running of lightweight OpenHarmony applications is achieved, solving the problem of cross-platform development, saving development costs and improving efficiency.
Patent Information
- Application Number
- CN202311814160.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-12-26
AI Technical Summary
Existing technologies cannot directly install and run lightweight OpenHarmony applications on the Android system, which requires application developers to repeat development for different system platforms, increasing the workload.
Use the Activity component of a standard Android application as the running container of the OpenHarmony application, achieve lifecycle synchronization through the LiteActivity and AceAbility classes, compile the Aafwk application framework into a dynamic library and package it as an Android resource package, and use the Android system's window management service to load the OpenHarmony application.
It enables rapid deployment of lightweight OpenHarmony applications on the Android system, saving development costs and improving development efficiency and application performance without modifying the native system.
Smart Images

Figure CN117785320B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded platform application development, and in particular to a method for loading a lightweight OpenHarmony application on an Android system. Background Art
[0002] The system's application development framework is a core component. The lightweight OpenHarmony application development framework is called the meta-capability component Aafwk. Applications are developed based on Aafwk and ultimately packaged into hap packages, which are then installed and run on the OpenHarmony system. Aafwk itself is deeply integrated with the OpenHarmony system and does not support deployment on other platforms. Therefore, hap applications cannot be directly installed and run on platforms other than the OpenHarmony system. Therefore, application developers need to redevelop applications for different target platforms, resulting in a doubled development workload.
[0003] To this end, the present invention designs a method for loading and running hap on an Android system, so that hap applications can be quickly deployed to the Android system for loading and running, thereby saving application development costs. Summary of the Invention
[0004] To solve the above problems, the purpose of the present invention is to propose a method for loading lightweight OpenHarmony applications on an Android system, so as to realize the operation of lightweight Hongmeng applications on the Android system, thereby saving application development costs.
[0005] In order to achieve the above technical objectives, the technical solution adopted by the present invention is:
[0006] A method for loading a lightweight OpenHarmony application on an Android system. This method uses the Activity component of a standard Android application as the runtime container for the OpenHarmony application's Ability. The Openharmony application is compiled and downloaded to the device as an Android application resource file. The Ability is started through a pre-installed LiteActivity and the application's .js / .bc files are loaded and run.
[0007] In terms of lifecycle scheduling, the lifecycle scheduling of OpenHarmony applications is implemented based on Android's Activity lifecycle and window management.
[0008] As a possible implementation, the method for loading the lightweight OpenHarmony application on the Android system further includes the following steps:
[0009] Compile the Aafwk application framework into an independent dynamic library libAceLite.so;
[0010] Create the AceAbility class to encapsulate the application Ability-related lifecycle interface provided by the libAceLite.so library;
[0011] Create a LiteActivity class that inherits from the Android system's AppCompatActivity class and call the Ability-related methods in the AceAbility class in its lifecycle callback method; this ensures that the Ability of the OpenHarmony application can be synchronized with the lifecycle of the Android application's Activity.
[0012] Create a LiteApplication class that inherits from the Application class of the Android system. Process the hap application file in its onCreate method and save the application package name and path in class variables; so that they can be obtained and passed to the relevant interfaces of libAceLite.so in the onStart method of the AceAbility class.
[0013] Package LiteActivity.java, AceAbility.java, and libAceLite.so into the Android resource package AndroidAdapter.aar to facilitate direct reference in Android application projects.
[0014] Build an Android application project that directly depends on the AndroidAdapter.aar package. The Application class of the application project inherits LiteApplication, and MainActivity inherits LiteActivity to ensure that the ACELite application can run normally in the Android environment.
[0015] After decompressing the hap application developed based on the ACELite framework, the complete file directory is stored as a resource file of the standard Android application apk in the assets directory of the application project;
[0016] When the application starts, LiteApplication is responsible for parsing the hap resource file, while LiteActivity is responsible for loading and running it.
[0017] As a possible implementation, the startup loading process of the lightweight OpenHarmony application on the Android system further includes:
[0018] When the application process is created, the system calls the onCreate method of Application, obtains the relevant files of the hap application package in the application resource directory, copies them to the data directory of the application, saves the package name of the hap application package and the copied data directory path, and provides getJsBundlePath() and getDataPath() accordingly; starts the entry Activity, calls the onCreate method of Activity, initializes the SurfaceView object and constructs AceAbility, and calls the onStart method of the AceAbility object; loads the libAceAbility.so library, obtains the Ability-related lifecycle interface, calls the getJsBundlePath() and getDataPath() methods of the LiteApplicaiton class, obtains the hap application package name and path, calls the onStart method of libAceAbility.so, passes in the hap application package name and path, and starts the Ability.
[0019] As a possible implementation method, the startup loading process of the lightweight OpenHarmony application on the Android system specifically includes the following steps:
[0020] 1) Application launch: When a user clicks an application icon or launches an application through other means, the system starts the application process;
[0021] 2) Application process creation: The system creates the application process and initializes the LiteApplication class in the process;
[0022] 3) LiteApplication initialization: In the onCreate method of LiteApplication, obtain the relevant files of the hap application package in the application resource directory and copy them to the data directory of the application; save the package name of the hap application package and the copied data directory path, and provide getJsBundlePath() and getDataPath() respectively;
[0023] 4) Start the entry Activity - LiteActivity: The system starts the entry LiteActivity of the application, and then the system begins to call the lifecycle methods of LiteActivity. In the onCreate method of LiteActivity, the SurfaceView object is initialized and the AceAbility is constructed, and then the onStart method of the AceAbility object is called;
[0024] 5) Start AceAbility: AceAbility is responsible for loading libAceAbility.so, obtaining the hap application package name and path by calling the getJsBundlePath() and getDataPath() methods of the LiteApplication class, and finally calling the onStart interface of the libAceAbility.so library to start the Ability of the corresponding hap application.
[0025] As a possible implementation, further, the LiteApplication in step 2) is the entry point of the entire application, and its instance remains a single instance during the life cycle of the application.
[0026] By adopting the above technical solution, the present invention has the following beneficial effects compared with the prior art:
[0027] 1) The present invention provides a systematic approach that enables lightweight HarmonyOS applications to run on the Android system, filling the gap in the industry in this field and reusing the native window management service of the Android system without the need to modify the native system. This comprehensive solution at the pure application layer provides developers with clear guidance for running HarmonyOS applications on the Android platform.
[0028] 2) By running lightweight HarmonyOS applications on the Android system, the method provided by the present invention avoids developing new Android applications from scratch, and realizes the one-time development and multi-terminal deployment of lightweight HarmonyOS applications, while maintaining consistency while improving development efficiency, allowing developers to focus more on the implementation of application logic and functions. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0030] Figure 1 This is the Ability life cycle flow diagram;
[0031] Figure 2 A flowchart for launching and loading lightweight OpenHarmony applications on Android systems;
[0032] Figure 3 This is the directory structure diagram of the application template project. DETAILED DESCRIPTION
[0033] The present invention will be described in further detail below with reference to the accompanying drawings and examples. It is particularly noted that the following examples are intended only to illustrate the present invention and are not intended to limit the scope of the present invention. Similarly, the following examples are only some embodiments of the present invention and are not intended to be exhaustive. All other embodiments obtained by those of ordinary skill in the art without creative effort are intended to fall within the scope of protection of the present invention.
[0034] Applications on the OpenHarmony system are scheduled using Abilities. Each Ability is a component capable of performing a single function, and an application can contain one or more Abilities. Each Ability has its own lifecycle, which collectively refers to the various states through which an Ability is scheduled by the system: start, activate, hide, and exit. Applications can implement functional logic for each Ability stage by overriding the corresponding lifecycle hook functions. The Ability mechanism, a core design of the OpenHarmony application framework, is closely tied to the system's AMS (Ability Manager Service). The AMS determines which Ability is currently in the foreground, tracks its lifecycle, tasks, and stack, and coordinates interactions between them. The AMS service cannot be run directly on the Android system because the Android system has its own set of application scheduling services and mechanisms based on the Activity component, called the ActivityManager. The ActivityManager is responsible for tracking and managing the lifecycle of all activities in an application, including creation, start, resume, pause, stop, and destruction. Android applications exist as tasks, each of which contains one or more activities.
[0035] The ActivityManager is responsible for maintaining the stack relationship between these tasks, ensuring that Activities are displayed correctly when users navigate between applications. It also monitors application processes to ensure they run properly even with limited system resources. It can start, stop, and restart application processes. The method designed in this invention uses Activities as runtime containers for OpenHarmony application Abilities, thereby enabling the loading of OpenHarmony applications on the Android system.
[0036] Specifically, Ability is the smallest unit of application called by Hongmeng system. An OpenHarmony application can contain one or more Abilities. The flow diagram of its life cycle (which is conventional existing technology) is shown in the attached figure. Figure 1 Similar to the way that Android systems schedule activities in units of activities, the design of this invention uses the Android system's activities as host containers for the OpenHarmony application's abilities, thereby reusing the Android system's native window management services. The following table shows the corresponding relationship between their life cycles:
[0037]
[0038]
[0039] Based on a deep understanding of the Aafwk framework and Android system design, the present invention proposes a solution for loading OpenHarmony applications on the Android platform, and designs a reasonable engineering structure for the adaptation of the openharmony application on the Android platform. In terms of design, the Activity component of the standard Android application is used as the running container of the OpenHarmony application Ability. After the Openharmony application is compiled, it is downloaded to the device as a resource file of the Android application. The Ability is started through the preset LiteActivity and the application's .js / .bc files are loaded for operation. In terms of lifecycle scheduling, we implement the lifecycle scheduling of the OpenHarmony application based on Android's Activity lifecycle and window management. In engineering design, a clear hierarchy is maintained, good encapsulation is provided, and secondary development of the application is facilitated.
[0040] The method of loading the lightweight OpenHarmony application on the Android system is as follows:
[0041] 1. Compile the Aafwk application framework into an independent dynamic library: Compile the aafwk application framework into an independent dynamic library libAceLite.so.
[0042] 2. Abstract AceAbility class: Create the AceAbility class to encapsulate the application Ability-related lifecycle interface provided by the libAceLite.so library.
[0043] 3. Abstract LiteActivity class: Create a LiteActivity class that inherits from the Android system's AppCompatActivity class. Call the Ability-related methods in the AceAbility class in its lifecycle callback method to synchronize the Ability of the OpenHarmony application with the lifecycle of the Android application's Activity.
[0044] 4. Abstract LiteApplication class: Create the LiteApplication class that inherits from the Application class of the Android system, process the hap application file in its onCreate method, and save the application package name and path in class variables so that they can be obtained and passed to the relevant interfaces of libAceLite.so in the onStart method of the AceAbility class.
[0045] 5. Package AndroidAdapter.aar: Package LiteActivity.java, AceAbility.java, and libAceLite.so into the Android resource package AndroidAdapter.aar for direct reference in Android application projects.
[0046] 6. Build the Android application project: Build the Android application project, which directly depends on the AndroidAdapter.aar package. The application project's Application class inherits LiteApplication, while MainActivity inherits LiteActivity, ensuring that the ACELite application can run properly in the Android environment.
[0047] 7. Resource File Processing: After decompressing a hap application developed based on the ACELite framework, the complete file directory is stored as a standard Android application APK resource file in the assets directory of the application project. When the application starts, LiteApplication is responsible for parsing the hap resource file, while LiteActivity is responsible for loading and running it.
[0048] Refer to the attached Figure 3 As shown, the application structure of a typical template project is as follows:
[0049] The Android platform adapter library, AndroidAdapter.aar, is stored in the libs directory within the first-level directory. The compiled and packaged .js and .bc files of the lightweight OpenHarmony application, along with related resources, are stored in the main / assets / hap / directory within the src directory. The Java / com / newland / nliteshell / directory contains the implementation of the application's entry class, which inherits from the LiteApplication class, and the implementation of the application's main Activity class, which inherits from the LiteActivity class.
[0050] Refer to the attached Figure 2 As shown in the figure, the startup loading process of the lightweight OpenHarmony application on the Android system includes the following steps:
[0051] 1) Application launch: When a user clicks an application icon or launches an application through other means, the system starts the application process.
[0052] 2) Application process creation: The system creates an application process and initializes the LiteApplication class in the process; LiteApplication is the entry point of the entire application, and its instance remains a single instance during the application's life cycle.
[0053] 3) LiteApplication initialization: In the onCreate method of LiteApplication, obtain the relevant files of the hap application package in the application resource directory and copy them to the data directory of the application; save the package name of the hap application package and the copied data directory path, and provide getJsBundlePath() and getDataPath() accordingly.
[0054] 4) Start the entry Activity - LiteActivity: The system starts the entry LiteActivity of the application, and then the system begins to call the lifecycle methods of LiteActivity; in the onCreate method of LiteActivity, the SurfaceView object is initialized and the AceAbility is constructed, and then the onStart method of the AceAbility object is called.
[0055] 5) Start AceAbility: AceAbility is responsible for loading libAceAbility.so, obtaining the hap application package name and path by calling the getJsBundlePath() and getDataPath() methods of the LiteApplication class, and finally calling the onStart interface of the libAceAbility.so library to start the Ability of the corresponding hap application.
[0056] This paper abstracts LiteActivity, uses the Android system's Activity component as a runtime container for lightweight HarmonyOS applications, and links their lifecycles, thus implementing a design method for running lightweight HarmonyOS applications on the Android system. This innovation allows the reuse of the host system's native window management services, improving application startup speed and overall performance.
[0057] In the design method of application engineering, the adaptation solution of the Openharmony application framework is encapsulated in an independent ndroidAdapter.aar package at the application layer. This does not require modification of the system firmware, has good adaptability, and is also convenient for secondary development of applications.
[0058] The above descriptions are only some embodiments of the present invention and do not limit the scope of protection of the present invention. Any equivalent device or equivalent process transformation made by using the contents of the description and drawings of the present invention, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for loading a lightweight OpenHarmony application on an Android system, characterized in that: Use the Activity component of a standard Android application as the running container for the OpenHarmony application Ability. After the OpenHarmony application is compiled, it is downloaded to the device as an Android application resource file. The Ability is started through the pre-installed LiteActivity and the application's .js / .bc files are loaded and run. In terms of lifecycle scheduling, the lifecycle scheduling of OpenHarmony applications is implemented based on Android's Activity lifecycle and window management; The loading process is started, including: When the application process is created, the system calls the onCreate method of Application, obtains the relevant files of the hap application package in the application resource directory, copies them to the data directory of the application, saves the package name of the hap application package and the copied data directory path, and provides getJsBundlePath() and getDataPath() respectively; starts the entry Activity, calls the onCreate method of Activity, initializes the SurfaceView object and constructs AceAbility, and calls the onStart method of the AceAbility object; loads the libAceAbility.so library, obtains the Ability-related lifecycle interface, calls the getJsBundlePath() and getDataPath() methods of the LiteApplicaiton class, obtains the hap application package name and path, calls the onStart method of libAceAbility.so, passes in the hap application package name and path, and starts the Ability; The method further comprises: Compile the Aafwk application framework into an independent dynamic library libAceLite.so; Create the AceAbility class to encapsulate the application Ability-related lifecycle interface provided by the libAceLite.so library; Create a LiteActivity class that inherits from the Android system's AppCompatActivity class and call the Ability-related methods in the AceAbility class in its lifecycle callback method; Create a LiteApplication class that inherits from the Android system's Application class, process the hap application file in its onCreate method, and save the application package name and path in class variables; Package LiteActivity.java, AceAbility.java, and libAceLite.so into the Android resource package AndroidAdapter.aar; Build an Android application project that directly depends on the AndroidAdapter.aar package. The Application class of the application project inherits LiteApplication, and MainActivity inherits LiteActivity to ensure that the ACELite application can run normally in the Android environment. After decompressing the hap application developed based on the ACELite framework, the complete file directory is stored as a resource file of the standard Android application apk in the assets directory of the application project; When the application starts, LiteApplication is responsible for parsing the hap resource file, while LiteActivity is responsible for loading and running it.
2. A method for loading a lightweight OpenHarmony application on an Android system according to claim 1, characterized in that: The startup and loading process of the lightweight OpenHarmony application on the Android system includes the following steps: 1) Application launch: When a user clicks an application icon or launches an application through other means, the system starts the application process; 2) Application process creation: The system creates the application process and initializes the LiteApplication class in the process; 3) LiteApplication initialization: In the onCreate method of LiteApplication, obtain the relevant files of the hap application package in the application resource directory and copy them to the data directory of the application; save the package name of the hap application package and the copied data directory path, and provide getJsBundlePath() and getDataPath() respectively; 4) Start the entry point activity - LiteActivity: The system starts the entry point LiteActivity of the application, and then the system begins to call the lifecycle methods of LiteActivity. In the onCreate method of LiteActivity, the SurfaceView object is initialized and the AceAbility is constructed, and then the onStart method of the AceAbility object is called; 5) Start AceAbility: AceAbility is responsible for loading libAceAbility.so, obtaining the hap application package name and path by calling the getJsBundlePath() and getDataPath() methods of the LiteApplication class, and finally calling the onStart interface of the libAceAbility.so library to start the Ability of the corresponding hap application.
3. A method for loading a lightweight OpenHarmony application on an Android system according to claim 2, characterized in that: The LiteApplication described in step 2) is the entry point of the entire application, and its instance remains a single instance during the life cycle of the application.
Citation Information
Patent Citations
Method for supporting installation of swan gap application on Android
CN114610342A
Method for operating Open Harmony application in Android system
CN115220873A