Application packaging method and device, electronic equipment and storage medium

By storing resources in Flutter in a modular fashion by channel and generating declaration files and access constant files, the problem of low efficiency in multi-channel packaging is solved, achieving efficient and standardized application package building and supporting multi-platform application development.

CN121807362APending Publication Date: 2026-04-07NANJING LINGXING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-23
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

The existing cross-platform application development framework Flutter lacks standardized and efficient solutions for multi-channel packaging, resulting in low application development efficiency.

Method used

By modularizing storage resources by channel, resource declaration files and access constant files are generated. Application packages are automatically built using channel identifiers and configuration parameters, ensuring that resources are packaged only in the target channel.

Benefits of technology

It achieves standardized and efficient multi-channel packaging, improves application development efficiency, avoids resource redundancy and errors, and supports multi-channel packaging of cross-platform applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807362A_ABST
    Figure CN121807362A_ABST
Patent Text Reader

Abstract

The invention discloses an application packaging method and device, electronic equipment and a storage medium, and belongs to the technical field of computer application. The application packaging method comprises the steps of determining a target resource set suitable for a target channel according to an identifier of the target channel and a resource declaration file of an application development framework project; determining an access path of each resource in the target resource set according to the identifier of the target channel and the resource access constant file; based on a preset parameter configuration file, obtaining a configuration parameter name corresponding to the target channel; and based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, executing a construction command of the application development framework, and generating an application package oriented to the target channel. By applying the technical scheme provided by the invention, normative and efficient multi-channel packaging can be realized, and the application development efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of computer application, and particularly relates to an application packaging method and device, an electronic device and a storage medium. BACKGROUND

[0002] With the increasing diversification of mobile application distribution channels, developers need to maintain multiple platform versions for the same application. Flutter, a cross-platform application development framework, is widely used in application development scenarios due to its efficient feature of "write once, run anywhere".

[0003] However, there is currently no perfect solution for how to implement standardized and efficient multi-channel packaging based on Flutter, resulting in low application development efficiency. SUMMARY

[0004] The purpose of the embodiments of the present application is to provide an application packaging method and device, an electronic device and a storage medium to achieve standardized and efficient multi-channel packaging and improve application development efficiency.

[0005] To solve the above technical problems, the present application provides the following technical solutions: In a first aspect, an application packaging method is provided, comprising: determining a target resource set suitable for a target channel according to the identifier of the target channel and a resource declaration file of an application development framework project, the resource declaration file including path declarations of each resource in a resource directory modularly stored by channel, each path declaration being associated with one or more applicable channel identifiers; determining an access path of each resource in the target resource set according to the identifier of the target channel and a resource access constant file, the resource access constant file including static constants for accessing resources; based on a pre-set parameter configuration file, obtaining a configuration parameter name corresponding to the target channel, the same parameters of the same function in the parameter configuration files of different channels using the same name; based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, executing a build command of the application development framework to generate an application package for the target channel.

[0006] Optionally, the resource directory includes a main channel resource directory for storing common resources and other channel resource directories for storing differentiated resources of each other channel, the file name of a resource in the main channel resource directory being consistent with the file name of the corresponding differentiated resource in the other channel resource directory, and the resource declaration file being generated by the following steps: scanning all resources in the main channel resource directory; For each resource scanned, determine whether there is a resource in the other channel resource directory with the same file name as the current resource; If there is a resource in the first other channel resource directory in the other channel resource directory with the same file name as the current resource, create a first path declaration for the current resource, the first path declaration points to the path of the current resource in the main channel resource directory, and is associated with the identity of the main channel and the identity of the other channel except the first other channel; If there is no resource in any of the other channel resource directories with the same file name as the current resource, create a second path declaration for the current resource, the second path declaration points to the path of the current resource in the main channel resource directory; Scan all resources in each of the other channel resource directories respectively; For each resource scanned, create a third path declaration for the current resource, the third path declaration points to the path of the current resource in the other channel resource directory, and is associated with the identity of the corresponding other channel.

[0007] Optionally, the resource access constant file is generated by the following steps: Scan all resources in the resource directory; According to the file name of the scanned resource, generate the static constant corresponding to each resource according to the preset naming rule; Based on the storage distribution of each resource in the resource directory, determine the value of the static constant corresponding to each resource; Based on the static constant and its value corresponding to each resource, generate the resource access constant file.

[0008] Optionally, the resource directory includes a main channel resource directory for storing general resources, and other channel resource directories for storing respective other channel differentiated resources, and the determination of the value of the static constant corresponding to each resource based on the storage distribution of each resource in the resource directory includes: For each resource in the resource directory, if the file name of the current resource only exists in the main channel resource directory, the value of the static constant corresponding to the current resource is determined as the path of the main channel resource directory; If the file name of the current resource exists in the main channel resource directory and at least one of the other channel resource directories, the value of the static constant corresponding to the current resource is determined as a conditional expression, the conditional expression is used to dynamically analyze the path according to the channel identity; If the current resource only exists in the second other channel resource directory, a value of a static constant corresponding to the current resource is determined as a path of the second other channel resource directory.

[0009] Optionally, the method further comprises: In a case where the resource directory is changed and / or a resource in the resource directory is changed, the resource declaration file and the resource access constant file are regenerated.

[0010] Optionally, the executing the build command of the application development framework comprises: Based on the configuration parameter name corresponding to the target channel, a configuration parameter corresponding to the target channel is acquired; The configuration parameter corresponding to the target channel is encoded to generate an encoded configuration string; Through the build command of the application development framework, the encoded configuration string is transmitted to the native platform, so that after the native platform decodes the encoded configuration string to obtain an original configuration parameter string, the original configuration parameter string is split into key-value pairs for use by the native code.

[0011] Optionally, the method further comprises: According to the identification of the target channel, a business logic code corresponding to the target channel is acquired; The executing the build command of the application development framework based on the access path of each resource in the target resource set and the parameter configuration file corresponding to the target channel to generate an application package for the target channel comprises: The executing the build command of the application development framework based on the access path of each resource in the target resource set, the parameter configuration file corresponding to the target channel, and the business logic code corresponding to the target channel to generate an application package for the target channel.

[0012] In a second aspect, an application packaging device is provided, comprising: A resource determination module is configured to determine a target resource set suitable for a target channel according to an identification of the target channel and a resource declaration file of an application development framework project, the resource declaration file including path declaration of each resource in a resource directory stored modularly by channel, and each path declaration being associated with one or more applicable channel identifications. An access path determination module is configured to determine an access path of each resource in the target resource set according to the identification of the target channel and a resource access constant file, the resource access constant file including a static constant used for accessing a resource. The parameter name obtaining module is configured to obtain a configuration parameter name corresponding to the target channel based on a preset parameter configuration file, and the same function in the parameter configuration files corresponding to different channels uses the same name. The application package generating module is configured to execute a build command of the application development framework based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, and generate an application package for the target channel.

[0013] In a third aspect, an electronic device is provided, which includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the method according to the first aspect.

[0014] In a fourth aspect, a readable storage medium is provided, which stores a program or instructions, and the program or instructions, when executed by a processor, implement the steps of the method according to the first aspect.

[0015] In a fifth aspect, a program product is provided, which includes instructions stored in a readable storage medium and adapted to be read and executed by a processor to cause a device having the processor to perform the steps of the method according to the first aspect.

[0016] In a sixth aspect, a chip is provided, which includes a processor and a communication interface coupled with the processor, and the processor is configured to run a program or instructions to implement the method according to the first aspect.

[0017] By applying the technical solutions provided in the embodiments of the present application, resources are modularly stored according to channels, and a resource declaration file and a resource access constant file of an application development framework project are generated. According to the identification of a target channel, the resource declaration file and the resource access constant file can be used to obtain an access path of each resource in a target resource set suitable for the target channel. Based on the access path of each resource in the target resource set and a parameter configuration file corresponding to the target channel, a build command of the application development framework is executed to generate an application package for the target channel. The target channel is any channel, and the scheme can be applied to each channel for application packaging. The resources are standardized managed and the resource access paths are automatically constructed, so that standardized and efficient multi-channel packaging can be implemented, and the application development efficiency is improved.

[0018] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the embodiments or the related art description will be briefly introduced. Obviously, the drawings in the following description only represent some of the embodiments of the present application, and other drawings can be obtained by those of ordinary skill in the art without any creative effort.

[0020] Figure 1 An implementation flowchart of an application packaging method in an embodiment of the present application; Figure 2 A structural schematic diagram of an application packaging device in an embodiment of the present application; Figure 3 A structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without any creative effort fall within the scope of the present application.

[0022] The terms "first", "second", and the like in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than that illustrated or described herein, and the objects distinguished by "first", "second" are usually a category, not limited to the number of objects, for example, the first object can be one or more. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / ", generally represents a "or" relationship between the front and rear associated objects.

[0023] The application packaging method provided by the embodiments of the present application will be described in detail below in combination with the drawings and specific embodiments and their application scenarios.

[0024] Referring to Figure 1 An implementation flowchart of an application packaging method provided by an embodiment of the present application is shown, and the method can include the following steps: S110: determining a target resource set suitable for a target channel according to the identification of the target channel and the resource declaration file of the application development framework project.

[0025] The resource declaration file includes path declaration of each resource in the resource directory stored in a modularized manner according to channels, each path declaration is associated with one or more applicable channel identifiers, and the resource directory includes a main channel resource directory for storing common resources and other channel resource directories for respectively storing differentiated resources of each other channel.

[0026] In the embodiment of the application, the official release channel of the developer is regarded as the main channel, and other channels such as application markets are regarded as other channels. The target channel can be the main channel or any one of the other channels. In the case of application packaging demand for the target channel, the technical solution provided in the embodiment of the application can be executed to generate an application package for the target channel.

[0027] The embodiment of the application differentiates and standardizes the management of resources to ensure that only the resources used by a channel are packaged into an application program for the channel, so that the uncontrollable risk caused by manual copying of resources can be avoided. The resources can include at least one of a picture file, an audio file, a video file, a font file or a text file.

[0028] The resources can be stored in a modularized manner according to channels in advance. For example, the resources are not directly stored in the main project, but are stored in a separate module project, such as a module named component_asset. In the module, a structured resource directory is established: a main channel resource directory (such as assets) for storing common resources, and a plurality of other channel resource directories (such as assets_channel1 and assets_channel2) for respectively storing differentiated resources of each other channel (such as channel1 and channel2). It can be understood that the resources are divided into two categories: one is common resources, i.e. resources used by the main channel, and other channels can also use the resources of this category, which are stored in the main channel resource directory, such as component_asset / assets; the other is differentiated resources used in some other channels, which are stored in other channel resource directories with the identifiers of the other channels as suffixes, such as component_asset / assets_channel1 for the differentiated resources of the other channel channel1 and component_asset / assets_channel2 for the differentiated resources of the other channel channel2.

[0029] It should be noted that in the embodiment of the application, the resources used by a channel can be understood as the resources used by the application program of the channel.

[0030] In the embodiments of the present application, the application development framework can be Flutter (an open source cross-platform application development framework). In Flutter, referencing resources requires writing the paths of these resources into a resource declaration file (such as pubspec.yaml), and only in this way will these resources be packaged at build time. It can be understood that the resource declaration file is used to manage resources that need to be packaged. Alternatively, a script can be used to automatically read resources, add path declarations of each resource in the resource declaration file, and associate one or more applicable channel identifiers, such as flavor identifiers, with each path declaration. This can improve efficiency and accuracy compared to manual addition.

[0031] Each resource in the main channel resource directory has at least one channel identifier. For example, all resources under component_asset / assets have at least one default-flavor identifier, indicating that the resources in the main channel resource directory will be used by the main channel, and may also be used by other channels. The default-flavor identifier can be understood as the flavor identifier of the main channel, which can be agreed as main.

[0032] For example, the path declaration of a resource is associated with [main, channel2], indicating that the resource is referenced when building the application of the main channel main and other channels channel2; and the path declaration of a resource is associated with [channel1], indicating that the resource is referenced when building the application of other channels channel1.

[0033] The resource declaration file can explicitly show the ownership relationship between resources and channels.

[0034] When there is a need to package an application for a target channel, the identifier of the target channel can be determined first. For example, when building the application of the target channel, a flavor parameter can be passed in to determine the identifier of the target channel. Then, according to the identifier of the target channel and the resource declaration file, a target resource set applicable to the target channel is determined, and the resources in the target resource set are the resources that need to be actually packaged, achieving on-demand introduction.

[0035] S120: According to the identifier of the target channel and the resource access constant file, determine the access path of each resource in the target resource set.

[0036] The resource access constant file includes static constants for accessing resources.

[0037] In Flutter, the access path of a resource can be automatically read by a script, and the resource access constant file is automatically written as a static constant for external use. Compared with manually passing in the access path of the resource, this method can improve efficiency and accuracy. The resource access constant file can be a dart file.

[0038] The resource access constant file includes a series of static constants for accessing resources, and each static constant corresponds to a resource.

[0039] After determining the target resource set suitable for the target channel, the access path of each resource in the target resource set can be determined according to the identifier of the target channel and the resource access constant file.

[0040] S130: Obtain the configuration parameter name corresponding to the target channel based on the preset parameter configuration file.

[0041] The configuration parameters of the same function in the parameter configuration files corresponding to different channels use the same name. Optionally, the parameter configuration files corresponding to each channel are stored in a subdirectory named by the channel identifier under the project root directory.

[0042] It can be understood that the application programs of different channels usually need different configuration parameters, such as server addresses, keys required by third-party software development kits (Software Development Kit, SDK), etc. The embodiments of the present application standardize the management of these configuration parameters. An independent parameter configuration file is created for each channel, and is stored in a standardized path in the project. For example, some configuration parameters required by the application programs of different channels are written in JavaScript (a programming language) object notation (JavaScript Object Notation, json) format into different parameter configuration files, which are stored under the channel folder in the project root directory, such as channel / config_channel1, channel / config_channel2, etc.

[0043] When there is a need to package the application for the target channel, the configuration parameter name corresponding to the target channel can be passed in based on the preset parameter configuration file, such as by --dart-define-from-file. It is necessary to ensure that the configuration parameters of the same function use the same name, and when reading these configuration parameters, the corresponding configuration parameter name is passed in by String.fromEnvironment. In this way, when constructing the application programs of different channels, the required configuration parameters can be read. The configuration parameters and the channels are decoupled and managed centrally.

[0044] S140: Based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, execute the build command of the application development framework to generate an application package for the target channel.

[0045] After determining the access path of each resource in the target resource set suitable for the target channel and obtaining the configuration parameter name corresponding to the target channel, the build command of the application development framework can be executed to generate an application package for the target channel. The application package is adapted to the target channel, the resource configuration is accurate, and the configuration parameter is correct.

[0046] Take the flutter as an example to illustrate the construction process.

[0047] Developing a Flutter application can use Android Studio (an Android integrated development tool) or VSCode (a software developer tool). When the run button is clicked directly, it cannot be distinguished which channel application is currently being built, so the running parameters need to be configured for the developer to choose which application needs to be debugged and run: If Android Studio is used, a channel package configuration file is added under the.run folder in the project root directory, and the identification and configuration parameters of the corresponding channel are added to the parameter list, such as --flavor=channel1 and --dart-define-from-file=channel / config_channel1. If VSCode is used, some channel package configuration files are added under the configurations field in the.vscode / launch.json in the project root directory, and the identification and configuration parameters of the corresponding channel are added to the parameter list, such as --flavor=channel1 and --dart-define-from-file=channel / config_channel1.

[0048] According to the method provided in the embodiments of the present application, resources are modularly stored according to channels, and a resource declaration file and a resource access constant file of an application development framework project are generated. According to the identifier of a target channel, the access path of each resource in a target resource set applicable to the target channel can be obtained by using the resource declaration file and the resource access constant file. Based on the access path of each resource in the target resource set and the parameter configuration file corresponding to the target channel, a build command of the application development framework is executed to generate an application package for the target channel. The target channel is any one channel, and the scheme can be applied to each channel for application packaging. The scheme can realize standardized and efficient multi-channel packaging, and is helpful to improve the application development efficiency.

[0049] In some embodiments of the present application, the file name of the resource in the main channel resource directory is consistent with the file name of the corresponding differentiated resource in the other channel resource directory. The resource declaration file is generated by the following steps: scanning all resources in the main channel resource directory; for each resource scanned, determining whether there is a resource with the same file name as the current resource in the other channel resource directory; if there is a resource with the same file name as the current resource in the first other channel resource directory in the other channel resource directory, creating a first path declaration for the current resource, the first path declaration pointing to the path of the current resource in the main channel resource directory, and associating the identifier of the main channel and the identifiers of the other channels except the first other channel; if there is no resource with the same file name as the current resource in any other channel resource directory, creating a second path declaration for the current resource, the second path declaration pointing to the path of the current resource in the main channel resource directory; scanning all resources in each other channel resource directory respectively; for each resource scanned, creating a third path declaration for the current resource, the third path declaration pointing to the path of the current resource in the other channel resource directory, and associating the identifier of the corresponding other channel.

[0050] For convenience of description, the above steps are combined for description.

[0051] In the embodiment of the present application, the file name of the resource in the main channel resource directory is consistent with the file name of the corresponding differentiated resource in the other channel resource directory. For example, the first resource is stored in the main channel resource directory, and the first resource will be replaced by the first target resource in the application program of a certain other channel. The first target resource is stored in the other channel resource directory corresponding to the other channel, and the first target resource is a differentiated resource. The file name of the first resource stored in the main channel resource directory is consistent with the file name of the first target resource stored in the other channel resource directory.

[0052] In the process of generating the resource declaration file, all resources in the main channel resource directory can be scanned first. For each scanned resource, it is determined whether there is a resource with the same file name as the current resource in the other channel resource directory. The current resource refers to the resource to which the current operation is directed.

[0053] For example, all resources in component_asset / assets are scanned to determine whether the file name of each resource exists in each other channel resource directory.

[0054] If there is a resource with the same file name as the current resource in the first other channel resource directory in the other channel resource directory, the current resource is considered to be a differentiated resource of the first other channel corresponding to the first other channel resource directory. In this case, a first path declaration is created for the current resource, the first path declaration points to the path of the current resource in the main channel resource directory, and is associated with the identifier of the main channel and the identifiers of the other channels except the first other channel. That is, the channel identifier associated with the current resource excludes the first other channel to ensure that the main channel resource directory of the differentiated resource is not mistakenly packaged when building the application program of the first other channel.

[0055] For example, the resource with the same file name as the resource center_bg.webp in the main channel resource directory component_asset / assets exists in the other channel resource directory component_asset / assets_channel2. The path of center_bg.webp in the main channel resource directory can be added under the flutter:assets: node of pubspec.yaml, and is associated with the identifiers (flavor) of all other channels except channel2, such as main and channel1, and the format is as follows: / / pubspec.yaml flutter: assets: - path: assets / images / center_bg.webp / / This is a differentiated resource, which will be packaged into the application only when the application corresponding to the main channel main and the application of other channels channel1 are built; flavors: - main - channel1 If any other channel resource directory does not have a resource with the same file name as the current resource, the current resource can be considered a general resource, which can be used by all channels. In this case, a second path declaration can be created for the current resource, which points to the path of the current resource in the main channel resource directory. The identifier of all channels can be associated, or no channel identifier can be associated.

[0056] For example, if there is no resource in any other channel resource directory with the same file name as the resource ic_home.webp in the main channel resource directory component_asset / assets, the path of ic_home.webp in the main channel resource directory can be directly added to the flutter:assets: node of pubspec.yaml, as follows: / / pubspec.yaml flutter: assets: - assets / images / ic_home.webp / / This is a general resource, which is used in the application of the main channel and the application of other channels.

[0057] After all the resources in the main channel resource directory are scanned, all the resources in each other channel resource directory can be further scanned. For each resource scanned, a third path declaration is created for the current resource, which points to the path of the current resource in the other channel resource directory corresponding to the other channel resource directory where the current resource is located. The identifier of the other channel corresponding to the other channel resource directory where the current resource is located is associated. The path declaration corresponding to each resource scanned in the other channel resource directory only associates a single channel to which it belongs.

[0058] For example, all resources in component_asset / assets_channel1 and component_asset / assets_channel2 are scanned, and the paths of these resources are added to the flutter:assets: node of pubspec.yaml with the corresponding channel flavor, as follows: / / pubspec.yaml flutter: assets: - path: assets_channel2 / images / center_bg.webp / / This is a differentiated resource, which will be packaged into the application only when building the application of other channel channel2; flavors: - channel2 The application embodiment can automatically and accurately pre-generate or update the resource declaration file through scanning and comparison, can reduce resource coverage errors, omissions or redundant packaging problems caused by manual maintenance, and ensure the accuracy of resource distribution.

[0059] In some embodiments of the application, the resource access constant file can be generated by the following steps: scan all resources in the resource directory; According to the file name of the scanned resource, generate a static constant corresponding to each resource according to the preset naming rule; Based on the storage distribution of each resource in the resource directory, assign a value to the static constant corresponding to each resource; Based on the static constant and its value corresponding to each resource, generate a resource access constant file according to the syntax rules of the target programming language.

[0060] For convenience of description, the above steps are combined for description.

[0061] In the embodiments of the application, all resources in the main channel resource directory and each other channel resource directory can be automatically scanned by a script, and according to the file name of the scanned resource, a static constant corresponding to each resource can be generated according to the preset naming rule. Alternatively, the static constant can be named using the camel case naming method.

[0062] Based on the storage distribution of each resource in the resource directory, the value of the static constant corresponding to each resource can be determined.

[0063] Optionally, for each resource in the resource directory, if the file name of the current resource only exists in the main channel resource directory, the value of the static constant corresponding to the current resource is determined as the path of the main channel resource directory; If the file name of the current resource exists in the main channel resource directory and at least one other channel resource directory, the value of the static constant corresponding to the current resource is determined as a conditional expression, and the conditional expression is used to dynamically analyze the path according to the channel identifier; If the file name of the current resource only exists in the second other channel resource directory, it can be considered that the current resource is only in the second other channel resource directory, and is a differentiated resource. The value of the static constant corresponding to the current resource can be determined as the path of the second other channel resource directory.

[0064] For each resource in the resource directory, there are three storage distribution situations of the current resource in the resource directory. One is that the file name of the current resource only exists in the main channel resource directory. Another is that the file name of the current resource exists in the main channel resource directory and in one or more other channel resource directories. The third is that the file name of the current resource only exists in one other channel resource directory.

[0065] If the file name of the current resource only exists in the main channel resource directory, it can be considered that the current resource is only in the main channel resource directory, and is a general resource. The value of the static constant corresponding to the current resource can be determined as the path of the main channel resource directory.

[0066] If the file name of the current resource exists in the main channel resource directory and at least one other channel resource directory, it can be considered that the current resource is a differentiated resource. The path corresponding to the main channel resource directory and the path corresponding to the other channel resource directory can be determined as a conditional expression for dynamically resolving the path according to the channel identifier. For example, for a same-name picture resource existing in the main channel resource directory and the other channel resource directory channel1, the value of the static constant corresponding to the resource is a conditional expression for determining whether to use the path under assets or assets_channel1 according to the channel identifier (such as the value of appFlavor) at the time of compilation.

[0067] If the file name of the current resource only exists in the second other channel resource directory, it can be considered that the current resource is only in the second other channel resource directory, and is a differentiated resource. The value of the static constant corresponding to the current resource can be determined as the path of the second other channel resource directory.

[0068] For example, all resources under the main channel resource directory component_asset / assets are scanned first. For each resource, it is determined whether a resource with the same file name as the resource exists in other channel resource directories (such as component_asset / assets_channel1 and component_asset / assets_channel2).

[0069] If none exists, the resource is a general resource. The static constant corresponding to the resource is named in small camel case according to the file name of the resource. The static constant and its value format are as follows: static const String icHomeWebp = 'packages / component_asset / assets / images / ic_home.webp'.

[0070] If exists, such as center_bg.webp exists in component_asset / assets_channel1, but does not exist in component_asset / assets_channel2, the static constant corresponding to the resource and its value format reference as follows: static const String centerBgWebp = 'packages / component_asset / ${(appFlavor == channel1)? 'assets_$appFlavor' : 'assets'} / images / center_bg.webp'.

[0071] If center_bg.webp exists in component_asset / assets_channel1 and component_asset / assets_channel2, the static constant corresponding to the resource and its value format reference as follows: static const String centerBgWebp = 'packages / component_asset / ${(appFlavor == channel1 || appFlavor == channel2)? 'assets_$appFlavor' : 'assets'} / images / center_bg.webp'.

[0072] For the case that the file name of the resource exists in the main channel resource directory and at least one other channel resource directory, it is necessary to determine whether to take the path of the resource under the main channel resource directory or the path under the other channel resource directory according to the channel identification parameter (such as --flavor parameter) passed in during construction and the resource directory where the resource is located.

[0073] Then scan the resources under each other channel resource directory, such as component_asset / assets_channel1 and component_asset / assets_channel2, and write the resources that do not exist in the main channel resource directory (i.e., the resources under component_asset / assets) into the resource access constant file in the form of a small camel case named static constant, and the format of the static constant and its value is as follows: static const String centerBgWebp = 'packages / component_asset / assets_$appFlavor / images / center_bg.webp'.

[0074] The resource access constant file can accurately obtain the access path of each resource in the target resource set applicable to the target channel. The resource access constant file is automatically generated or updated by a script in advance, and the developer does not need to manually write and maintain a large number of resource path strings, which can effectively solve the problems caused by spelling errors and update delays, improve the development efficiency, and improve the maintainability of the code.

[0075] In some embodiments of the present application, the method can further include the following steps: In the case where the resource directory is changed and / or the resources in the resource directory are changed, the resource declaration file and the resource access constant file are regenerated.

[0076] In the embodiments of the present application, the resource declaration file and the resource access constant file can be generated based on the resources in the resource directory. After the resource declaration file and the resource access constant file are generated, the resource directory can be changed, and / or the resources in the resource directory can be changed, such as adding a certain other channel resource directory, deleting a certain other channel resource directory, adding a certain resource, or deleting a certain resource. In this case, the resource declaration file and the resource access constant file need to be regenerated so that when there is a packaging requirement for an application facing a target channel, the accurate resource access path can be obtained based on the updated resource declaration file and the resource access constant file.

[0077] In some embodiments of the present application, the method can further include the following steps: Based on the configuration parameter name corresponding to the target channel, the configuration parameter corresponding to the target channel is obtained; The configuration parameter corresponding to the target channel is encoded to generate an encoded configuration string; The encoding configuration string is transmitted to the native platform through a build command of the application development framework, so that the native platform decodes the encoding configuration string to obtain an original configuration parameter string, and then splits the original configuration parameter string into key-value pairs for use by the native code.

[0078] For convenience of description, the above steps are combined for description.

[0079] In cross-platform development, configuration parameters on the side of an application development framework (such as flutter) need to be synchronized to the side of a native platform (such as Android or iOS). During building, the configuration parameters corresponding to a target channel can be obtained based on the configuration parameter name corresponding to the target channel, the configuration parameters corresponding to the target channel are encoded (such as base64 encoding), and an encoding configuration string is generated. The encoding configuration string is transmitted to the native platform through a build command of the application development framework, such as --dart-define-from-file of flutter. During the building stage of the native platform, the encoding configuration string can be read by a building tool of the native platform, and then the encoding configuration string is decoded to obtain an original configuration parameter string. The original configuration parameter string is split into key-value pairs, so that the native code can use the same configuration parameters as the application development framework by accessing the key-value pairs.

[0080] In this way, the parameter barrier between the application development framework (such as flutter) and the native platform is broken down, so that the native code can use the same set of configuration parameters as the application development framework, ensuring the unity and correctness of the entire application configuration.

[0081] In some embodiments of the present application, the method can further include the following steps: According to the identification of the target channel, the business logic code corresponding to the target channel is obtained; The build command of the application development framework is executed based on the access path of each resource in the target resource set and the parameter configuration file corresponding to the target channel, and an application package facing the target channel is generated, which can include the following steps: The build command of the application development framework is executed based on the access path of each resource in the target resource set, the parameter configuration file corresponding to the target channel, and the business logic code corresponding to the target channel, and an application package facing the target channel is generated.

[0082] It can be understood that in addition to resources and configuration parameters, certain channels can require specific business logic. In the embodiments of the present application, business logic code can be written separately for each channel, and the business logic code corresponding to different channels is distinguished by channel identification (such as through the appFlavor constant).

[0083] When there is an application packaging requirement for a target channel, the business logic code preset for the target channel can be obtained according to the identifier of the target channel. During construction, the business logic code corresponding to the target channel and the main project code are compiled together.

[0084] In this way, the clarity of the core business logic is ensured, the channel customization logic is easy to manage and remove, and the maintainability and readability of the code are improved.

[0085] The above detailed description of the technical solutions provided by the embodiments of the present application shows that the embodiments of the present application abandon the various inconveniences and potential risks that may be caused by manual writing of resource indexes, realize automatic construction of resource indexes through standardized management of resources and script processing, and realize the ability that related resources are packaged into an application only when needed by a channel package to be constructed, thereby effectively avoiding the problem of expansion of the package size caused by support for multi-channel packaging. In addition, by configuring each difference parameter in a file and standardizing the naming of the parameters, a set of parameter reading code can be used on the Flutter side and the native side to adapt different channel packages. Furthermore, in combination with the ability of multi-variant packaging of a native platform (such as Android, iOS, and HarmonyOS), a set of projects can be used to construct multi-channel applications.

[0086] The embodiments of the present application have at least the following advantages: Easy to maintain: the main channel application and other channel applications completely share a set of projects, and different channel applications can be constructed directly using the construction command of the application development framework, without interfering with each other when constructing multi-channel applications, thereby reducing the difficulty of maintenance; Cross-platform: supporting construction of channel packages for multiple system platforms such as Android, iOS, and HarmonyOS based on an application development framework (such as Flutter); High efficiency: resource management is completely handled by scripts, avoiding repetitive manual work and improving development efficiency; Extensible: for subsequent possible addition of channels, only simple configuration is required to support, and good extensibility is achieved.

[0087] It should be noted that in the embodiments of the present application, in resource differentiation management, the resources are not limited to separate local modular management, but can also be stored in the main project or as an independent module and then published online to realize remote dependency; the specific script implementation is not limited to Dart implementation, but also includes other arbitrary script implementations such as python and shell; In parameter and code differentiation management, it is not limited to using --dart-define-from-file to pass parameters. --dart-define can also be used. These parameters can be read in the code through String.fromEnvironment, or int.fromEnvironment or bool.fromEnvironment can be used depending on the actual type of the parameter.

[0088] It should be noted that the application packaging method provided in this application embodiment can be executed by an application packaging device, or by a control module within the application packaging device for executing the application packaging method. This application embodiment uses the execution of the application packaging method by an application packaging device as an example to illustrate the application packaging method provided in this application embodiment.

[0089] See Figure 2 The diagram shown is a structural schematic of an application packaging device provided in an embodiment of this application, comprising the following modules: The resource determination module 210 is used to determine the set of target resources applicable to the target channel based on the identifier of the target channel and the resource declaration file of the application development framework project. The resource declaration file includes the path declaration of each resource in the resource catalog that is modularly stored by channel, and each path declaration is associated with one or more applicable channel identifiers. The access path determination module 220 is used to determine the access path of each resource in the target resource set based on the identifier of the target channel and the resource access constant file. The resource access constant file includes static constants used to access resources. The parameter name acquisition module 230 is used to obtain the configuration parameter name corresponding to the target channel based on the preset parameter configuration file. Parameters with the same function in the parameter configuration files corresponding to different channels use the same name. The application package generation module 240 is used to execute the application development framework's build command to generate an application package for the target channel based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel.

[0090] The apparatus provided in this application provides modular storage of resources by channel and generates resource declaration files and resource access constant files for the application development framework project. Based on the identifier of the target channel, the access path of each resource in the target resource set applicable to the target channel can be obtained using the resource declaration files and resource access constant files. Based on the access path of each resource in the target resource set and the parameter configuration file corresponding to the target channel, the build command of the application development framework is executed to generate an application package for the target channel. The target channel can be any channel, and this scheme can be applied to package applications for each channel. By standardizing resource management and automating the construction of resource access paths, standardized and efficient multi-channel packaging can be achieved, which helps to improve application development efficiency.

[0091] In some embodiments of this application, the resource catalog includes a main channel resource catalog for storing general resources, and other channel resource catalogs for storing differentiated resources for each other channel. The filenames of resources in the main channel resource catalog are consistent with the filenames of the corresponding differentiated resources in the other channel resource catalogs. The application packaging device 200 also includes a declaration file generation module for generating a resource declaration file through the following steps: Scan all resources in the main channel resource catalog; For each resource scanned, determine whether there is a resource with the same filename as the current resource in other channel resource directories; If a resource with the same filename as the current resource exists in the first other channel resource directory of other channel resource directories, then a first path declaration is created for the current resource. The first path declaration points to the path of the current resource in the main channel resource directory and is associated with the identifier of the main channel and the identifiers of other channels other than the first other channel. If no resource with the same filename as the current resource does not exist in any other channel resource directory, a second path declaration is created for the current resource, which points to the path of the current resource in the main channel resource directory; Scan all resources in each of the other channel's resource catalogs; For each scanned resource, a third path declaration is created for the current resource. The third path declaration points to the path in the resource directory of another channel where the current resource is located, and is associated with the corresponding identifier of the other channel.

[0092] In some embodiments of this application, the application packaging device 200 further includes a constant file generation module, used to generate a resource access constant file through the following steps: Scan all resources in the resource directory; Based on the filenames of the scanned resources, static constants are generated for each resource according to preset naming rules; determine the value of the static constant corresponding to each resource based on the storage distribution of each resource in the resource directory; generate the resource access constant file based on the static constant and its value corresponding to each resource.

[0093] In some embodiments of the present application, the resource directory includes a main channel resource directory for storing common resources, and other channel resource directories respectively for storing various other channel differentiated resources, and the constant file generation module is specifically configured to: For each resource in the resource directory, if the file name of the current resource only exists in the main channel resource directory, the value of the static constant corresponding to the current resource is determined as the path of the main channel resource directory; If the file name of the current resource exists in the main channel resource directory and at least one other channel resource directory, the value of the static constant corresponding to the current resource is determined as a conditional expression, and the conditional expression is used to dynamically resolve the path according to the channel identifier; If the current resource only exists in the second other channel resource directory, the value of the static constant corresponding to the current resource is determined as the path of the second other channel resource directory.

[0094] In some embodiments of the present application, the application packaging device 200 further includes a file updating module, configured to: In the case that the resource directory is changed and / or the resource in the resource directory is changed, the resource declaration file and the resource access constant file are regenerated.

[0095] In some embodiments of the present application, the application package generation module 240 is specifically configured to: obtain the configuration parameter corresponding to the target channel based on the configuration parameter name corresponding to the target channel; Encode the configuration parameter corresponding to the target channel to generate an encoded configuration string; Pass the encoded configuration string to the native platform through the build command of the application development framework, so that the native platform decodes the encoded configuration string to obtain the original configuration parameter string, and then splits the original configuration parameter string into key-value pairs for use by the native code.

[0096] In some embodiments of the present application, the application packaging device 200 further includes a logic code obtaining module, configured to: Obtain the business logic code corresponding to the target channel according to the identifier of the target channel; The application package generation module 240 is specifically configured to: Based on the access path of each resource in the target resource set, the parameter configuration file corresponding to the target channel, and the business logic code corresponding to the target channel, the application development framework's build command is executed to generate an application package for the target channel.

[0097] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the relevant method embodiments, and will not be repeated here to avoid repetition.

[0098] Corresponding to the above method embodiments, this application also provides an electronic device, including: Memory, used to store computer programs; A processor is used to implement the steps of the above application packaging method when executing computer programs.

[0099] like Figure 3 The diagram shows the structural composition of an electronic device, which may include a processor 10, a memory 11, a communication interface 12, and a communication bus 13. The processor 10, memory 11, and communication interface 12 all communicate with each other through the communication bus 13.

[0100] In this embodiment, the processor 10 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic devices.

[0101] The processor 10 can call programs stored in the memory 11. Specifically, the processor 10 can execute operations in the embodiment of the application packaging method.

[0102] The memory 11 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment, the memory 11 stores at least a program for implementing the following functions: Based on the target channel identifier and the resource declaration file of the application development framework project, determine the target resource set applicable to the target channel. The resource declaration file includes the path declaration of each resource in the resource catalog that is modularly stored by channel, and each path declaration is associated with one or more applicable channel identifiers. Based on the identifier of the target channel and the resource access constant file, determine the access path for each resource in the target resource set. The resource access constant file includes static constants used to access resources. Based on the preset parameter configuration file, obtain the configuration parameter name corresponding to the target channel. The same configuration parameter with the same function in the parameter configuration file corresponding to different channels uses the same name. Based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, a build command of an application development framework is executed to generate an application package for the target channel.

[0103] In a possible implementation, the memory 11 can include a program storage area and a data storage area, where the program storage area can store an operating system and application programs required by at least one function, and the data storage area can store data created during use.

[0104] In addition, the memory 11 can include a high-speed random access memory, and can also include a nonvolatile memory, for example, at least one magnetic disk storage device or other volatile solid-state storage device.

[0105] The communication interface 12 can be an interface of a communication module, configured to connect with other devices or systems.

[0106] Of course, it needs to be explained that, Figure 3 The structures shown do not constitute a limitation on the electronic device in the embodiments of the present application, and the electronic device can include more or fewer components than Figure 3 those shown, or combine certain components.

[0107] The embodiments of the present application also provide a readable storage medium, and the readable storage medium stores a program or instructions, the program or instructions are executed by a processor to realize each process of the application packaging method embodiments, and the same technical effects can be achieved, to avoid repetition, which will not be described here.

[0108] The processor is the processor in the electronic device embodiments. The readable storage medium includes a computer readable storage medium, such as a computer readable memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, etc.

[0109] In addition, it needs to be explained that: the embodiments of the present application also provide a program product or program, and the program product or program can include instructions, which can be stored in a readable storage medium. The processor of the device reads the instructions from the readable storage medium, and the processor can execute the instructions, so that the device executes the description in the foregoing method embodiments, therefore, which will not be described here. In addition, the beneficial effects of using the same method are not described. For the technical details of the program product or program embodiments involved in the present application, please refer to the description of the method embodiments of the present application.

[0110] The embodiment of the present application further provides a chip, which comprises a processor and a communication interface, the communication interface is coupled with the processor, the processor is used for running programs or instructions, realizes various processes of the method embodiment, and can achieve the same technical effects. To avoid repetition, details are not described here.

[0111] It should be understood that the chip mentioned in the embodiment of the present application can also be referred to as a system chip, a system chip, a chip system or a system on chip, etc.

[0112] It should be noted that in this paper, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the method and device in the embodiment of the present application is not limited to the order of functions shown or discussed, but can also include functions performed in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method can be performed in an order different from that described, and various steps can also be added, omitted or combined. In addition, the features described with reference to certain examples can be combined in other examples.

[0113] From the above description of the embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment method can be realized by means of software and necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions for making a terminal (which can be a mobile phone, computer, server, air conditioner or network device, etc.) execute the method described in each embodiment of the present application.

[0114] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above specific embodiments, the above specific embodiments are only illustrative, not restrictive, and those skilled in the art can make many forms of embodiments and make some improvements and modifications to the present application under the inspiration of the present application without departing from the purpose of the present application and the protection scope of the claims. These embodiments, improvements and modifications all belong to the protection scope of the present application.

Claims

1. An application packaging method, characterized in that, include: Based on the identifier of the target channel and the resource declaration file of the application development framework project, a set of target resources applicable to the target channel is determined. The resource declaration file includes a path declaration for each resource in a resource catalog that is modularly stored by channel, and each path declaration is associated with one or more applicable channel identifiers. Based on the identifier of the target channel and the resource access constant file, the access path of each resource in the target resource set is determined, and the resource access constant file includes static constants for accessing resources; Based on the preset parameter configuration file, obtain the configuration parameter name corresponding to the target channel. The same configuration parameter with the same function in the parameter configuration file corresponding to different channels uses the same name. Based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, the build command of the application development framework is executed to generate an application package for the target channel.

2. The method according to claim 1, characterized in that, The resource catalog includes a main channel resource catalog for storing general resources, and other channel resource catalogs for storing differentiated resources for each other channel. The filenames of the resources in the main channel resource catalog are identical to the filenames of the corresponding differentiated resources in the other channel resource catalogs. The resource declaration file is generated through the following steps: Scan all resources in the main channel resource directory; For each scanned resource, determine whether there exists a resource in the other channel resource directory with the same filename as the current resource; If a resource with the same filename as the current resource exists in the first other channel resource directory of the other channel resource directory, a first path declaration is created for the current resource. The first path declaration points to the path of the current resource in the main channel resource directory and is associated with the identifier of the main channel and the identifiers of other channels other than the first other channel. If no resource with the same filename as the current resource exists in any of the other channel resource directories, a second path declaration is created for the current resource, the second path declaration pointing to the path of the current resource in the main channel resource directory; Scan all resources in each of the other channel resource directories respectively; For each scanned resource, a third path declaration is created for the current resource. The third path declaration points to the path in the resource directory of another channel where the current resource is located, and is associated with the corresponding identifier of the other channel.

3. The method according to claim 1, characterized in that, The resource access constant file is generated through the following steps: Scan all resources in the resource catalog; Based on the filenames of the scanned resources, static constants are generated for each resource according to preset naming rules; Based on the storage distribution of each resource in the resource directory, determine the value of the static constant corresponding to each resource; The resource access constant file is generated based on the static constants and their values ​​corresponding to each resource.

4. The method according to claim 3, characterized in that, The resource catalog includes a main channel resource catalog for storing general resources, and other channel resource catalogs for storing differentiated resources for each other channel. The step of determining the value of a static constant corresponding to each resource based on its storage distribution within the resource catalog includes: For each resource in the resource directory, if the filename of the current resource exists only in the main channel resource directory, then the value of the static constant corresponding to the current resource is determined to be the path of the main channel resource directory; If the filename of the current resource exists in both the main channel resource directory and at least one of the other channel resource directories, then the value of the static constant corresponding to the current resource is determined to be a conditional expression, which is used to dynamically resolve the path based on the channel identifier. If the current resource exists only in the second other channel resource directory, then the value of the static constant corresponding to the current resource is determined to be the path of the second other channel resource directory.

5. The method according to claim 1, characterized in that, The method further includes: If the resource directory changes and / or the resources in the resource directory change, the resource declaration file and the resource access constant file are regenerated.

6. The method according to claim 1, characterized in that, The execution of the build command for the application development framework includes: Based on the configuration parameter name corresponding to the target channel, obtain the configuration parameters corresponding to the target channel; The configuration parameters corresponding to the target channel are encoded to generate an encoded configuration string; The encoded configuration string is passed to the native platform through the build command of the application development framework. After the native platform decodes the encoded configuration string to obtain the original configuration parameter string, it splits the original configuration parameter string into key-value pairs for use by the native code.

7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Based on the identifier of the target channel, obtain the business logic code corresponding to the target channel; The step of executing the application development framework's build command based on the access path of each resource in the target resource set and the parameter configuration file corresponding to the target channel to generate an application package for the target channel includes: Based on the access path of each resource in the target resource set, the parameter configuration file corresponding to the target channel, and the business logic code corresponding to the target channel, the application development framework's build command is executed to generate an application package for the target channel.

8. An application packaging device, characterized in that, include: The resource determination module is used to determine the set of target resources applicable to the target channel based on the identifier of the target channel and the resource declaration file of the application development framework project. The resource declaration file includes a path declaration for each resource in a resource catalog that is modularly stored by channel, and each path declaration is associated with one or more applicable channel identifiers. The access path determination module is used to determine the access path of each resource in the target resource set based on the identifier of the target channel and the resource access constant file, wherein the resource access constant file includes static constants for accessing resources. The parameter name acquisition module is used to acquire the configuration parameter name corresponding to the target channel based on the preset parameter configuration file. Parameters with the same function in the parameter configuration files corresponding to different channels use the same name. The application package generation module is used to execute the construction command of the application development framework based on the access path of each resource in the target resource set and the configuration parameter name corresponding to the target channel, and generate an application package for the target channel.

9. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the application packaging method as described in any one of claims 1-7.

10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the application packaging method as described in any one of claims 1-7.