Business function implementation method and device, electronic equipment and storage medium
By binding dynamic programs and native interfaces in the cross-platform dynamic engine and performing data type mapping, the problem of long engine startup time is solved, performance and iteration efficiency are improved, and high-performance requirements of business functions are met.
Patent Information
- Application Number
- CN202310372705.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-10
- Publication Date
- 2024-10-15
AI Technical Summary
The existing cross-platform dynamic engine has a complex structure, which results in a long startup time and cannot meet the high performance requirements of business functions on time limits, especially in scenarios with strict timing requirements such as splash screen delivery.
After the target application is started, the dynamic program is obtained and bound to the target native interface. Based on the preset data type mapping relationship, the parameter type of the dynamic program is mapped to the type of the native interface, and the native interface is directly called to implement business logic. , simplifying the engine structure and improving starting speed.
It realizes the rapid startup of the cross-platform dynamic engine, meets business needs, and significantly improves performance and iteration efficiency, especially in scenarios such as splash screen advertisements.
Smart Images

Figure CN118779019A_ABST
Abstract
Description
Background Art
[0002] In recent years, terminal applications (Application, APP) have developed rapidly. In order to make full use of the business traffic of APP, some additional business functions can usually be integrated into APP. These business functions can be realized by executing corresponding business programs in APP. For example, the above business function can be multimedia resource delivery.
[0003] In the related art, the above-mentioned business program is usually written in a dynamic language. In order to enable the business program to run on different operating systems, a cross-platform dynamic engine is integrated in the APP to execute the business program. The principle of the cross-platform dynamic engine is: based on the native language API (Application Programming Interface) of different operating systems, a new framework interface is built in the engine to eliminate the differences between different operating systems, and the native capabilities of the operating system are exposed to the above-mentioned business program through the new framework interface to realize the execution of the business program.
[0004] Since the structure of the existing cross-platform dynamic engine is relatively complex, after the APP is started, the startup time of the dynamic engine is relatively long; thus, when the implementation of the above-mentioned business functions has relatively high time requirements, the existing cross-platform dynamic engine may not be able to meet the business needs.
[0005] For example, the above-mentioned business function is the splash screen delivery in the multimedia resource delivery. The timing of the splash screen delivery is usually after the APP is started, and the delivery time is very short, generally about 1 second. If the cross-platform dynamic engine starts slowly, it will affect the delivery of multimedia resources. Summary of the invention
[0006] The embodiments of the present application provide a method, device, electronic device and storage medium for implementing business functions, so as to simplify the structure of a cross-platform dynamic engine and improve the startup speed of the cross-platform dynamic engine to meet business needs.
[0007] On the one hand, an embodiment of the present application provides a method for implementing a business function, the method comprising:
[0008] After the target application is started, a dynamic program to be executed is obtained, wherein the dynamic program is used to implement a business function in the target application;
[0009] Acquire a target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in a native program, and the native program is a program embedded in an operating system for providing various underlying interfaces;
[0010] For the at least one target object, the following operations are performed respectively: based on a preset data type mapping relationship, a data type of a target parameter of a target object is mapped to a data type in a target native interface bound to the target object, and the mapped target parameter is passed to the corresponding target native interface;
[0011] At least one target native interface is respectively called to execute corresponding mapped target parameters to realize the business function corresponding to the dynamic program.
[0012] On the one hand, an embodiment of the present application provides a device for implementing a business function, including:
[0013] A program acquisition module, used to acquire a dynamic program to be executed after the target application is started, wherein the dynamic program is used to implement a business function in the target application;
[0014] An interface acquisition module, used to acquire a target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in a native program, and the native program is a program embedded in the operating system for providing various underlying interfaces;
[0015] A mapping module is used to perform the following operations for the at least one target object: based on a preset data type mapping relationship, map the data type of a target parameter of a target object to the data type in the target native interface bound to the target object, and pass the mapped target parameter to the corresponding target native interface;
[0016] The calling module is used to call at least one target native interface to execute the corresponding mapped target parameters to realize the business function corresponding to the dynamic program.
[0017] Optionally, the device further includes a binding module, configured to:
[0018] For the at least one target object, perform the following operations respectively:
[0019] Creating a structure of at least one target method in a target object, obtaining a native object in the native program corresponding to the target object, and obtaining at least one native method in a target native interface implemented by the native object;
[0020] The obtained call information of each native method in the target native interface is respectively stored in a structure of a target method corresponding to the one target object, so as to bind the one target object to the corresponding target native interface.
[0021] Optionally, the device further comprises a creation module, configured to:
[0022] Based on the native program, create a corresponding factory class for at least one target business component;
[0023] For the at least one target business component, the following operations are performed respectively: based on a factory class of a target business component, according to the agreed method selection specification, at least one native method is selected from the native program to create a corresponding target native interface, and a native object corresponding to the target native interface is created.
[0024] Optionally, the interface acquisition module is further used to:
[0025] For the at least one target object, the following operations are performed respectively: from the structure of each target method of a target object, the call information of each native method in the bound target native interface is obtained;
[0026] Then the calling module is also used for:
[0027] For the at least one target native interface, the following operations are performed respectively: based on the calling information of each native method in a target native interface, each native method is called to execute the corresponding mapped target parameters.
[0028] Optionally, the device further includes a relationship acquisition module, configured to obtain a preset data type mapping relationship in the following manner:
[0029] For each data type corresponding to the at least one target object in the dynamic program, an intermediate data type corresponding to each data type is created to obtain a first mapping relationship; wherein the intermediate data type belongs to a data type in the native program;
[0030] Convert each data type corresponding to the at least one target native interface into a corresponding intermediate data type to obtain a second mapping relationship;
[0031] The data type mapping relationship is obtained based on the first mapping relationship and the second mapping relationship.
[0032] Optionally, the mapping module is further used for:
[0033] Mapping the data type of the target parameter of the one target object to a corresponding intermediate data type based on the first mapping relationship through the first mapping interface of the dynamic program;
[0034] Through the second mapping interface of the native program, based on the second mapping relationship, the corresponding intermediate data type is mapped to the data type in the target native interface bound to the one target object.
[0035] Optionally, the device further includes a memory management module, configured to:
[0036] For the target parameter of the at least one target object, the following operations are performed respectively:
[0037] After mapping the data type of a target parameter of a target object to a corresponding intermediate data type, the memory management of the mapped target parameter is bound to the memory management of the target parameter before mapping; wherein the memory management binding means: when applying for the memory of the mapped target parameter, the memory of the target parameter before mapping is applied, and when releasing the memory of the mapped target parameter, the memory of the target parameter before mapping is released.
[0038] Optionally, the device further comprises:
[0039] A storage module, used for storing the target parameters before mapping of the applied memory into a weak reference set;
[0040] The release module is used to implement the business function corresponding to the dynamic program, and traverse the weak reference set in the process of releasing memory, and release the target parameters before mapping of the unreleased memory.
[0041] Optionally, the device further comprises a return module, configured to:
[0042] For the at least one target native interface, perform the following operations respectively:
[0043] Get the execution result of a target native interface;
[0044] Based on the preset data type mapping relationship, mapping the data type of the execution result to a data type corresponding to the target object bound to the one target native interface;
[0045] The mapped execution result is returned to the target object bound to the one target native interface.
[0046] An electronic device provided in an embodiment of the present application includes a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the above-mentioned business function implementation methods.
[0047] An embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is executed on an electronic device, the computer program is used to enable the electronic device to execute the steps of any one of the above-mentioned service function implementation methods.
[0048] An embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device performs the steps of any one of the above-mentioned business function implementation methods.
[0049] The embodiment of the present application adopts the above technical solution, which has at least the following technical effects:
[0050] After the target application is started, in the process of executing the dynamic program through the cross-platform dynamic engine, the embodiment of the present application calls the target object in the dynamic program and calls the target native interface bound to the target object to execute the corresponding business logic through the target native interface. At the same time, in order to pass the target parameter of the target object to the target native interface, the data type of the target parameter of the target object is mapped to the data type in the target native interface based on the preset data mapping relationship. In this way, the business logic of the dynamic program is realized through the native capability of the native program, which can simplify the structure of the cross-platform dynamic engine and improve its startup speed to meet business needs.
[0051] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0053] Figure 1 A schematic diagram of an application scenario of a method for implementing a business function in an embodiment of the present application;
[0054] Figure 2 This is a schematic diagram of the structure of a cross-platform dynamic engine in an embodiment of the present application;
[0055] Figure 3 A schematic diagram of binding a JS object to an iOS native method in an embodiment of the present application;
[0056] Figure 4 A schematic diagram of creating a native object of a target native interface bound to a JS object in an embodiment of the present application;
[0057] Figure 5 A schematic diagram of the process of binding a native method to a JS object and a JS interpreter calling a native method in an embodiment of the present application;
[0058] Figure 6 A schematic diagram of the classification of data types of the JS interpreter Quickjs in an embodiment of the present application;
[0059] Figure 7 A schematic diagram of mapping the data type of a JS object and the data type of the native level in an embodiment of the present application;
[0060] Figure 8 This is a schematic diagram of the structure of the native framework layer in an embodiment of the present application;
[0061] Fig. 9 A schematic diagram of a factory class created for each type of component by the native framework layer in an embodiment of the present application;
[0062] Fig.10 It is a schematic diagram of the implementation process of the view component base class and the frame layout view component in the embodiment of the present application;
[0063] Fig.11 A flowchart of a method for implementing a business function in an embodiment of the present application;
[0064] Fig.12 This is a schematic diagram of memory management binding in an embodiment of the present application;
[0065] Fig.13 A schematic diagram of memory release in an embodiment of the present application;
[0066] Fig.14 This is a schematic diagram of the structure of another cross-platform dynamic engine in an embodiment of the present application;
[0067] Fig.15A A schematic diagram of binding a target object and a target native interface in an embodiment of the present application;
[0068] Fig. 15B A schematic diagram of a specific scenario of a method for implementing a business function in an embodiment of the present application;
[0069] Fig.16 A schematic diagram comparing a native solution and a dynamic solution in an embodiment of the present application;
[0070] Fig.17 A structural block diagram of a device for implementing a business function in an embodiment of the present application;
[0071] Fig.18 It is a schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0072] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the technical solution of the present application, rather than all of the embodiments. Based on the embodiments recorded in the application documents, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solution of the present application.
[0073] The following is an introduction to some concepts involved in the embodiments of the present application.
[0074] Target application: An application (Application, APP) installed on a terminal device, which is a software resource in the terminal device and a computer program that can complete one or more services. It generally has a visual display interface and can interact with users, such as social software, browser software, information software, video software, shopping software, music software, etc.
[0075] Dynamic program: A program written in a dynamic language. A dynamic language is an interpreted language, such as Python, vbscript, javascript, installshield script, ActionScript, etc. It is not like languages such as C\C++ that can be compiled into binary code and exist in the form of executable files. Dynamic languages do not need to be compiled and can be used directly. The interpreter is responsible for the interpretation.
[0076] JS object: It is the encapsulation of JS code, which can encapsulate methods (functions), so that the calling methods can be managed systematically. The method is the encapsulation of the JS operation process. When operating the same process, you only need to call the corresponding method.
[0077] Native program: A program written in the native language of the terminal device's operating system. For example, the native language of the iOS operating system is OC, and the native language of the Android operating system is JAVA.
[0078] The word “exemplary” is used hereinafter to mean “serving as an example, example, or illustration.” Any embodiment described as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0079] The terms "first" and "second" in this document are used for descriptive purposes only and should not be understood as explicitly or implicitly indicating relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first" and "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0080] In the related art, the above-mentioned business program is usually written in a dynamic language. In order to enable the business program to run on different operating systems, a cross-platform dynamic engine is integrated in the APP to execute the business program. Since the structure of the existing cross-platform dynamic engine is relatively complex, after starting the APP, the startup time of the dynamic engine is relatively long; thus, when the implementation of the above-mentioned business functions has a relatively high time limit requirement, the existing cross-platform dynamic engine may not be able to meet the business needs.
[0081] In view of this, the embodiments of the present application provide a method, device, electronic device and storage medium for realizing business functions. In the process of executing a dynamic program through a cross-platform dynamic engine, by calling the target object in the dynamic program, the target native interface bound to the target object is called to execute the corresponding business logic through the target native interface. At the same time, in order to pass the target parameters of the target object to the target native interface, the data type of the target parameter of the target object is mapped to the data type in the target native interface based on a preset data mapping relationship. In this way, the business logic of the dynamic program is realized through the native capabilities of the native program, which can simplify the structure of the dynamic engine and improve its startup speed to meet business needs.
[0082] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application. In addition, the embodiments and features in the embodiments of the present application may be combined with each other if there is no conflict.
[0083] like Figure 1 As shown, it is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario diagram includes two terminal devices 110 and a server 120.
[0084] In the embodiment of the present application, the terminal device 110 includes but is not limited to mobile phones, tablet computers, laptop computers, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals and other devices; the terminal device may be installed with a target application, which may be any software, and the server 120 may be a background server corresponding to the target application, or a server specifically used to store relevant data, which is not specifically limited in the present application. The server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0085] In an optional implementation, the terminal device 110 and the server 120 may communicate with each other via a communication network, which may be a wired network or a wireless network.
[0086] In the embodiment of the present application, the terminal device 110 can implement additional business functions in the target application, and the business functions can be implemented by a dynamic program. When the target application is started for the first time, the dynamic program can be obtained from the server 120. In the process of executing the dynamic program, the terminal device 110 calls the target native interface bound to each target object in the dynamic program, and at the same time, based on the preset data type mapping relationship, maps the data type of the target parameter of each target object to the data type in the target native interface bound to the target object, and passes the mapped target parameter to the corresponding target native interface; thereby calling each target native interface to execute the corresponding mapped target parameter to implement the business function corresponding to the dynamic program.
[0087] In some application scenarios, the above-mentioned business function may be to display splash screen ads. In this case, the logic of each target object in the above-mentioned dynamic program may be to display pictures, texts, etc., and page rendering may be achieved by calling the target native interface bound to each target object. At the same time, the target parameters in each target object (such as picture address, text content, etc.) may be converted into the data type of the corresponding target native interface and passed to the corresponding target native interface to achieve the display of splash screen ads.
[0088] It should be noted that the above-mentioned business functions may also be other functions, such as displaying advertisements other than splash screen advertisements, and there is no limitation to this. Figure 1 The figure is only an example. In fact, the number of terminal devices and servers is not limited and is not specifically limited in the embodiments of the present application.
[0089] The following describes the business function implementation method provided by the exemplary embodiment of the present application in combination with the application scenario described above and with reference to the accompanying drawings. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0090] The business function implementation method of the embodiment of the present application can be executed by a terminal device, and a target application is installed on the terminal device. The target application integrates a cross-platform dynamic engine that can run on different operating systems. The terminal device can execute the business function implementation method through the cross-platform dynamic engine.
[0091] Before introducing the method for implementing the business functions of the embodiment of the present application, the cross-platform dynamic engine of the embodiment of the present application is first introduced.
[0092] The cross-platform dynamic engine of the embodiment of the present application integrates an interpreter, which is used to execute dynamic programs. It can increase the dynamic capabilities of the native programs of the terminal devices, and by smoothing the interface differences of the native programs (written in OC language or JAVA language), the native interfaces are opened up to the dynamic programs, and the logic of the dynamic programs is executed through the native interfaces, thereby making the performance of the cross-platform dynamic engine as close to the native as possible.
[0093] The cross-platform dynamic engine adopts the idea of layered design. Each layer has an independent interface and can provide services to the outside world separately, thereby achieving decoupling between layers and improving reusability and maintainability. In the following embodiments of this application, the dynamic program is written in JavaScript (hereinafter referred to as JS) as an example. Figure 2 As shown, the overall architecture of the cross-platform dynamic engine can be divided into the following three layers: JS interpreter, engine layer and native framework layer.
[0094] Among them, the JS interpreter is used to interpret and execute dynamic programs written in JavaScript in the upper layer; the engine layer is used to integrate the JS interpreter to provide friendly JS interaction capability support for the native framework layer; the native framework layer is used to build a native framework based on the business related to the dynamic program. At this layer, the interface differences of different native programs are smoothed out, and the native capabilities of the operating system are opened up to JS.
[0095] Optionally, in order to simplify the structure of the cross-platform dynamic engine to increase its startup speed and reduce its package size, a simple interpreter can be selected. Taking the JS interpreter as an example, as shown in Table 1, Quickjs is significantly better than other JS interpreters in terms of initialization speed and package size. Therefore, Quickjs can be selected as the JS interpreter. The interpreter of the embodiment of the present application can be selected as needed, and the following embodiment is described by taking the interpreter as Quickjs as an example.
[0096] Table 1
[0097]
[0098] The high performance and small size of Quickjs determine that it only supports the most basic JS calls and executions, and does not encapsulate other functions. For example, other functions include page rendering, animation display, sensor functions, etc. These other functions need to be implemented through native programs.
[0099] The embodiment of the present application takes into account that the dynamic program is not convenient to be directly called by the native program of the terminal device. Therefore, the JS object in the dynamic program is bound to the native interface in the native program through the engine layer, so that the JS object is called to the native method in the native interface through the JS interpreter.
[0100] For example, Figure 3 As shown, the native program of the iOS operating system contains a UILabel class for creating text component labels. The UILabel class includes multiple methods for setting text, such as setText, setFont, setTEXTColor, etc. The interface method of the UILabel object in the native program can be bound to the JS Label object through the engine layer, so that when JS calls the method with the same name, it calls the native method of the native program. This process can be understood as the binding process of the JS object and the native interface in the native program.
[0101] The following describes the binding process between JS objects and native interfaces in native programs.
[0102] The binding process between the JS object and the native interface in the native program includes two parts: determining the binding source and determining the binding scheme.
[0103] (1) Determine the binding source
[0104] In order to minimize the impact on the performance of the cross-platform dynamic engine, the embodiment of the present application can select the required native methods from the native program for binding, thereby further improving the startup speed of the cross-platform dynamic engine and reducing memory usage.
[0105] For example, taking the iOS operating system as an example, the UILabel class of iOS contains many native methods, such as setText, setFont, setTEXTColor, alloc, dealloc, copy and other methods. If the dynamic program needs to call native methods related to the user interface (UI), you can select the required UI method to bind to the JS object. For example, the UI method includes the above-mentioned setText, setFont, setTEXTColor and other methods, and other native methods of iOS can be left unbound.
[0106] Each class in the native program of the operating system needs to bind different native methods. In order to customize the method binding source through the above-mentioned native framework layer, the idea of interface-oriented programming can be used to select the native methods in the external interface designed by the native framework layer for binding; in addition to following the custom interface protocol, the native program also follows the interface protocol open to the outside world by the operating system. The embodiment of the present application can agree on the prefix name of the native interface to be bound, such as QJSBridge, and obtain the native method in the agreed native interface as the binding source.
[0107] (2) Determine the binding scheme
[0108] After determining the binding source, you can further determine the scheme for binding the native method to the JS object. The binding scheme is introduced below.
[0109] The binding scheme of the embodiment of the present application is based on the following design ideas:
[0110] First, corresponding to the JS object, the calling process of the native method is also encapsulated into an object.
[0111] For example, in the calling process of the native method of the iOS operating system, the native method signature is obtained based on the native method name, and then the object instance is obtained based on the native method signature.
[0112] Secondly, bind the calling process of the encapsulated native method to the JS object.
[0113] Finally, when executing the dynamic program, the bound native method is called by calling the JS object.
[0114] Based on the above design concept, the binding scheme of the embodiment of the present application may include the following two parts: binding the native method of the target native interface to the JS object, and calling the native method bound to the JS object. The binding scheme is exemplarily introduced below with reference to a specific example.
[0115] For example, taking the binding of the native method of the UILabel class of the iOS operating system to a JS object as an example, before binding, a target native interface is created through the native framework layer, and the native method to be bound is defined as the binding source. For example, the name of the target native interface is prefixed with QJSBridge, such as Figure 4 As shown, create a Label class to implement the QJSBridgeLabel interface, and then create an object LabelA of the Label class.
[0116] like Figure 5 As shown, on the one hand, the process of binding the native method of the target native interface to the JS object includes the following steps A1-A3:
[0117] A1. Traverse all QJSBridge prefix interfaces implemented by LabelA object, generate an interface list, obtain all native methods defined in the interface list, and generate a native method list;
[0118] A2. traverse the native method list obtained above, and generate an object of a native method calling process (for example, named Innovation class) for each native method;
[0119] A3. Create a JSFunction (which can be understood as a JS function) structure of a JS object through the JS interpreter, and use the interface provided by the JS interpreter to store the object of the Innovation class in the JSFunction structure as opaque data.
[0120] On the other hand, calling the native method of the target native interface bound to the JS object through the JS interpreter includes the following steps B1-B2:
[0121] B1. Call the JS object corresponding to the JSFunction structure through the JS interpreter;
[0122] B2. According to the calling rules of the JS interpreter, all the information of the JSFunction structure can be obtained, and the opaque data Innovation object can be taken out from the JSFunction structure;
[0123] B3. Utilize the native method calling process encapsulated by the Innovation object (including calling information and operating system mechanisms) to finally implement the calling of the native method of the LabelA object.
[0124] For example, put the call information of setText into the JSFunction object, JS can access the JSFunction object, and then when JS accesses JSFunction, it takes out the call information of setText and calls the setText method through this call information.
[0125] In an embodiment of the present application, the specific implementation of the above-mentioned binding scheme is encapsulated inside the engine layer, and a convenient binding calling interface is provided to the outside. Ultimately, on the basis of minimizing performance consumption, it is achieved that the native program only needs to define the target native interface according to the agreed rules, and the native method in the agreed target native interface can be bound to the JS object through the engine layer, so that the JS interpreter can conveniently call the native method in the target native interface when calling the JS object.
[0126] In the above embodiments of the present application, the calling of native methods by the JS interpreter is solved through the binding scheme of JS objects and native methods. However, the parameters and return values of the native methods in the calling process cannot be conveniently and directly passed between the JS interpreter and the native program. Therefore, the embodiments of the present application introduce a data type mapping process to realize the mutual conversion between the data type of the JS object and the data type of the native program, so as to solve the problem that the data types of the native program and the dynamic program are not interoperable.
[0127] The data type mapping process in the following embodiment is exemplarily introduced.
[0128] For example, Figure 6 As shown, taking Quickjs as the JS interpreter as an example, the present application embodiment analyzes the source code of Quickjs and obtains three main characteristics of the Quickjs data type:
[0129] 1. All data types of Quickjs belong to JSValue, including basic data types and object data types.
[0130] For example, basic data types include JS_TAG_INT, JS_TAG_BOOL, JS_TAG_FLOAT64, etc., and object data types include JS_TAG_STRING, JS_TAG_OBJECT, etc.
[0131] 2. The operation interface supported by basic data types includes variable creation and value retrieval.
[0132] 3. The object data type provides a personalized operation interface for creating and using different objects. For example, the personalized operation interface supported by JSObject includes setting object properties or getting object properties.
[0133] The purpose of the engine layer in the embodiment of the present application is to provide convenient JS interaction capabilities for native programs, so the engine layer needs to serve the native framework layer. First, the usage requirements of the native framework layer in data type mapping are analyzed, which mainly include the following two points:
[0134] 1) When the native framework layer operates on the data of the JS object, it needs to use the personalized operation capability of JSValue. At this time, it is necessary to map the data type of the JS object to the data type of the native program, such as obtaining the Value in the JS Map (key-value pair collection) variable.
[0135] 2) When the native framework layer calls the JS object, the data type of the native program needs to be converted into the data type of the JS object.
[0136] Based on this, the data type mapping scheme includes the following two cases:
[0137] In the first case, the data type of the JS object is mapped to the data type of the native program. The calling details of the JS object can be shielded from the native framework layer by friendly encapsulation of the JSValue interface.
[0138] For example, the JS interpreter creates a text component by calling the target native interface bound to the JS object. At this time, the target parameter of the text content needs to be passed in. When the JS interpreter passes the target parameter to the target native interface, it passes the data type of the JS object. Finally, when the target native interface is used, it is necessary to map the target parameter to the data type of the native program through the mapping interface of the native program.
[0139] In the second case, the data type of the native program is mapped to the data type of the JS object: a simple and convenient data type mapping interface is provided for the native framework layer.
[0140] For example, taking the example of calling the target native interface to create a text component, after the target native interface creates the text component, it is necessary to return the text component to the JS interpreter. This requires mapping the data type of the text component of the native program to the data type of the JS object to pass it to the JS interpreter for calling.
[0141] The following is an exemplary introduction to the data type mapping process in the embodiment of the present application.
[0142] like Figure 7 As shown, the data type mapping process is as follows:
[0143] First, the JS object is converted to JSValue, which is the data type of the JS object, through the JS interpreter.
[0144] In the embodiment of the present application, in order to shield the JS object call of the JS interpreter from the native framework layer, an intermediate data type is introduced, such as Figure 7 The middle-layer QJSValue class in JSValue is created, and subclasses corresponding to all data types of JSValue are created. For example, for the JSValue data type JS_TAG_STRING, the subclass created is QJString in the QJSValue class, thereby realizing friendly encapsulation of the operation interface of the JSValue data type.
[0145] The conversion from JSValue to the middle-layer QJSValue class can be implemented using the mapping interface provided by the JS interpreter Quickjs. For the mapping of the data type of the native program to the middle-layer QJSValue class, the embodiment of the present application designs a more friendly encapsulation, designs the Adapter module to perform the mapping work, and further designs the AdapterCreater module to generate the corresponding Adapter according to the data type of the native program, so as to realize the mapping of the data type of the native program to the middle-layer QJSValue class.
[0146] The above-mentioned data type mapping scheme of the embodiment of the present application is transparent to the caller (native framework layer). The native framework layer can call the AdapterCreater interface and pass in the data type of the native program to realize the mapping of the data type with the intermediate class QJSValue, and then map the data type of the native program to JSValue based on the mapping relationship between the intermediate class QJSValue and JSValue.
[0147] The following uses the advertising business as an example of the business function implemented by the dynamic program to introduce the native framework layer of the cross-platform dynamic engine of the embodiment of the present application.
[0148] Based on the engine layer, the embodiment of the present application designs a native framework layer, builds a native framework for the advertising business, smoothes the interface differences of different operating systems with minimal performance cost, and realizes the connection from native programs to dynamic programs (JS is taken as an example below).
[0149] For example, Figure 8 As shown in the figure, the overall architecture of the native framework layer includes the following modules:
[0150] 1) Context module: implements the integration of the engine layer, provides JS interaction capabilities for the native framework layer, and is responsible for passing parameters to the engine layer and receiving execution message callbacks from the engine layer;
[0151] 2) Advertising basic capability module: This is the core of the entire native framework layer. Different operating systems are designed with unified and concise interface protocols, and the native capabilities are connected to JS using the engine layer integrated with Context.
[0152] 3) Engine module: The external interface of the native framework layer supports interaction with the advertising traffic APP (Application), including receiving the APP's personalized capabilities (such as black and white image color, etc.) and receiving advertising data, as well as calling back JS code execution status and messages to the APP. This module is also responsible for the integration of the Context module.
[0153] The following is an exemplary introduction to the above-mentioned advertising basic capability module.
[0154] In the embodiment of the present application, a simple factory pattern can be used to design the various components of the advertising basic capability module. Here, the basic view component is taken as an example for introduction. The design principles of other animation components and sensor components are similar to those of the view component.
[0155] like Fig. 9 As shown, the native framework layer creates a factory class for each type of component, such as QJSBrideComponentFactory, which is used to produce components and register custom components. Components are created by the factory when they are used, rather than creating all components when the cross-platform dynamic engine is initialized, which reduces memory usage. Both the factory and the component follow the method binding specification of the engine layer, select the necessary native method declarations to bind to the target native interface of the JS object (such as the QJSBridge prefix interface), such as Fig. 9 The base component BaseComponent in the QJSBridgeBaseComponent interface corresponds to the base component BaseComponent. The base component BaseComponent includes various types of components, such as frame container component FrameContainer, linear container component LinearContainer, text component TextComponent, picture component ImageComponent, video component VideoComponent, etc. Each component corresponds to a QJSBridge prefix interface. By binding the target native interface to the JS object, the JS interpreter obtains the view component (such as text, picture, etc.) by calling the target native interface bound to the JS object, thereby using the native capabilities of the terminal device to perform component UI rendering.
[0156] For example, Fig.10As shown in the figure, the implementation of the base class component of the view component and the frame layout container component is shown. The specific implementation method is to define the QJSBridge prefix interface, and each operating system creates a class to follow the interface protocol, and calls the native capabilities of the terminal device to implement the native methods defined in the QJSBridge prefix interface, thereby realizing the native capabilities of the frame layout container component being connected to JS.
[0157] In addition, the advertising basic capability module of the embodiment of the present application can conveniently receive advertising traffic APP or external customized personalized components by registering custom components, thereby realizing flexible expansion of component capabilities.
[0158] It should be noted that the embodiment of the present application takes the implementation of advertising business by dynamic program as an example to exemplify the native framework layer. It can be understood that the native framework layer can be designed according to different business functions, and the business functions are not limited to advertising business.
[0159] After introducing the above-mentioned cross-platform dynamic engine of the embodiment of the present application, the business function implementation method based on the cross-platform dynamic engine of the embodiment of the present application is introduced below.
[0160] See also Fig.11 As shown, it is an implementation flow chart of a method for realizing a business function provided by an embodiment of the present application. Taking a terminal device as an execution subject as an example, the terminal device can execute the method through a cross-platform dynamic engine integrated in a target application. The specific implementation process is as follows:
[0161] Step S1101, after the target application is started, a dynamic program to be executed is obtained, where the dynamic program is used to implement business functions in the target application.
[0162] The target application can be any software. The dynamic program is written in a dynamic language, such as javascript. When the target application is started for the first time, the dynamic program to be executed can be obtained from the server and saved. When the target application is started again later, the saved dynamic program can be directly obtained. The business functions implemented by the dynamic program can be designed as needed, for example, it can be a splash screen advertisement, which is usually displayed after the target application is started.
[0163] Step S1102, obtaining a target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in a native program, and the native program is a program embedded in the operating system for providing various underlying interfaces.
[0164] Among them, the dynamic program can be executed through the interpreter in the cross-platform dynamic engine. For example, when the dynamic program is written in javascript, the dynamic program can be executed through the JS interpreter. Optionally, in order to reduce the package size of the JS interpreter as much as possible, the JS interpreter can use Quickjs, so that the startup speed of the cross-platform dynamic engine can be further improved.
[0165] In the process of executing the dynamic program through the interpreter, when a target object is called, the target native interface bound to the target object can be obtained. For example, when the dynamic program is JS, the target object can be the JS object in the above embodiment, and the target native interface can be the QJSBridge prefix interface, through which the logic of the target object of the dynamic program can be implemented.
[0166] In some embodiments, before executing step S1102, each target object in the dynamic program may be bound to a corresponding target native interface, which may specifically include the following steps C1-C2:
[0167] C1. Create a structure of at least one target method in a target object, obtain a native object in a native program corresponding to a target object, and obtain at least one native method in a target native interface implemented by the native object.
[0168] The target object encapsulates at least one target method, which can be understood as a function. The interpreter can create structures of each target method. For example, taking the target object as a JS object, a JSFunction structure of the JS object is created.
[0169] Each target object has a corresponding native object in the native program, and the native object can be created by the native framework layer of the cross-platform dynamic engine to implement the target native interface. In the embodiment of the present application, by obtaining the native object corresponding to the target object, the target native interface implemented by the native object can be obtained, and each native method in the target native interface can be obtained.
[0170] C2. The obtained call information of each native method in the target native interface is stored in a structure of a corresponding target method of a target object, so as to bind a target object to the corresponding target native interface.
[0171] Among them, the target method of the target object corresponds one-to-one to the native method in the target native interface. For example, the target method of the target object Lable includes setText, setFont, and setTextColor, and the native methods in the bound target native interface UILabel also include setText, setFont, and setTextColor. The calling information of each native method is stored in the structure of the corresponding target method; for example, the calling information of the native method setText is stored in the structure of the target method setText.
[0172] In an embodiment of the present application, by binding the native method of the target native interface to the target object in the dynamic program, the dynamic program can easily call the target native interface to implement corresponding business logic, such as creating text, displaying pictures, etc.
[0173] In some embodiments, when obtaining the target native interface bound to at least one target object in the dynamic program in the above step S1102, the following operations are performed for at least one target object: from the structure of each target method of a target object, the calling information of each native method in the bound target native interface is obtained.
[0174] For each target method of the target object, the calling information of the corresponding native method stored in the structure of the target method is obtained; for example, the calling information of the native method setText is obtained from the structure of the target method setText.
[0175] In some embodiments, the above target native interface and the corresponding native object can be created by following the steps D1-D2:
[0176] D1. Create corresponding factory classes for at least one target business component based on the native program.
[0177] Among them, at least one target business component can be generated by the native framework layer in the above embodiment. For example, the target business component can be a view component, an animation component, etc. The view component can include text, pictures, etc., and the animation component can include attribute animation, frame animation, animation group, etc. A factory class is created for each target business component based on the native program through the native framework layer to produce components and register custom components. The components are produced and created by the factory when they are used, instead of creating all components when the cross-platform dynamic engine is initialized, so as to reduce memory usage.
[0178] D2. For at least one target business component, perform the following operations respectively: Based on a factory class of a target business component, select at least one native method from the native program according to the agreed method selection specification to create a corresponding target native interface, and create a native object corresponding to the target native interface.
[0179] The agreed method selection specification may be: selecting the necessary native method declarations to bind to the target native interface of the target object (e.g., the QJSBridge prefix interface in the above embodiment), and creating the target native interface corresponding to the corresponding target business component based on the factory class. For example, the target business component is Fig. 9 For the text component TextComponent in the code, the corresponding target native interface can be the QJSBridgeTextComponent interface.
[0180] Step S1103, for at least one target object, perform the following operations respectively: based on a preset data type mapping relationship, map the data type of a target parameter of a target object to the data type in a target native interface bound to the target object, and pass the mapped target parameter to the corresponding target native interface.
[0181] In the embodiment of the present application, in order to enable the parameters and return values of the method in the calling process to be conveniently and directly passed between the dynamic program and the native program, a preset data type mapping relationship is used to realize the mutual conversion between the data type of the dynamic program and the data type of the native program, thereby solving the problem that the data types of the native program and the dynamic program are not interoperable.
[0182] In some embodiments, the preset data type mapping relationship can be obtained by executing the following steps E1-E2:
[0183] E1. For each data type corresponding to at least one target object in the dynamic program, create an intermediate data type corresponding to each data type to obtain a first mapping relationship; wherein the intermediate data type belongs to a data type in the native program.
[0184] Among them, taking the target object as a JS object and its corresponding data type as the JSValue in the above embodiment as an example, an intermediate data type such as the QJSValue class in the above embodiment is created, and the QJSValue class creates subclasses corresponding to all data types of JSValue. For example, for the data type JS_TAG_STRING of JSValue, the created subclass is QJString in the QJSValue class.
[0185] E2. Convert each data type corresponding to at least one target native interface into a corresponding intermediate data type to obtain a second mapping relationship.
[0186] In an embodiment of the present application, for the mapping of the data type of the native program to the intermediate data type, an Adapter module can be designed to perform the mapping work, and an AdapterCreater module can be further designed to generate a corresponding Adapter according to the data type of the native program to realize the mapping of the data type of the native program to the intermediate data type.
[0187] E3. Obtain a data type mapping relationship based on the first mapping relationship and the second mapping relationship.
[0188] In the embodiment of the present application, in order to shield the target object call of the dynamic program from the native program, an intermediate data type is introduced, thereby achieving friendly encapsulation of the data type of the dynamic program.
[0189] In some embodiments, in the above step S1103, based on a preset data type mapping relationship, mapping the data type of a target parameter of a target object to the data type in a target native interface bound to the target object may include the following steps F1-F2:
[0190] F1. Mapping a data type of a target parameter of a target object to a corresponding intermediate data type based on a first mapping relationship through a first mapping interface of a dynamic program.
[0191] Among them, the first mapping interface can be provided by the interpreter of the dynamic program. For example, the data type of the target parameter of the target object is JSValue, and the intermediate data type is QJSValue. The conversion from JSValue to the intermediate layer QJSValue class can be implemented using the mapping interface provided by the JS interpreter.
[0192] F2. Map the corresponding intermediate data type to a data type in a target native interface bound to a target object based on a second mapping relationship through a second mapping interface of the native program.
[0193] The mapping of the data type of the native program to the intermediate data type can be implemented through the second mapping interface in the native program. For example, the above-mentioned Adapter is used as the second mapping interface to perform the mapping work, and through AdapterCreater, the corresponding Adapter is generated according to the data type of the native program to realize the mapping of the data type of the native program to the intermediate data type.
[0194] Step S1104, respectively calling at least one target native interface to execute the corresponding mapped target parameters to implement the business functions corresponding to the dynamic program.
[0195] For example, suppose the logic of a target object in a dynamic program is to display a picture, but the target object does not have a method to display pictures. The picture display is achieved by calling the target native interface bound to the target object. When calling the target native interface to display the picture, the mapped target parameter Image url (picture address) needs to be passed in so that the target native interface calls this image url to render the picture.
[0196] For example, the logic of another target object in the dynamic program is to create a text component. The target native interface bound to the target object needs to be called to create the text component. At this time, the mapped target parameters (such as text content, text color, etc.) need to be passed to the target native interface so that the target native interface calls this target parameter to create the text component.
[0197] In some embodiments, when at least one target native interface is called respectively in the above step S1104 to execute the corresponding mapped target parameters, the following operations can be performed for at least one target native interface: based on the calling information of each native method in a target native interface, each native method is called to execute the corresponding mapped target parameters.
[0198] For example, the native methods in the target native interface include setText, setTextColor, etc. By calling these native methods, functions such as creating text content and setting text color can be realized. The mapped target parameters are text content, text color, etc.
[0199] In the embodiment of the present application, the target native interface is called by binding the native interface of the native program to the object in the dynamic program. At the same time, the data type of the dynamic program is mapped with the data type of the terminal native program to realize the transmission of the target parameter. In this way, the logic of the dynamic program is executed through the native program, which can simplify the structure of the dynamic engine and improve its startup speed to meet business needs.
[0200] In some embodiments, after at least one target native interface is respectively called to execute the corresponding mapped target parameters in the above step S1104, the following steps G1-G3 may be respectively performed for at least one target native interface:
[0201] G1. Get the execution result of a target native interface.
[0202] For example, when the target native interface is used to create a text component, the created text component can be used as the execution result; when the target native interface is used to display a picture, the displayed picture can be used as the execution result.
[0203] G2. Based on a preset data type mapping relationship, the data type of the execution result is mapped to a data type corresponding to a target object bound to a target native interface.
[0204] Among them, similar to the above steps F1-F2, through the second mapping interface of the native program, based on the above second mapping relationship, the data type of the execution result is mapped to the corresponding intermediate data type; through the first mapping interface of the dynamic program, based on the above first mapping relationship, the corresponding intermediate data type is mapped to the data type in the target object bound to the target native interface.
[0205] G3. Return the mapped execution result to a target object bound to a target native interface.
[0206] For example, taking calling the target native interface to create a text component as an example, after the target native interface creates the text component, it is necessary to return the text component to the target object bound to the target native interface. This requires mapping the data type of the text component of the native program to the data type of the target object so that the target object can make the call.
[0207] In some embodiments, considering that the target parameters of the dynamic program may not be able to achieve automatic memory management, improper memory application or release may easily cause memory leaks or wild pointers, causing the target application to crash. In order to ensure stability, the embodiment of the present application designs a memory management solution to achieve automatic and centralized management of the target parameters of the target objects in the dynamic program, while shielding the memory management details of the target parameters from the native program.
[0208] Optionally, for the target parameters of each target object in the dynamic program, perform the following operations respectively:
[0209] After mapping the data type of a target parameter of a target object to a corresponding intermediate data type, the memory management of the mapped target parameter is bound to the memory management of the target parameter before mapping; wherein the memory management binding means: when applying for the memory of the mapped target parameter, the memory of the target parameter before mapping is applied, and when releasing the memory of the mapped target parameter, the memory of the target parameter before mapping is released.
[0210] In the embodiment of the present application, considering that the terminal native language (OC / JAVA) can automatically manage memory, this feature is utilized to introduce an intermediate data type (such as QJSValue in the above embodiment) in the data type mapping process, and bind the memory management of the target parameter before mapping (such as JSValue type) and the target parameter mapped to the intermediate data type. Since the target parameter of the intermediate data type can automatically perform memory management, the automatic creation and release of the memory of the target parameter before mapping can be achieved.
[0211] For example, Fig.12 As shown, taking the intermediate data type as QJSValue in the above embodiment and the data type before mapping as JSValue in the above embodiment as an example, QJSValue is a native language type. When QJSValue is created and memory is requested, the corresponding JSValue is created and memory is requested. When QJSValue is released, the memory of JSValue is released.
[0212] In some embodiments, after implementing the business functions corresponding to the dynamic program, the cross-platform dynamic engine can be destroyed. When the engine is destroyed, the corresponding target parameters of the intermediate data types (such as QJSValue in the above embodiment) may not all be automatically recovered. However, the interpreter may be destroyed only after the memory of all target parameters is released. Therefore, it is necessary to ensure that when the engine is destroyed, the memory corresponding to the target parameters of the target object (i.e., the target parameters before mapping) is released in a centralized manner.
[0213] In order to solve this problem, the embodiment of the present application introduces a weak reference collection (Map) to store the pre-mapped target parameters (such as JSValue in the above embodiment) of the applied memory without affecting the normal release of the target parameters of the intermediate data type, so that when the engine is destroyed, the pre-mapped target parameters that have not been destroyed along with the target parameters of the intermediate data type are released.
[0214] Optionally, after mapping the data type of the target parameter of the target object to the corresponding intermediate data type, the following operations may be performed:
[0215] The target parameters before mapping of the applied memory are stored in the weak reference collection. After the business functions corresponding to the dynamic program are realized, the weak reference collection is traversed during the memory release process to release the target parameters before mapping of the unreleased memory.
[0216] For example, Fig.13 As shown, taking the target parameter of the intermediate data type as the QJSValue in the above embodiment, and the target parameter before mapping as the JSValue in the above embodiment as an example, when storing the JSValue, the JSValue is stored in a weak reference Map, and when the engine is destroyed, the weak reference Map is traversed, and the JSValue whose memory is not released is released, so that the memory can be released in a centralized manner when the engine is destroyed.
[0217] The following is an illustrative introduction to the specific scenarios of the method for implementing the business functions of the embodiments of the present application.
[0218] In some embodiments, the use scenario of the solution of the embodiment of the present application may be a splash screen advertisement, that is, the service function implemented by the dynamic program is to display a splash screen advertisement, which has two characteristics:
[0219] First, the splash screen is displayed when the target application is started. The engine must be initialized after the target application is started. The splash screen display requires the engine to be initialized immediately. For the sake of user experience, the target application has limited time for the splash screen. The revenue of the splash screen ad is strongly related to the menu time. Under the premise of ensuring revenue, the splash screen ad has high requirements for the engine initialization time.
[0220] Second, the target application startup is a CPU-busy scenario, and a large number of target application initialization tasks will be performed simultaneously, which will further extend the engine initialization time.
[0221] The above two characteristics place high demands on the initialization time of the cross-platform dynamic engine in the flash screen advertising scenario.
[0222] In the initial experimental investigation of the embodiments of the present application, the CPU is busy in the scenario. The initialization time of the existing cross-platform dynamic engine is usually greater than 1s, and some are even close to 2s. However, the total time reserved for the splash screen advertisement of the target application is usually around 1s, so the existing dynamic engine cannot meet the demand for splash screen advertisements.
[0223] The embodiment of the present application takes splash screen advertising as the entry point and can be applied to splash screen advertising scenarios in various applications, and can also be applied to other advertising scenarios or other business scenarios.
[0224] For example, taking the splash screen advertising scenario as an example, the business characteristics of the splash screen advertising are mapped to the design requirements of the cross-platform dynamic engine, mainly in two aspects:
[0225] Fast startup speed: In the flash screen advertising scenario, the APP has strict control over the flash screen display time, so the flash screen advertising has very high requirements on the startup performance of the cross-platform dynamic engine;
[0226] Small package size: The advertising business relies on the traffic APP (i.e. the target application mentioned above), and the cross-platform dynamic engine is integrated into the APP. The package size should be increased as little as possible to reduce the integration pressure of the APP.
[0227] A cross-platform dynamic engine provided in an embodiment of the present application increases cross-platform dynamic capabilities for native programs of terminal devices while ensuring high startup speed and light weight of the engine.
[0228] In some embodiments, the embodiments of the present application can select JavaScript as a dynamic language; by integrating a JavaScript interpreter and conducting secondary development on this basis, the interaction between the terminal native language and JS can be realized; by building a framework, the different native system capability interfaces of each terminal are flattened, which is reflected in the native framework layer. The native interface designed in the native framework layer to be exposed to JS is consistent in different operating systems. In this way, when JS calls a native interface, the role in different operating systems is consistent. For example, both the iOS and Android sides have sensors. When building the native framework layer, the iOS and Android sides encapsulate the logic of starting the sensor with the same interface name, such as startSensor, and bind this native interface to the JS object. When JS calls the startSensor method, the execution result on both the iOS and Android sides is to start the sensor.
[0229] In addition, the embodiment of the present application connects the flattened system capability interface to the front-end language JavaScript, so that the business code written in JavaScript can ultimately call the terminal native system capabilities, thereby providing a cross-platform dynamic solution for different terminal systems.
[0230] The embodiment of the present application breaks through the performance bottleneck of the existing cross-platform dynamic engine, meets the requirements of the advertising business scenario for startup performance and package size increase, and provides a set of cross-platform dynamic solutions that can be applied to all advertising scenarios of terminal devices, greatly improving the iteration efficiency of advertising business needs. In addition, the cross-platform dynamic engine of the embodiment of the present application can be applied not only to advertising business scenarios, but also to other business scenarios that have requirements for startup performance and package size increase.
[0231] For example, Fig.14 As shown, the embodiment of the present application can select the high-performance and small-sized Quickjs as the JS interpreter; secondly, the engine layer is designed to realize the interaction between the native program and the dynamic program, so as to facilitate the upper layer to quickly realize the business capabilities; finally, the native framework layer designed utilizes the interface of the engine layer to open up the dynamic program's call to the terminal's native capabilities, and shields the interface differences of different operating systems from the dynamic program.
[0232] The following is an illustrative introduction to the logic of the method for implementing the business functions of the embodiment of the present application in conjunction with specific examples.
[0233] For example, Fig.15AAs shown, it is assumed that the target objects in the dynamic program include Image, Text, and Video, and the target native interfaces they are bound to are QJSBridgeImageComponent, QJSBridgeTextComponent, and QJSBridgeVideoComponent, respectively.
[0234] like Fig. 15B As shown, assuming that the dynamic program is a dynamic program for flash screen ads, the logic of the target object Image in the dynamic program is to display ad images. When the dynamic program is executed by the cross-platform dynamic engine, since the dynamic program does not have a method for displaying images, it is necessary to bind the native method showImage in the target native interface QJSBridgeImageComponent to the target object Image so that the dynamic program can display ad images. In other words, the target native interface QJSBridgeImageComponent gives the page rendering logic to the target object Image, and implements page rendering by calling the page rendering logic. At the same time, when the dynamic program calls the native method showImage, it needs to pass in the target parameter Image url (image address), and it is necessary to convert this target parameter Image url into the data type of the native program through data type mapping, so that the target native interface QJSBridgeImageComponent calls the image url to render the ad image.
[0235] The cross-platform dynamic engine of the embodiment of the present application has the following advantages:
[0236] 1. Good performance
[0237] After the cross-platform dynamic engine was implemented, we tried to integrate it in the splash screen scene. Through testing and online experiments, we verified that the performance of the engine in all aspects is close to that of the native engine. The performance data is shown in a bar chart as follows: Fig.16 shown.
[0238] from Fig.16 It can be seen from the data that the performance indicators of the cross-platform dynamic engine are slightly inferior to or on par with the native ones. The startup time, which is the most concerned issue in the flash screen advertising scenario, is only 20ms different from the native one. This can be compensated by starting a thread in parallel to preheat the engine while selecting the menu. The package size is increased by 5M, and the cost of increasing the package when the traffic APP is connected is within a controllable range.
[0239] The embodiment of the present application breaks through the startup performance bottleneck of the existing cross-platform dynamic engine in terms of performance through a cross-platform dynamic engine customized for the advertising business, and meets the needs of the advertising business.
[0240] 2. Improved Iteration Efficiency
[0241] The cross-platform dynamic engine of the embodiment of the present application was connected to the flash screen advertising scenario for testing, and it was verified that the engine is effective in improving iteration efficiency, mainly including improvements in the following two aspects.
[0242] 1) Improved R&D efficiency: Native development solutions require dual-end development and testing on iOS and Android. After connecting to the cross-platform dynamic engine, dynamic solutions only require front-end development and testing, which improves R&D and testing efficiency by more than 40%.
[0243] 2) Improved release efficiency: After the native development solution is completed, it needs to pass the application store review before it can be put on the shelves, and it needs to be gradually released as users update the APP, which takes about 15 days. After switching to a dynamic solution implemented by a cross-platform dynamic engine, it only takes one day to complete the development and release 80%, and the user reach efficiency has also been significantly improved.
[0244] Based on the same inventive concept, the embodiment of the present application also provides a device for implementing business functions. The principle of solving the problem by the device is similar to the method of the above embodiment, so the implementation of the device can refer to the implementation of the above method, and the repeated parts will not be repeated.
[0245] See also Fig.17 As shown, a service function implementation device provided in an embodiment of the present application may include:
[0246] The program acquisition module 171 is used to acquire the dynamic program to be executed after the target application is started, and the dynamic program is used to implement the business function in the target application;
[0247] The interface acquisition module 172 is used to acquire the target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in the native program, and the native program is a program embedded in the operating system for providing various underlying interfaces;
[0248] The mapping module 173 is used to perform the following operations for at least one target object: based on a preset data type mapping relationship, map the data type of a target parameter of a target object to the data type in a target native interface bound to the target object, and pass the mapped target parameter to the corresponding target native interface;
[0249] The calling module 174 is used to call at least one target native interface to execute the corresponding mapped target parameters to realize the business function corresponding to the dynamic program.
[0250] In the embodiment of the present application, the target native interface is called by binding the native interface of the native program to the object in the dynamic program. At the same time, the data type of the dynamic program is mapped with the data type of the terminal native program to realize the transmission of the target parameter. In this way, the logic of the dynamic program is executed through the native program, which can simplify the structure of the dynamic engine and improve its initialization speed to meet business needs.
[0251] Optionally, the device further includes a binding module, configured to:
[0252] For at least one target object, perform the following operations:
[0253] Create a structure of at least one target method in a target object, obtain a native object in a native program corresponding to a target object, and obtain at least one native method in a target native interface implemented by the native object;
[0254] The obtained call information of each native method in the target native interface is respectively stored in a structure of a target method corresponding to a target object, so as to bind a target object to the corresponding target native interface.
[0255] Optionally, the device further comprises a creation module, which is used to:
[0256] Create corresponding factory classes for at least one target business component based on the native program;
[0257] For at least one target business component, the following operations are performed respectively: based on a factory class of a target business component, according to the agreed method selection specification, at least one native method is selected from the native program to create a corresponding target native interface, and a native object corresponding to the target native interface is created.
[0258] Optionally, the interface acquisition module 172 is further used to:
[0259] For at least one target object, the following operations are performed respectively: from the structure of each target method of a target object, the call information of each native method in the bound target native interface is obtained;
[0260] The calling module 174 is also used for:
[0261] For at least one target native interface, the following operations are performed respectively: based on the call information of each native method in a target native interface, each native method is called to execute the corresponding mapped target parameter.
[0262] Optionally, the device further includes a relationship acquisition module, which is used to obtain a preset data type mapping relationship in the following manner:
[0263] For each data type corresponding to at least one target object in the dynamic program, an intermediate data type corresponding to each data type is created to obtain a first mapping relationship; wherein the intermediate data type belongs to a data type in the native program;
[0264] Convert each data type corresponding to at least one target native interface into a corresponding intermediate data type to obtain a second mapping relationship;
[0265] Based on the first mapping relationship and the second mapping relationship, a data type mapping relationship is obtained.
[0266] Optionally, the mapping module is also used to:
[0267] Mapping a data type of a target parameter of a target object to a corresponding intermediate data type based on a first mapping relationship through a first mapping interface of the dynamic program;
[0268] Through the second mapping interface of the native program, based on the second mapping relationship, the corresponding intermediate data type is mapped to a data type in a target native interface bound to a target object.
[0269] Optionally, the device further includes a memory management module, configured to:
[0270] For at least one target object's target parameters, perform the following operations:
[0271] After mapping the data type of a target parameter of a target object to a corresponding intermediate data type, the memory management of the mapped target parameter is bound to the memory management of the target parameter before mapping; wherein the memory management binding means: when applying for the memory of the mapped target parameter, the memory of the target parameter before mapping is applied, and when releasing the memory of the mapped target parameter, the memory of the target parameter before mapping is released.
[0272] Optionally, the device further comprises:
[0273] A storage module is used to store the target parameters before the mapping of the requested memory into a weak reference set;
[0274] The release module is used to implement the business functions corresponding to the dynamic program. During the memory release process, the weak reference set is traversed to release the target parameters before the mapping of the unreleased memory.
[0275] Optionally, the device further comprises a return module, which is used to:
[0276] For at least one target native interface, perform the following operations:
[0277] Get the execution result of a target native interface;
[0278] Based on a preset data type mapping relationship, the data type of the execution result is mapped to a data type corresponding to a target object bound to a target native interface;
[0279] Returns the mapped execution result to a target object bound to a target native interface.
[0280] For the convenience of description, the above parts are divided into modules according to their functions and described separately. Of course, when implementing this application, the functions of each module can be implemented in the same or multiple software or hardware.
[0281] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0282] After introducing the service function implementation method and device according to the exemplary embodiment of the present application, next, an electronic device according to another exemplary embodiment of the present application is introduced.
[0283] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. In one embodiment, the electronic device may be a terminal device, such as Figure 1 The terminal device 110 shown in FIG. 1 is a terminal device 110 shown in FIG. 1 . In this embodiment, the structure of the electronic device can be as follows: Fig.18 As shown, it includes: a communication component 1810, a memory 1820, a display unit 1830, a camera 1840, a sensor 1850, an audio circuit 1860, a Bluetooth module 1870, a processor 1880 and other components.
[0284] The communication component 1810 is used to communicate with the server. In some embodiments, a wireless fidelity (WiFi) module may be included. The WiFi module belongs to a short-range wireless transmission technology. The electronic device can help the user to send and receive information through the WiFi module.
[0285] The memory 1820 can be used to store software programs and data. The processor 1880 executes various functions and data processing of the terminal device 110 by running the software programs or data stored in the memory 1820. The memory 1820 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. The memory 1820 stores an operating system that enables the terminal device 110 to run. In the present application, the memory 1820 can store an operating system and various application programs, and can also store a computer program for executing the service function implementation method of the embodiment of the present application.
[0286] The display unit 1830 may also be used to display information input by the user or information provided to the user and a graphical user interface (GUI) of various menus of the terminal device 110. Specifically, the display unit 1830 may include a display screen 1832 disposed on the front of the terminal device 110. The display screen 1832 may be configured in the form of a liquid crystal display, a light emitting diode, etc. The display unit 1830 may be used to display the user interface of the target application and the business function in the embodiment of the present application.
[0287] The display unit 1830 can also be used to receive input digital or character information and generate signal input related to user settings and function control of the terminal device 110. Specifically, the display unit 1830 may include a touch screen 1831 arranged on the front of the terminal device 110, which can collect user touch operations on or near it, such as clicking a button, dragging a scroll box, etc.
[0288] The touch screen 1831 can be covered on the display screen 1832, or the touch screen 1831 and the display screen 1832 can be integrated to realize the input and output functions of the terminal device 110. The integrated touch screen can be referred to as a touch display screen. In this application, the display unit 1830 can display the application and the corresponding operation steps.
[0289] The camera 1840 can be used to capture still images, and the user can publish the images taken by the camera 1840 through the application. The camera 1840 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the processor 1880 to convert it into a digital image signal.
[0290] The terminal device may further include at least one sensor 1850, such as an acceleration sensor 1851, a distance sensor 1852, a fingerprint sensor 1853, and a temperature sensor 1854. The terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.
[0291] The audio circuit 1860, the speaker 1861, and the microphone 1862 can provide an audio interface between the user and the terminal device 110. The audio circuit 1860 can transmit the electrical signal converted from the received audio data to the speaker 1861, which is converted into a sound signal for output. The terminal device 110 can also be configured with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 1862 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1860 and converted into audio data, and then the audio data is output to the communication component 1810 to be sent to, for example, another terminal device 110, or the audio data is output to the memory 1820 for further processing.
[0292] The Bluetooth module 1870 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 1870 to exchange data.
[0293] The processor 1880 is the control center of the terminal device. It uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal device and processes data by running or executing software programs stored in the memory 1820 and calling data stored in the memory 1820. In some embodiments, the processor 1880 may include one or more processing units; the processor 1880 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the baseband processor mainly processes wireless communications. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 1880. In the present application, the processor 1880 can run the operating system, application programs, user interface display and touch response, as well as the business function implementation method of the embodiment of the present application. In addition, the processor 1880 is coupled to the display unit 1830.
[0294] In some possible implementations, various aspects of the service function implementation method provided by the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of the service function implementation method according to various exemplary embodiments of the present application described above in this specification. For example, the electronic device may execute the following steps: Fig.11Follow the steps shown in .
[0295] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0296] The program product of the embodiment of the present application may adopt a portable compact disk read-only memory (CD-ROM) and include a computer program, and can be run on an electronic device. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, apparatus, or device.
[0297] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.
[0298] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0299] The computer program for performing the operation of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages. The computer program can be executed entirely on the user electronic device, partially on the user electronic device, as a separate software package, partially on the user electronic device and partially on a remote electronic device, or entirely on a remote electronic device or server. In the case of a remote electronic device, the remote electronic device can be connected to the user electronic device through any type of network including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, using an Internet service provider to connect through the Internet).
[0300] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain a computer-usable computer program.
[0301] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program commands. These computer program commands can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the commands executed by the processor of the computer or other programmable data processing device generate commands for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0302] These computer program commands may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the commands stored in the computer readable memory produce an article of manufacture comprising a command device, the command device implementing the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0303] These computer program commands can also be loaded onto a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the commands executed on the computer or other programmable device provide the instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0304] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0305] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for implementing a business function, characterized in that: The method comprises: After the target application is started, a dynamic program to be executed is obtained, wherein the dynamic program is used to implement a business function in the target application; Acquire a target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in a native program, and the native program is a program embedded in an operating system for providing various underlying interfaces; For the at least one target object, the following operations are performed respectively: based on a preset data type mapping relationship, a data type of a target parameter of a target object is mapped to a data type in a target native interface bound to the target object, and the mapped target parameter is passed to the corresponding target native interface; At least one target native interface is respectively called to execute corresponding mapped target parameters to realize the business function corresponding to the dynamic program.
2. The method according to claim 1, characterized in that The method further comprises: For the at least one target object, perform the following operations respectively: Creating a structure of at least one target method in a target object, obtaining a native object in the native program corresponding to the target object, and obtaining at least one native method in a target native interface implemented by the native object; The obtained call information of each native method in the target native interface is respectively stored in a structure of a target method corresponding to the one target object, so as to bind the one target object to the corresponding target native interface.
3. The method according to claim 2, characterized in that The method further comprises: Based on the native program, create a corresponding factory class for at least one target business component; For the at least one target business component, the following operations are performed respectively: based on a factory class of a target business component, according to the agreed method selection specification, at least one native method is selected from the native program to create a corresponding target native interface, and a native object corresponding to the target native interface is created.
4. The method according to claim 2, characterized in that: The step of acquiring a target native interface bound to at least one target object in the dynamic program includes: For the at least one target object, the following operations are performed respectively: from the structure of each target method of a target object, the call information of each native method in the bound target native interface is obtained; Then the respectively calling at least one target native interface to execute the corresponding mapped target parameters includes: For the at least one target native interface, the following operations are performed respectively: based on the calling information of each native method in a target native interface, each native method is called to execute the corresponding mapped target parameters.
5. The method according to claim 1, characterized in that The preset data type mapping relationship is obtained in the following manner: For each data type corresponding to the at least one target object in the dynamic program, an intermediate data type corresponding to each data type is created to obtain a first mapping relationship; wherein the intermediate data type belongs to a data type in the native program; Convert each data type corresponding to the at least one target native interface into a corresponding intermediate data type to obtain a second mapping relationship; The data type mapping relationship is obtained based on the first mapping relationship and the second mapping relationship.
6. The method according to claim 5, characterized in that The mapping of the data type of a target parameter of a target object to the data type in the target native interface bound to the target object based on a preset data type mapping relationship includes: Mapping the data type of the target parameter of the one target object to a corresponding intermediate data type based on the first mapping relationship through the first mapping interface of the dynamic program; Through the second mapping interface of the native program, based on the second mapping relationship, the corresponding intermediate data type is mapped to the data type in the target native interface bound to the one target object.
7. The method according to claim 6, characterized in that The method further comprises: For the target parameter of the at least one target object, the following operations are performed respectively: After mapping the data type of a target parameter of a target object to a corresponding intermediate data type, the memory management of the mapped target parameter is bound to the memory management of the target parameter before mapping; wherein the memory management binding means: when applying for the memory of the mapped target parameter, the memory of the target parameter before mapping is applied, and when releasing the memory of the mapped target parameter, the memory of the target parameter before mapping is released.
8. The method according to claim 7, characterized in that The method further comprises: The target parameters before the mapping of the applied memory are stored in a weak reference set; After the business function corresponding to the dynamic program is realized, in the process of releasing memory, the weak reference set is traversed to release the target parameters before mapping whose memory has not been released.
9. The method according to any one of claims 1 to 8, characterized in that: After respectively calling at least one target native interface to execute the corresponding mapped target parameters, the method further includes: For the at least one target native interface, perform the following operations respectively: Get the execution result of a target native interface; Based on the preset data type mapping relationship, mapping the data type of the execution result to a data type corresponding to the target object bound to the one target native interface; The mapped execution result is returned to the target object bound to the one target native interface.
10. A device for implementing a business function, characterized in that: include: A program acquisition module, used to acquire a dynamic program to be executed after the target application is started, wherein the dynamic program is used to implement a business function in the target application; An interface acquisition module, used to acquire a target native interface bound to at least one target object in the dynamic program; wherein the target native interface runs in a native program, and the native program is a program embedded in the operating system for providing various underlying interfaces; A mapping module is used to perform the following operations for the at least one target object: based on a preset data type mapping relationship, map the data type of a target parameter of a target object to the data type in the target native interface bound to the target object, and pass the mapped target parameter to the corresponding target native interface; The calling module is used to call at least one target native interface to execute the corresponding mapped target parameters to realize the business function corresponding to the dynamic program.
11. The device according to claim 10, characterized in that The device also includes a binding module, which is used to: For the at least one target object, perform the following operations respectively: Creating a structure of at least one target method in a target object, obtaining a native object in the native program corresponding to the target object, and obtaining at least one native method in a target native interface implemented by the native object; The obtained call information of each native method in the target native interface is respectively stored in a structure of a target method corresponding to the one target object, so as to bind the one target object to the corresponding target native interface.
12. The device according to claim 11, characterized in that The device also includes a creation module, which is used to: Based on the native program, create a corresponding factory class for at least one target business component; For the at least one target business component, the following operations are performed respectively: based on a factory class of a target business component, according to the agreed method selection specification, at least one native method is selected from the native program to create a corresponding target native interface, and a native object corresponding to the target native interface is created.
13. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the methods of claims 1 to 9.
14. A computer-readable storage medium, characterized in that: It comprises a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of any method described in claims 1 to 9.
15. A computer program product, characterized in that The method comprises a computer program stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device executes the steps of any one of the methods described in claims 1 to 9.
