Resource file processing method, resource file calling method, electronic equipment and storage medium

By generating identification numbers for resource files in Flutter projects and replacing paths, the loading instability caused by resource file path errors is solved, and the stability of resource loading and code base is improved.

CN120234302APending Publication Date: 2025-07-01GUANGZHOU SHIYUAN ELECTRONICS CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311862250.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-29
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

In the Flutter file processing tool, the string address of the resource file path is written incorrectly, causing the resource to be loaded unstable, and cannot be detected during compilation, resulting in an error being found during project operation.

Method used

Generate an identification number for all resource files in the project directory, replace the path with an identification number, and call the identification number directly to avoid string address errors.

Benefits of technology

Improve the stability of resource loading, avoid resource unloading problems caused by string address writing errors, and enhance the stability of the code base.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120234302A_ABST
    Figure CN120234302A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and discloses a resource file processing method, a resource file calling method, electronic equipment and a storage medium, and the resource file processing method comprises the following steps: obtaining a project directory corresponding to a project; running the file generation command under the project directory to generate a code file corresponding to the project directory; based on the code file, traversing all resource files under the item directory to generate an identification number corresponding to each resource file; and replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file. By generating the identification numbers corresponding to the resource files for all the resource files under the item directory and directly calling the identification numbers corresponding to the resource files when the resource files are called subsequently, the problem that resources cannot be loaded due to writing errors of character string addresses of the resource files can be avoided, and therefore the stability of resource loading is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the technical field of data processing, and in particular, to a method for processing resource files, a method for calling resource files, an electronic device, and a storage medium. Background Art

[0002] Flutter is an open-source user interface (UI) toolkit developed by Google, which can achieve code reuse across multiple platforms. It helps developers build multi-platform applications efficiently with a single codebase and supports mobile, web, desktop, and embedded platforms. The introduction of Flutter technology enables developers to write only one set of code instead of two sets for Android and iOS, improving the R & D efficiency.

[0003] Currently, when processing resource files through the Flutter file processing tool, the path of the local resource file needs to be passed to load the resource file. Since the path of the resource file is an unrestricted string address, when the path of the resource file is written incorrectly, the IDE cannot detect the writing error during compilation, and this error is only discovered during the project runtime, resulting in low stability of resource loading. Summary of the Invention

[0004] Embodiments of the present application provide a method for processing resource files, a method for calling resource files, an electronic device, and a storage medium. By generating an identification number corresponding to each resource file in the project directory and directly calling the identification number corresponding to the resource file when subsequently calling the resource file, the present application can avoid the problem of resource failure to load caused by incorrect writing of the string address of the resource file, thereby improving the stability of resource loading.

[0005] Embodiments of the present application provide the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a method for processing resource files, including:

[0007] Obtain the project directory corresponding to the project;

[0008] Run a file generation command in the project directory to generate a code file corresponding to the project directory;

[0009] Based on the code file, traverse all resource files in the project directory to generate an identification number corresponding to each resource file;

[0010] Replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0011] In some embodiments, the project directory includes at least two folders. Based on the code file, traverse all resource files under the project directory to generate an identification number corresponding to each resource file, including:

[0012] Traverse all resource files in each folder to generate an identification number corresponding to each resource file in each folder, where different folders include different resource files.

[0013] In some embodiments, generating an identification number corresponding to each resource file includes:

[0014] Obtain information about the resource file through an annotation code parsing interface;

[0015] Generate an identification number corresponding to each resource file according to the information of the resource file, where the information of the resource file includes the path and file name corresponding to the resource file.

[0016] In some embodiments, replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file includes:

[0017] Determine whether the path corresponding to each resource file in the code file is an empty path;

[0018] If so, determine that there is no resource file corresponding to the path of the resource file, and delete the path corresponding to the resource file in the code file;

[0019] If not, replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0020] In a second aspect, an embodiment of the present application provides a method for calling a resource file. The method for calling a resource file includes:

[0021] Obtain the identification number corresponding to the resource file, where the identification number corresponding to the resource file is generated by the resource file processing method of the first aspect;

[0022] Call the resource file according to the identification number corresponding to the resource file.

[0023] In a third aspect, an embodiment of the present application provides a resource file processing device. The resource file processing device includes:

[0024] A code generation module, configured to obtain the project directory corresponding to the project; run a file generation command under the project directory to generate a code file corresponding to the project directory;

[0025] An identification number generation module, configured to traverse all resource files under the project directory based on the code file to generate an identification number corresponding to each resource file;

[0026] A path replacement module, configured to replace the path corresponding to each resource file in a code file with the identification number corresponding to each resource file.

[0027] Fourthly, an embodiment of the present application provides a resource file calling device, which includes:

[0028] An obtaining module, configured to obtain the identification number corresponding to a resource file, where the identification number corresponding to the resource file is generated by the resource file processing method in the first aspect above;

[0029] A calling module, configured to call a resource file according to the identification number corresponding to the resource file.

[0030] Fifthly, an embodiment of the present application provides an electronic device, including:

[0031] At least one processor; and

[0032] A memory communicatively connected to the at least one processor; wherein,

[0033] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the resource file processing method in the first aspect or the resource file calling method in the second aspect.

[0034] Sixthly, an embodiment of the present application provides a non-volatile computer-readable storage medium, which stores computer-executable instructions for causing an electronic device to execute the resource file processing method in the first aspect or the resource file calling method in the second aspect.

[0035] The beneficial effect of the embodiment of the present application is: different from the prior art, the embodiment of the present application provides a resource file processing method, which includes: obtaining a project directory corresponding to a project; running a file generation command under the project directory to generate a code file corresponding to the project directory; based on the code file, traversing all resource files under the project directory to generate an identification number corresponding to each resource file; and replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0036] By generating an identification number corresponding to a resource file for all resource files under a project directory and directly calling the identification number corresponding to the resource file when subsequently calling the resource file, the present application can avoid the problem that resources cannot be loaded due to incorrect writing of the string address of the resource file, thereby improving the stability of resource loading. Description of the Drawings

[0037] One or more embodiments are exemplarily illustrated by corresponding drawings. These exemplary illustrations do not limit the embodiments. Elements with the same reference numerals in the drawings represent similar elements. Unless otherwise stated, the drawings in the figures do not constitute a scale limitation.

[0038] Figure 1 is a schematic diagram of an application environment provided by an embodiment of the present application;

[0039] Figure 2 is a schematic flowchart of a method for processing a resource file provided by an embodiment of the present application;

[0040] Figure 3 is Figure 2 a refined flowchart of step S202 in

[0041] Figure 4 is Figure 2 a refined flowchart of step S203 in

[0042] Figure 5 is Figure 2 a refined flowchart of step S203 in

[0043] Figure 6 is Figure 2 a refined flowchart of step S203 in

[0044] Figure 7 is Figure 2 a refined flowchart of step S204 in

[0045] Figure 8 is a schematic flowchart of a method for calling a resource file provided by an embodiment of the present application;

[0046] Figure 9 is a schematic structural diagram of a device for processing a resource file provided by an embodiment of the present application;

[0047] Figure 10 is a schematic structural diagram of a device for calling a resource file provided by an embodiment of the present application;

[0048] Figure 11 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.

[0049] Explanation of the reference numerals in the drawings:

[0050] Label Name Label Name 100 Application environment 902 Identification number generation module 10 Electronic device 903 Path replacement module 20 Server 101 Processor 90 Resource file processing device 102 Memory 901 Code generation module 110 Resource file calling device 111 Acquisition module 112 Calling module Detailed implementation manners

[0051] For the convenience of understanding the present application, the present application will be described in more detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that when an element is expressed as "fixed to" another element, it can be directly on the other element, or there can be one or more intermediate elements therebetween. When an element is expressed as "connected to" another element, it can be directly connected to the other element, or there can be one or more intermediate elements therebetween. The terms "vertical", "horizontal", "left", "right" and similar expressions used in this specification are only for the purpose of illustration.

[0052] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as commonly understood by those of ordinary skill in the technical field to which this application belongs. The terms used in this specification in the description of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.

[0053] The technical solution of the present application will be specifically described below in conjunction with the accompanying drawings of the specification:

[0054] Please refer to Figure 1 , Figure 1 which is a schematic diagram of an application environment provided by an embodiment of the present application;

[0055] As Figure 1 shown, the application environment 100 includes: an electronic device 10 and a server 20. Among them, the electronic device 10 is communicatively connected to the server 20 through a network, and the network includes a wired network and / or a wireless network. It can be understood that the network includes wireless networks such as 2G, 3G, 4G, 5G, wireless local area network, and Bluetooth, and can also include wired networks such as serial cables and network cables.

[0056] In an embodiment of the present application, the electronic device 10 is used to replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file, send a resource file call command to the server when calling a resource file, or form a project code library according to the code file and store the project code library on the server. It can be understood that the electronic device 10 can be an electronic product with communication and networking functions such as a computer or a mobile phone. The electronic device 10 includes a communication module, which is communicatively connected to the server 20 and is used to send a resource file call command to the server when calling a resource file to obtain the resource file. In an embodiment of the present application, the communication module can implement communication with the Internet and the Internet, and the communication module includes, but is not limited to, communication units such as a WIFI module, a ZigBee module, an NB_IoT module, a 4G module, a 5G module, and a Bluetooth module.

[0057] In an embodiment of the present application, the electronic device 10 includes a controller, which serves as the control core of the electronic device 10 and is used to control the electronic device 10 to execute a resource file processing method or a resource file calling method. The controller can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine), or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of these components. The controller can also be any conventional processor, controller, microcontroller, or state machine. The controller can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration, or one or more combinations of a microcontroller unit (MCU), a field-programmable gate array (FPGA), and a system-on-chip (SoC).

[0058] It can be understood that the electronic device 10 in the embodiment of the present application further includes a storage module, and the storage module includes but is not limited to: one or more of devices such as FLASH flash memory, NAND flash memory, vertical NAND flash memory (VNAND), NOR flash memory, resistive random access memory (RRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), spin transfer torque random access memory (STT-RAM), etc.

[0059] In an embodiment of the present application, the server 20 is communicatively connected to the electronic device 10 and is used to store resource files, receive and execute resource file calling commands sent by the electronic device, or store a project code library. The number of the servers 20 is multiple, and the multiple servers can form a server cluster. For example, the server cluster includes: a first server, a second server,..., an Nth server, or the server cluster can be a cloud computing service center, and the cloud computing service center includes several servers. The servers in the embodiment of the present application include but are not limited to: tower servers, rack servers, blade servers, and cloud servers. Preferably, the server is a cloud server (Elastic Compute Service, ECS).

[0060] In the embodiments of the present application, FAPT (Flutter Asset Packaging Tool) is a plug-in tool developed specifically for processing resource files in Flutter, and the method for processing resource files in the present application is implemented based on the FAPT plug-in tool; Dart is a computer programming language developed by Google, which is an object-oriented, class-defined, single-inheritance language. Its syntax is similar to that of the C language and can be translated into JavaScript. It supports interfaces, mixins, abstract classes, reified generics, optional typing, and a sound type system. The code files generated by the code generator in the following methods are written in the Dart programming language.

[0061] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of a method for processing resource files provided by an embodiment of the present application;

[0062] Among them, for the method of processing the resource file, specifically, the execution subject of the method of processing the resource file is one or at least two processors of an electronic device.

[0063] As Figure 2 shown, the method for processing the resource file includes:

[0064] Step S201: Obtain the project directory corresponding to the project;

[0065] Specifically, Flutter is a user interface (UI) toolkit open-sourced by Google. A Flutter project includes three project directories: the android directory, the ios directory, and the lib directory. Among them, the android and ios directories are complete projects at both ends, and the code is generated in the languages of each end. The lib directory stores the dart files that implement the core logic of the project. The code files in the lib directory will ultimately be rendered to the android and ios platforms. In the embodiments of the present application, when obtaining the project directory corresponding to the project, the project directory refers to the lib directory.

[0066] Step S202: Run a file generation command in the project directory to generate a code file corresponding to the project directory;

[0067] Please refer to Figure 3 , Figure 3 which is Figure 2 a detailed flowchart of step S202 in

[0068] As Figure 3As shown, step S202: Run the file generation command in the project directory to generate the code files corresponding to the project directory, including:

[0069] In the embodiment of the present application, run the file generation command in the project directory. The file generation command is used to execute the following steps. Among them, the file generation command includes the flutter packages pub run build_runner build --delete-conflicting-outputs command.

[0070] Step S2021: Customize the code generator, where the code generator inherits from the single annotation processor;

[0071] Specifically, create a custom code generator. The code generator includes the code generator (Generator) in source_gen in Dart, and customize the code generator (Generator) to inherit from the single annotation processor. Among them, the command for the custom code generator to inherit from the single annotation processor includes: class FAPTGenerator extends GeneratorForAnnotation <createid>It can be understood that the custom class FAPTGenerator inherits from the single annotation processor to enable the official library to automatically generate code files. Among them, the single annotation processor includes GeneratorForAnnotation.

[0072] Step S2022: Based on the code generator, run the method for generating annotation elements to generate annotations.

[0073] Specifically, based on the code generator (Generator), run the method for generating annotation elements. Among them, the method for generating annotation elements includes the generateForAnnotatedElement method. After executing this method, if the resource file is an image file, add the ImageCreateID() annotation to the image loading helper class in the project. If the resource file is of other types, add corresponding annotations to the corresponding loading helper class in the project to generate annotations, where the annotations include target annotations.

[0074] Step S2023: Generate code files according to the annotations.

[0075] Specifically, since the code generator (Generator) inherits from the single annotation processor, it is necessary to add a target annotation to the single annotation processor. This target annotation is the annotation that needs to be processed in the processing method of this resource file, so that the code generator (Generator) can intercept the annotation elements according to the target annotation, and then create a trigger Builder. This trigger Builder is used to trigger the code generator, create a configuration file, and run the trigger Builder according to this configuration file to call the Dart official code generation library through the GeneratorForAnnotation interface, and generate a code file in the form of xxx.fapt.dart in combination with the file generation command (flutter packages pub run build_runner build --delete-conflicting-outputs). Among them, this code file includes Dart code, and this Dart code includes information such as annotations and the paths of resource files.

[0076] Step S203: Based on the code file, traverse all resource files in the project directory to generate an identification number corresponding to each resource file.

[0077] Please refer to Figure 4 , Figure 4 is Figure 2 the detailed process schematic diagram of step S203 in

[0078] Such as Figure 4 As shown, step S203: Based on the code file, traverse all resource files in the project directory to generate an identification number corresponding to each resource file, including:

[0079] Step S2031: Traverse all resource files in the folder to generate an identification number corresponding to each resource file in the folder;

[0080] Specifically, the project directory includes folders. Traverse the paths of all resource files in the folder through the generateForAnnotatedElement method to generate an identification number corresponding to each resource file in the folder. Among them, the resource files include image files and / or text files. For example, the project directory includes an images folder, which is used to store image files. Suppose one of the image files is user.png, then the path of this image file is the string: "images / user.png".

[0081] Please refer to Figure 5 , Figure 5 which Figure 2 is the detailed process diagram of step S203 in

[0082] As Figure 5 shown, step S203: Based on the code file, traverse all resource files in the project directory to generate an identification number corresponding to each resource file, including:

[0083] Step S2032: Traverse all resource files in each folder to generate an identification number corresponding to each resource file in each folder, where different folders include different resource files;

[0084] Specifically, the project directory may also include at least two folders. Traverse the paths of all resource files in each folder through the generateForAnnotatedElement method to generate an identification number corresponding to each resource file in each folder, where different folders include different resource files. Among them, the resource files include image files and / or text files. For example, the project directory includes a num1 folder and a num2 folder, and the num1 folder and the num2 folder may include different image files and text files at the same time.

[0085] Please refer to Figure 6 , Figure 6 which Figure 2 is the detailed process diagram of step S203 in

[0086] As Figure 6 As shown in the figure, step S203: Traverse all resource files in the project directory based on the code file to generate an identification number for each resource file, including:

[0087] Step S2033: Obtain the information of the resource file through the annotation code parsing interface;

[0088] Specifically, through the annotation code parsing interface, that is, the GeneratorForAnnotation interface, obtain the information of the resource file according to the paths of all resource files in each folder.

[0089] Step S2034: Generate an identification number for each resource file according to the information of the resource file, where the information of the resource file includes the path and file name corresponding to the resource file;

[0090] Specifically, generate an identification number for each resource file according to the information of the resource file, where the information of the resource file includes the path and file name corresponding to the resource file. For example, the project directory includes an images folder for storing picture files. Suppose one of the picture files is user.png, and the path of this picture file is the string: "images / user.png". Then, according to the path and file name corresponding to this picture file, the generated identification number is user.

[0091] Step S204: Replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file;

[0092] Please refer to Figure 7 , Figure 7 is Figure 2 the detailed process diagram of step S204 in

[0093] As Figure 7 shown in the figure, step S204: Replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file, including:

[0094] Step S2041: Obtain the path corresponding to each resource file in the code file;

[0095] Specifically, obtain the path corresponding to each resource file in the code file by traversing, where the path is represented in the form of a string, and the resource file includes picture files and / or text files. For example, for the picture file user.png in the images folder, the path of this picture file is the string: "images / user.png".

[0096] Step S2042: Determine whether the path corresponding to each resource file in the code file is an empty path;

[0097] Specifically, in a preset order, for example, the arrangement order of folders, traverse the paths corresponding to each resource file in each folder in the code file, and determine whether the path is an empty path, that is, determine whether there is a resource file in the path corresponding to the resource file. If there is no resource file in the path corresponding to the resource file, it is determined that the path is an empty path, and then step S2043 is entered; if there is a resource file in the path corresponding to the resource file, it is determined that the path is not an empty path, and then step S2044 is entered.

[0098] In the embodiment of the present application, the processing method of the resource file further includes:

[0099] According to the path corresponding to the resource file, determine the type of the resource file. For example, a certain folder includes pictures of multiple picture types. According to the path corresponding to the resource file, wherein the path of the resource file includes a suffix name, and the suffix name is used to indicate the picture type of the picture, such as: PNG, JPEG, JPG. By obtaining the path corresponding to the resource file, the type of the resource file can be determined.

[0100] Furthermore, traverse resource files of different types. Specifically, if a certain folder includes at least two types of resource files, then: traverse resource files of the same type until all resource files of a certain type are traversed, and then traverse resource files of the next type until all resource files in the folder are traversed, and determine the identification number of each resource file in the folder.

[0101] Step S2043: Determine that there is no resource file in the path corresponding to the resource file, and delete the path corresponding to the resource file in the code file;

[0102] Specifically, if the path corresponding to each resource file in the code file is an empty path, indicating that the resource file cannot be obtained through this path, it is determined that there is no resource file in the path corresponding to the resource file, and the path corresponding to the resource file in the code file is deleted.

[0103] Step S2044: Replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file;

[0104] Specifically, if the path corresponding to each resource file in the code file is not an empty path, indicating that the resource file can be obtained through this path, then replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file. Among them, the identification numbers corresponding to each resource file are different, and the identification number is unique. For example, for the picture file user.png in the images folder, the path of this picture file is the string: "images / user.png". According to the path and file name of this picture file, the identification number corresponding to this picture file is obtained as user, and the path "images / user.png" is replaced with the identification number corresponding to this picture file, which is user.

[0105] It can be understood that during the process of Flutter loading local picture files or text files, since the paths of local picture files or text files are composed of strings and the form of the strings is relatively complex, directly using the string form of the paths of local picture files or text files in Dart code is likely to cause problems such as incorrect writing of path addresses and inability to find the corresponding local picture files or text files, resulting in a high error rate of file loading.

[0106] In this application, by replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file, when calling the resource file in the code, there is no need to pass parameters by handwriting the string path, thereby being able to avoid the problem of resource failure to load caused by incorrect writing of the string address of the resource file, and further improving the stability of resource loading.

[0107] Moreover, when the code file on Flutter is migrated to a code library later, since the compiler in Flutter cannot recognize whether the string path is correct during code compilation, after the code file is migrated to a code library, there will be a problem of being unable to find the resource file in the code library, resulting in a decrease in the stability of the code library and problems such as non-existence or errors of resource files when the code library is called subsequently.

[0108] In this application, by replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file, when migrating the code file to a code library, since there is no need to find the resource file through the string path, therefore, it is possible to avoid problems such as non-existence or errors of resource files when the code library is called subsequently, and improve the stability of the code library.

[0109] In an embodiment of the present application, by providing a method for processing resource files, the method for processing resource files includes: obtaining a project directory corresponding to a project; running a file generation command under the project directory to generate code files corresponding to the project directory; based on the code files, traversing all resource files under the project directory to generate an identification number corresponding to each resource file; and replacing the path corresponding to each resource file in the code files with the identification number corresponding to each resource file. When subsequently calling a resource file, since the path corresponding to each resource file in the code files has been replaced with the identification number corresponding to each resource file, when calling a resource file in the code, it is not necessary to pass parameters by writing a string path manually, but directly call the resource file through the unique identification number corresponding to the resource file. This method can avoid the problem that resources cannot be loaded due to incorrect writing of the string address of the resource file, thereby improving the stability of resource loading.

[0110] Please refer to Figure 8 , Figure 8 which is a schematic flowchart of a method for calling resource files provided by an embodiment of the present application;

[0111] Among them, for the method for calling resource files, specifically, the execution entity of the method for calling resource files is one or at least two processors of an electronic device.

[0112] As Figure 8 shown, the method for calling resource files includes:

[0113] Step S801: Obtain the identification number corresponding to the resource file;

[0114] Specifically, the identification numbers corresponding to all resource files are stored in the code files, and the identification number corresponding to the resource file is obtained from the code files.

[0115] Step S802: Call the resource file according to the identification number corresponding to the resource file;

[0116] Specifically, according to the identification number corresponding to the resource file, directly input the identification number corresponding to the resource file in the code file, and then, according to the correspondence between the identification number corresponding to the resource file and the path, obtain the resource file in the path to call the resource file.

[0117] In an embodiment of the present application, by providing a method for calling resource files, the method for calling resource files includes: obtaining the identification number corresponding to the resource file, where the identification number corresponding to the resource file is generated by the above method for processing resource files; calling the resource file according to the identification number corresponding to the resource file. The present application can directly call the resource file according to the identification number corresponding to the resource file without inputting the path address corresponding to the resource file, thereby improving the efficiency of calling and loading resource files.

[0118] Please refer to Figure 9 again, Figure 9 which is a schematic structural diagram of a resource file processing device provided by an embodiment of the present application;

[0119] Among them, the resource file processing device is applied to an electronic device. Specifically, the resource file processing device is applied to one or at least two processors of the electronic device.

[0120] As Figure 9 shown, the resource file processing device 90 includes:

[0121] A code generation module 901, configured to obtain a project directory corresponding to a project; run a file generation command under the project directory to generate a code file corresponding to the project directory;

[0122] An identification number generation module 902, configured to traverse all resource files under the project directory based on the code file to generate an identification number corresponding to each resource file;

[0123] A path replacement module 903, configured to replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0124] In the embodiment of the present application, the code generation module 901 is specifically configured to:

[0125] Customize a code generator, where the code generator inherits from a single annotation processor;

[0126] Based on the code generator, run a method for generating annotation elements to generate an annotation;

[0127] Generate a code file according to the annotation.

[0128] In the embodiment of the present application, the identification number generation module 902 is specifically configured to:

[0129] Traverse all resource files in the folder to generate an identification number corresponding to each resource file in the folder;

[0130] Traverse all resource files in each folder to generate an identification number corresponding to each resource file in each folder, where different folders include different resource files;

[0131] Obtain information of the resource file through an annotation code parsing interface;

[0132] Generate an identification number corresponding to each resource file according to the information of the resource file, where the information of the resource file includes the path and file name corresponding to the resource file.

[0133] In the embodiment of the present application, the path replacement module 903 is specifically configured to:

[0134] Determine whether the path corresponding to each resource file in the code file is an empty path;

[0135] If so, determine that there is no resource file at the path corresponding to the resource file, and delete the path corresponding to the resource file in the code file;

[0136] If not, replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0137] In the embodiments of the present application, the processing device for the resource file can also be built by hardware devices. For example, the processing device for the resource file can be built by one or more than two chips, and each chip can work in coordination with each other to complete the processing method for the resource file described in the above embodiments. For another example, the processing device for the resource file can also be built by various logic devices, such as being built by a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine), or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of these components.

[0138] The processing device for the resource file in the embodiments of the present application can be a device, or a component, an integrated circuit, or a chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a notebook computer, a handheld computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.

[0139] The processing device for the resource file in the embodiments of the present application can be a device with an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.

[0140] The processing device for the resource file provided in the embodiments of the present application can implement Figure 2 For the sake of avoiding repetition, the various processes implemented will not be elaborated here.

[0141] It should be noted that the above-mentioned processing device for resource files can execute the method for processing resource files provided in the embodiments of the present application, and has the corresponding functional modules and beneficial effects for executing the method. For the technical details not described in detail in the embodiments of the processing device for resource files, reference can be made to the method for processing resource files provided in the above embodiments.

[0142] In the embodiments of the present application, by providing a processing device for resource files, including: a code generation module, configured to obtain a project directory corresponding to a project; run a file generation command under the project directory to generate a code file corresponding to the project directory; an identification number generation module, configured to traverse all resource files under the project directory based on the code file to generate an identification number corresponding to each resource file; a path replacement module, configured to replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

[0143] By generating an identification number corresponding to a resource file for all resource files under a project directory and directly calling the identification number corresponding to the resource file when subsequently calling the resource file, the present application can avoid the problem of incorrect writing of the string address of the resource file, thereby improving the stability of resource loading.

[0144] Please refer to Figure 10 , Figure 10 which is a schematic structural diagram of a resource file calling device provided in the embodiments of the present application;

[0145] Among them, the resource file calling device is applied to an electronic device. Specifically, the resource file calling device is applied to one or at least two processors of the electronic device.

[0146] As Figure 10 shown, the resource file calling device 110 includes:

[0147] An acquisition module 111, configured to acquire an identification number corresponding to a resource file, where the identification number corresponding to the resource file is generated by the method for processing resource files in the above embodiments;

[0148] A calling module 112, configured to call a resource file according to the identification number corresponding to the resource file.

[0149] It should be noted that the identification number corresponding to the resource file in the embodiments of the present application is generated by the method for processing resource files in the above embodiments. For the specific content, reference can be made to the content in the above embodiments and will not be elaborated here.

[0150] In the embodiments of the present application, the calling device for the resource file can also be built by hardware devices. For example, the calling device for the resource file can be built by one or more than two chips, and each chip can cooperate with each other to complete the method for calling the resource file described in the above embodiments. For another example, the calling device for the resource file can also be built by various logic devices, such as being built by a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine), or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of these components.

[0151] The calling device for the resource file in the embodiments of the present application can be a device, or a component, an integrated circuit, or a chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.

[0152] The calling device for the resource file in the embodiments of the present application can be a device with an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.

[0153] The calling device for the resource file provided in the embodiments of the present application can implement Figure 8 each of the implemented processes. To avoid repetition, it will not be elaborated here.

[0154] It should be noted that the above-mentioned calling device for the resource file can execute the method for calling the resource file provided in the embodiments of the present application, and has the corresponding functional modules and beneficial effects for executing the method. For the technical details not described in detail in the embodiments of the calling device for the resource file, reference can be made to the method for calling the resource file provided in the above embodiments.

[0155] In an embodiment of the present application, by providing a calling device for resource files, including: an acquisition module, configured to acquire an identification number corresponding to a resource file, where the identification number corresponding to the resource file is generated by the resource file processing method of the above embodiment; a calling module, configured to call the resource file according to the identification number corresponding to the resource file.

[0156] The present application calls the resource file through the identification number corresponding to the resource file, so that there is no need to input the path address corresponding to the resource file, thereby improving the efficiency of calling and loading the resource file.

[0157] Please refer to Figure 11 , Figure 11 which is a schematic structural diagram of an electronic device provided by an embodiment of the present application;

[0158] As Figure 11 shown, the electronic device 10 includes one or more processors 101 and a memory 102. Among them, Figure 11 one processor 101 is taken as an example in

[0159] The processor 101 and the memory 102 can be connected through a bus or other means, Figure 11 and taking the connection through the bus as an example in

[0160] The processor 101 is configured to provide computing and control capabilities to control the electronic device 10 to execute corresponding tasks. For example, the processor 101 controls the electronic device 10 to execute the resource file processing method or the resource file calling method in any of the above method embodiments. The resource file processing method includes: acquiring a project directory corresponding to a project; running a file generation command under the project directory to generate a code file corresponding to the project directory; based on the code file, traversing all resource files under the project directory to generate an identification number corresponding to each resource file; replacing the path corresponding to each resource file in the code file with the identification number corresponding to each resource file. The resource file calling method includes: acquiring an identification number corresponding to a resource file, where the identification number corresponding to the resource file is generated by the resource file processing method of the first aspect; calling the resource file according to the identification number corresponding to the resource file.

[0161] By generating an identification number corresponding to each resource file under the project directory and directly calling the identification number corresponding to the resource file when subsequently calling the resource file, the present application can avoid the problem of incorrect string address writing of the resource file, thereby improving the stability of resource loading.

[0162] The processor 101 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), a hardware chip, or any combination thereof; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0163] The memory 102, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions / modules corresponding to the processing method or the calling method of the resource file in the embodiments of the present application. By running the non-transitory software programs, instructions, and modules stored in the memory 102, the processor 101 can implement the processing method or the calling method of the resource file in any of the following method embodiments. Specifically, the memory 102 may include a volatile memory (VM), such as a random access memory (RAM); the memory 102 may also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD), or other non-transitory solid-state storage devices; the memory 102 may also include a combination of the above types of memories.

[0164] The memory 102 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 102 optionally includes a memory remotely disposed relative to the processor 101, and these remote memories may be connected to the processor 101 through a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0165] One or more modules are stored in the memory 102, and when executed by one or more processors 101, perform the processing method or the calling method of the resource file in any of the above method embodiments. For example, execute the Figure 2 steps shown above; it can also implement Figure 8 the functions of the respective modules or units.

[0166] In the embodiments of the present application, the electronic device 10 may also have components such as a wired or wireless network interface, a keyboard, and an input / output interface for input and output. The electronic device 10 may also include other components for implementing the functions of the device, which will not be elaborated here.

[0167] The embodiments of the present application also provide a non-volatile computer-readable storage medium, such as a memory including program code, and the above program code can be executed by a processor to complete the processing method or the calling method of the resource file in the above embodiments. For example, the non-volatile computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CDROM), magnetic tape, a floppy disk, and an optical data storage device, etc.

[0168] The embodiments of the present application also provide a computer program product, which includes one or more program codes, and the program codes are stored in a non-volatile computer-readable storage medium. The processor of the electronic device reads the program codes from the non-volatile computer-readable storage medium, and the processor executes the program codes to complete the method steps of the processing method or the calling method of the resource file provided in the above embodiments.

[0169] Those of ordinary skill in the art can understand that all or part of the steps for implementing the above embodiments can be completed by hardware, or can be completed by hardware related to program code. The program can be stored in a computer-readable storage medium, and the above-mentioned storage medium can be a read-only memory, a magnetic disk, or an optical disc, etc.

[0170] Through the description of the above embodiments, those of ordinary skill in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the non-volatile computer-readable storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0171] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; under the idea of the present application, the technical features in the above embodiments or different embodiments can also be combined, and the steps can be implemented in any order, and there are many other variations in different aspects of the present application as described above. For the sake of brevity, they are not provided in detail; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.< / createid>

Claims

1. A method for processing resource files, characterized in that, The method includes: Obtain the project directory corresponding to the project; Run a file generation command under the project directory to generate code files corresponding to the project directory; Based on the code files, traverse all resource files under the project directory to generate an identification number corresponding to each resource file; Replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

2. The method according to claim 1, wherein The running of the file generation command under the project directory to generate code files corresponding to the project directory includes: Customize a code generator, where the code generator inherits from a single annotation processor; Based on the code generator, run a method for generating annotation elements to generate annotations; Generate the code files according to the annotations.

3. The method according to claim 1 or 2, characterized in that, The resource files include picture files and / or text files.

4. The method according to claim 1, wherein The project directory includes folders. The traversing of all resource files under the project directory based on the code files to generate an identification number corresponding to each resource file includes: Traverse all resource files in the folder to generate an identification number corresponding to each resource file in the folder.

5. The method according to claim 4, wherein The project directory includes at least two folders. The traversing of all resource files under the project directory based on the code files to generate an identification number corresponding to each resource file includes: Traverse all resource files in each folder to generate an identification number corresponding to each resource file in each folder, where different folders include different resource files.

6. The method according to claim 4 or 5, characterized in that, The generating of an identification number corresponding to each resource file includes: Obtain information of the resource file through an annotation code parsing interface; Generate an identification number corresponding to each resource file according to the information of the resource file, where the information of the resource file includes the path and file name corresponding to the resource file.

7. The method according to claim 1, characterized in that, The replacing of the path corresponding to each resource file in the code file with the identification number corresponding to each resource file includes: Determine whether the path corresponding to each resource file in the code file is an empty path; If so, determine that there is no resource file corresponding to the path of the resource file, and delete the path corresponding to the resource file in the code file; If not, replace the path corresponding to each resource file in the code file with the identification number corresponding to each resource file.

8. A method for calling a resource file, characterized in that, The method includes: Obtain the identification number corresponding to the resource file, where the identification number corresponding to the resource file is generated by the processing method of the resource file according to any one of claims 1-7; Call the resource file according to the identification number corresponding to the resource file.

9. An electronic device, characterized in that, Includes: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the processing method of the resource file according to any one of claims 1-7 or the calling method of the resource file according to claim 8.

10. A non-volatile computer-readable storage medium, characterized in that, The non-volatile computer storage medium stores a computer program or instructions, and when the computer program or instructions are executed, the method for processing a resource file as described in any one of claims 1-7 or the method for invoking a resource file as described in claim 8 is implemented.