Method, device, equipment and medium for generating application installation package
By inserting anti-shake bytecode fragments into the target bytecode of the application, the problem of adding annotations to the source code in the prior art for anti-shake protection is solved, and the anti-shake protection of the view control is realized, which reduces the development workload and supports third-party SDKs.
Patent Information
- Application Number
- CN202110193157.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-20
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2041-02-20
AI Technical Summary
In the prior art, business developers need to add anti-shake protection annotations to the source code of the application to prevent the problem of continuous response of view controls due to rapid multiple clicks caused by user hand shaking, which increases the development workload.
By identifying the target method of setting the click event for the view control in the target bytecode of the application, and inserting anti-shake bytecode fragments into the bytecode of these methods, the anti-shake protection of the view control is achieved, avoiding the need to add annotations in the source code.
It realizes anti-stunning protection of view controls, reduces the development workload of business developers, and supports anti-stunning protection of click events in third-party SDKs.
Smart Images

Figure CN112860279B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, apparatus, device and medium for generating an application installation package. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] Clicking is one of the most common operations for users when using applications (Application, APP). For example, in the Android system, setting a click event for a view control View is achieved by developing source code, that is, setting the code logic that needs to be executed when this View is clicked.
[0004] When a user accidentally clicks on a View multiple times in quick succession due to hand shaking, and the last click event has not yet been completed, it is easy to respond to multiple click events in succession. For example, from a news information flow list, if you click an item to enter the main text page, if the user clicks twice quickly, it is easy to open the main text page of the article first, and then open another identical main text page on top of it. Another example is the like button of a comment. If the user clicks twice quickly, it is easy to like it first and then cancel the like immediately.
[0005] At present, in order to solve the above problems, business developers are usually required to write annotations outside the method of each click event when developing the source code of the application. The annotation is used to indicate that the click event needs anti-shake protection, that is, when the view control is clicked multiple times in quick succession, it will not respond repeatedly. This increases the development workload of business developers. Summary of the invention
[0006] The embodiments of the present disclosure provide a method, apparatus, device and medium for generating an application installation package, which are used to identify a target method in a bytecode for setting a click event for a view control, and then insert an anti-shake bytecode fragment into the target method to implement anti-shake protection for the view control. This does not require business developers to add anti-shake protection annotations in the source code, thereby reducing the development workload of business developers.
[0007] In a first aspect, the present disclosure provides a method for generating an application installation package, comprising:
[0008] After compiling the development source code of the application, obtaining the target bytecode of the application;
[0009] Identify the bytecode of the target method in the target bytecode; wherein the bytecode of the target method is used to set a click event for a view control;
[0010] Inserting an anti-jitter bytecode segment into the bytecode of the target method;
[0011] An installation package of the application is generated based on the target bytecode after the anti-shake bytecode segment is inserted.
[0012] In an optional implementation, the identifying the bytecode of the target method in the target bytecode includes:
[0013] Traversing the bytecodes of the methods in the target bytecodes to determine whether the bytecodes of the methods contain target feature information;
[0014] If the target feature information is included, it is determined that the bytecode of the method is the bytecode of the target method.
[0015] In an optional implementation, the target feature information includes one or more of the following:
[0016] The interface attributes include the first bytecode fragment;
[0017] The method name is the target name;
[0018] The method description includes a second bytecode fragment;
[0019] The method calling mode is the target mode;
[0020] The method description ends with the third bytecode fragment;
[0021] The view control's parameter position is located at the target position in the method description.
[0022] In an optional implementation, inserting an anti-jitter bytecode segment into the bytecode of the target method includes:
[0023] The anti-shake bytecode segment is inserted before a fourth bytecode segment in the bytecode of the target method; wherein the fourth target bytecode segment is a bytecode segment for starting to execute the target method.
[0024] In an optional implementation, the logic of the anti-shake bytecode segment includes:
[0025] If the target view control is clicked, determine whether there is a target time point in response to the last click of the target view control based on the correspondence between the view controls saved before the current time point and the time point in response to the click of the view control;
[0026] If the target time point exists, and the interval between the current time point and the target time point is less than the set duration, the click event of the target view control is intercepted.
[0027] In an optional implementation, the logic of the anti-shake bytecode segment further includes:
[0028] If the target time point exists, and the interval between the current time point and the target time point is greater than the set time length, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked; or
[0029] If the target time point does not exist, respond to the click event of the view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked.
[0030] In an optional implementation, the logic of the anti-shake bytecode segment further includes:
[0031] If the number of saved correspondences exceeds the set number, they are cleaned up according to the preset rules.
[0032] In an optional embodiment, the method further includes:
[0033] The set duration is set in an application initialization bytecode segment in the target bytecode.
[0034] In an optional implementation, the target bytecode is one or both of the following:
[0035] Bytecode compiled from development source code, bytecode of third-party software development kit SDK.
[0036] In an optional implementation, an annotation source code is provided in the source code of the corresponding target method in the development source code, wherein the annotation source code is used to indicate that anti-shake protection is not performed on the target method;
[0037] The method further comprises:
[0038] If the identified bytecode of the target method includes an annotation bytecode, the anti-shake bytecode segment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
[0039] In an optional implementation, the development source code is provided in different code packages, and the method further includes:
[0040] The configuration information of the target code package is added to the target configuration file, where the configuration information of the target code package is used to indicate that anti-shake protection is performed on the target method in the target code package.
[0041] In a second aspect, the present disclosure further provides a device for generating an application installation package, comprising:
[0042] An acquisition module, used to compile the development source code of the application and obtain the target bytecode of the application;
[0043] An identification module, used for identifying the bytecode of a target method in the target bytecode; wherein the bytecode of the target method is used for setting a click event for a view control;
[0044] An insertion module, used for inserting an anti-shake bytecode segment into the bytecode of the target method;
[0045] The generation module is used to generate an installation package of the application based on the target bytecode after the anti-shake bytecode fragment is inserted.
[0046] In an optional implementation, the identification module is further used for:
[0047] Traversing the bytecodes of the methods in the target bytecodes to determine whether the bytecodes of the methods contain target feature information;
[0048] If the target feature information is included, it is determined that the bytecode of the method is the bytecode of the target method.
[0049] In an optional implementation, the target feature information includes one or more of the following:
[0050] The interface attributes include the first bytecode fragment;
[0051] The method name is the target name;
[0052] The method description includes a second bytecode fragment;
[0053] The method calling mode is the target mode;
[0054] The method description ends with the third bytecode fragment;
[0055] The view control's parameter position is located at the target position in the method description.
[0056] In an optional embodiment, the insertion module is further used for:
[0057] The anti-shake bytecode segment is inserted before a fourth bytecode segment in the bytecode of the target method; wherein the fourth target bytecode segment is a bytecode segment for starting to execute the target method.
[0058] In an optional implementation, the logic of the anti-shake bytecode segment includes:
[0059] If the target view control is clicked, determining whether there is a target time point in response to the last click of the target view control based on the correspondence between the view controls saved before the current time point and the time point in response to the click of the view control;
[0060] If the target time point exists, and the interval between the current time point and the target time point is less than the set duration, the click event of the target view control is intercepted.
[0061] In an optional implementation, the logic of the anti-shake bytecode segment further includes:
[0062] If the target time point exists, and the interval between the current time point and the target time point is greater than the set time length, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked; or
[0063] If the target time point does not exist, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked.
[0064] In an optional implementation, the logic of the anti-shake bytecode segment further includes:
[0065] If the number of saved correspondences exceeds the set number, they are cleaned up according to the preset rules.
[0066] In an optional embodiment, the device further includes a setting module, which is used to:
[0067] The set duration is set in an application initialization bytecode segment in the target bytecode.
[0068] In an optional implementation, the target bytecode is one or both of the following:
[0069] Bytecode compiled from development source code, bytecode of third-party software development kit SDK.
[0070] In an optional implementation, an annotation source code is provided in the source code of the corresponding target method in the development source code, wherein the annotation source code is used to indicate that anti-shake protection is not performed on the target method;
[0071] The device also includes a module for prohibiting insertion:
[0072] If the identified bytecode of the target method includes an annotation bytecode, the anti-shake bytecode segment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
[0073] In an optional implementation, the development source code is provided in different code packages, and the apparatus further includes a configuration module for:
[0074] The configuration information of the target code package is added to the target configuration file, where the configuration information of the target code package is used to indicate that anti-shake protection is performed on the target method in the target code package.
[0075] In a third aspect, the present disclosure further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the steps of any one of the methods for generating an application installation package in the first aspect.
[0076] In a fourth aspect, the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the methods for generating an application installation package in the first aspect are implemented.
[0077] According to the solution provided by the embodiment of the present disclosure, after the development source code of the application is compiled, the target bytecode of the application can be obtained, and then the target method for setting a click event for the view control in the target bytecode is identified, and then the anti-shake bytecode fragment is inserted into the target method to implement anti-shake protection for the view control. There is no need for business developers to add anti-shake protection annotations in the source code, thereby reducing the development workload of business developers.
[0078] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or be understood by practicing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0080] Figure 1 A flowchart of a method for generating an application installation package provided by an embodiment of the present disclosure;
[0081] Figure 2 A flowchart of another method for generating an application installation package provided by an embodiment of the present disclosure;
[0082] Figure 3 A flow chart of an anti-shake protection logic provided by an embodiment of the present disclosure;
[0083] Figure 4 A schematic diagram of a device for generating an application installation package provided by an embodiment of the present disclosure;
[0084] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0085] In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the present disclosure will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.
[0086] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein.
[0087] In addition, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, product, or apparatus.
[0088] For ease of understanding, some concepts involved in the embodiments of the present application are explained below.
[0089] Application (APP): refers to the program installed on smart devices such as mobile phones, which generally need to cooperate with the server to run. Common applications are mainly divided into two categories. One is the pre-installed system application, such as text messages, photos, etc.; the other is third-party applications, such as NetEase News for information and WeChat for social networking.
[0090] View control (VIEW): In Android apps, all user interface elements are composed of View and ViewGroup. View is an object drawn on the screen that users can interact with, and ViewGroup is a view container for storing other Views and ViewGroups. In the disclosed embodiments, the view control is referred to as VIEW for short.
[0091] Page jitter: When a user clicks VIEW quickly and continuously while using an APP, multiple click events may be responded to, resulting in multiple pages being opened or multiple requests being sent continuously. This is called page jitter.
[0092] Click event (CLICKEVENT): In Android, there are five ways to set click events for Views, which essentially specify the method (a piece of source code) to be executed when the View is clicked. Among them, dynamic settings include four methods: internal class, click event interface implementation, Lambda expression, and method reference. Static settings can be declared in the layout xml (Extensible Markup Language) file.
[0093] SDK: Software Development Kit. There are two formats in Android development: JAR and AAR, which can be directly integrated into the project. The sources are generally: (1) SDK provided by Android, that is, the source code corresponding to each system version, such as the specific implementation of View mentioned above. (2) SDK provided by third-party developers, that is, packaged business implementation, which can be directly integrated into the project, such as third-party push service.
[0094] Packaging and compilation: Android packaging and compilation refers to the process of converting the code written by developers into an APK file that can be run on a mobile phone. There are several steps, such as converting a .java file into a .class file. It is usually completed through the gradle tool.
[0095] Bytecode file: In Android development, it generally refers to a file in .class format, which is compiled by the compiler from the .java.kotlin code written by the developer. It is platform-independent and is a binary service provided independently of the underlying host platform.
[0096] Gradle Transform: A packaging and compilation process provided by Android, which can be customized by developers. The input is the bytecode compiled by the project and SDK, and developers can complete their own logic.
[0097] ASM: is a bytecode manipulation framework that can be used to dynamically generate bytecode or enhance existing classes. ASM can directly generate binary class bytecode, or dynamically change its behavior before it is loaded, such as inserting code before and after method execution, etc.
[0098] ClassVisitor: ASM supports .class bytecode visitors for custom trigger events, custom annotation parsing, method parsing, etc.
[0099] MethodVisitor: ASM supports method visitors that customize trigger events, such as method attributes, parameter attributes, etc.
[0100] The design concept of the embodiments of the present application is introduced below.
[0101] To solve the problem of page jitter, business developers are usually required to write annotations outside the method of each click event when developing the source code of the application. The annotation is used to indicate that the click event needs anti-jitter protection, that is, when the view control is clicked multiple times in quick succession, it only responds to the first click and does not respond repeatedly. However, this increases the development workload of business developers.
[0102] In order to improve the above situation, the embodiments of the present application provide a method, apparatus, device and medium for generating an application installation package. After compiling the development source code of the application, the target bytecode of the application can be obtained, and then the target method for setting a click event for the view control in the target bytecode is identified, and then an anti-shake bytecode fragment is inserted into the bytecode of the target method to implement anti-shake protection of the view control. There is no need for business developers to add anti-shake protection annotations in the source code, thereby reducing the development workload of business developers.
[0103] The following is an introduction to the method for generating an application installation package of the present application in conjunction with the accompanying drawings and specific embodiments.
[0104] refer to Figure 1 The embodiment of the present application provides a method for generating an application installation package, which can be applied to a compilation device installed with a compilation environment. The method for generating an application installation package can include the following steps:
[0105] Step S101, compile the development source code of the application to obtain the target bytecode of the application.
[0106] The development source code is the code written by the business developers during the APP development process. For example, in Android APP development, the development source code can be in .java format, .kotlin format, etc. The developed source code needs to be packaged and compiled to generate an APK file that runs on the smart device. In this process, the development source code can be compiled by a compiler to obtain bytecode, such as .class format code.
[0107] The target bytecode of the above application may include the bytecode compiled from the development source code of the application itself, and may also include the bytecode of a third-party SDK, such as the bytecode of a third-party push service. It may also include the bytecode compiled from the development source code and the bytecode of a third-party SDK at the same time.
[0108] It should be noted that the above APP development can be based on the Android system or other operating systems, which is not limited in the embodiments of the present disclosure. The following embodiments are described by taking the APP development based on the Android system as an example.
[0109] Step S102, identifying the bytecode of the target method in the target bytecode; wherein the bytecode of the target method is used to set a click event for the view control.
[0110] In this step, the target method can be identified according to the characteristic information of the bytecode of the target method, for example, the characteristic information may include method description, method name, interface attribute information, etc. The target method may include multiple setting methods, for example, the following setting methods: internal class, click event interface, Lambda expression, method reference, etc. Under different setting methods, the characteristic information of the bytecode of the target method is also different, which can be specifically determined according to the corresponding setting method.
[0111] Step S103: inserting an anti-shake bytecode segment into the bytecode of the target method.
[0112] In this step, the anti-jitter bytecode fragment can be inserted at a specified position in the bytecode of the target method. For example, the anti-jitter bytecode fragment can be inserted in front of the fourth bytecode fragment in the bytecode of the target method, where the fourth target bytecode fragment is the bytecode fragment that starts executing the target method.
[0113] Exemplarily, before inserting the anti-shake bytecode fragment, the bytecode of the target method is decompiled, and the source code obtained is as follows:
[0114]
[0115] After inserting the anti-shake bytecode fragment, the bytecode of the target method is decompiled, and the source code obtained is as follows:
[0116]
[0117]
[0118] Among them, the source code corresponding to the anti-shake bytecode fragment is "if(!ClickGuarder.INSTANCE.watch(view)){". It can be seen that after the source code fragment "public void onClick(View view){", the target method starts to be executed. Therefore, the bytecode fragment compiled from the source code fragment can be the above-mentioned fourth target bytecode fragment.
[0119] Step S104: Generate an installation package of the application based on the target bytecode after the anti-shake bytecode segment is inserted.
[0120] In this step, after obtaining the target bytecode after inserting the anti-shake bytecode fragment, the multiple bytecode files where the target bytecode is located can be integrated into a DEX file, and then the DEX file is packaged to generate an APK application installation package. Among them, the DEX file is an executable file of the Android system, which contains all the operating instructions and runtime data of the application.
[0121] For example, Figure 2 As shown, the source code files in the application module include the developed source code. The application dependency may be a third-party SDK, which is a bytecode. The developed source code is compiled to obtain the bytecode of the application itself. The bytecode file of the application itself and the bytecode file in the third-party SDK can then be integrated into a DEX file, and then the DEX file is packaged to generate an APK application installation package.
[0122] In the disclosed embodiment, after the development source code of the application is compiled, the target bytecode of the application can be obtained, and then the target method for setting a click event for the view control in the target bytecode is identified, and then an anti-shake bytecode fragment is inserted into the bytecode of the target method to implement anti-shake protection for the view control. Business developers are not required to add anti-shake protection annotations to the source code, thereby reducing the development workload of business developers, and business developers do not need to understand the logic of the anti-shake bytecode fragment, so that they are unaware of the anti-shake protection.
[0123] In addition, APP development usually requires the introduction of a third-party SDK. If anti-shake protection annotations are added to the source code, anti-shake protection cannot be provided for click events in the third-party SDK, because the third-party SDK contains compiled bytecodes. The disclosed embodiment can provide anti-shake protection not only for click events in the APP development source code, but also for click events in the third-party SDK.
[0124] In some embodiments, step S102 may be implemented by the following steps:
[0125] a. Traverse the bytecode of the method in the target bytecode to determine whether the bytecode of the method contains the target feature information.
[0126] b. If the target feature information is included, the bytecode of the method is determined to be the bytecode of the target method.
[0127] In the embodiment of the present disclosure, the packaging and compilation of the development source code can be completed by the gradle tool. In the packaging and compilation process, after the development source code is compiled by the compiler, the Gradle Transform process can be added. Figure 2 In the process from the completion of compilation to the generation of DEX files, the Gradle Transform process is added, and then the ClassVisitor can be customized in the bytecode operation framework ASM. The target bytecode is traversed through the ClassVisitor. When the bytecode of the method is accessed (i.e., the visitMethod timing), it is determined whether the method is the target method by judging whether the bytecode of the method contains the target feature information, that is, the method for setting the click event for the view control. Among them, the target feature information can be determined according to the setting method of the target method.
[0128] In an optional implementation, the target feature information includes one or more of the following:
[0129] The interface attributes include the first bytecode fragment;
[0130] The method name is the target name;
[0131] The method description includes a second bytecode fragment;
[0132] The method calling mode is the target mode;
[0133] The method description ends with the third bytecode fragment;
[0134] The view control's parameter position is located at the target position in the method description.
[0135] Exemplarily, the target method may include the following four types: the first type is the target method set by an internal class; the second type is the target method set by implementing a click event interface; the third type is the target method set by a Lambda expression; and the fourth type is the target method set by a method reference. The target feature information of these four target methods is introduced below.
[0136] The target characteristic information of the first target method and the second target method is the same, which may include: the interface attribute contains "android / view / View$OnClickListener", that is, the first bytecode fragment mentioned above; the method name is "onClick", that is, the target name mentioned above; the method description is "(Landroid / view / View;)V", that is, the second bytecode fragment mentioned above.
[0137] The target characteristic information of the third target method is the same as that of the fourth target method, including: the method calling method is "invokeDynamic", which is the above target method; the method name is "onClick"; the method description ends with ")Landroid / view / View$OnClickListener;", which is the above third bytecode fragment; in the method description, it is declared that it has one or more parameters, and the parameter position of the view control view is the last bit in the declared parameters, that is, the parameter position of the first parameter starts from 0, and the parameter position of view is the number of parameters minus one, for example, the number of parameters is 4, and the parameter position of view is 3; if there is only one parameter view, then its parameter position is 0.
[0138] In the related art, the method of adding anti-shake protection annotations in the source code cannot provide anti-shake protection for the third and fourth target methods mentioned above, because these two target methods do not support adding annotations. However, the embodiments of the present disclosure can provide anti-shake protection for the above four target methods.
[0139] Further, based on the Gradle Transform process of the above embodiment, step S103 can be implemented in the following way: customize the MethodVisitor in ASM, and when the target method is identified, the anti-shake bytecode fragment can be dynamically inserted at the specified position of the target method through the bytecode writing capability provided by the MethodVisitor.
[0140] For example, dynamically inserting the anti-shake bytecode fragment through MethodVisitor can be implemented through the following bytecode:
[0141] Label l0 = new Label();
[0142] mv.visitLabel(l0);
[0143] mv.visitFieldInsn(GETSTATIC,"com / netease / parkinson / ClickGuarder",
[0144] "INSTANCE","Lcom / netease / parkinson / ClickGuarder;");
[0145] mv.visitVarInsn(ALOAD,mParamPosition);
[0146] mv.visitMethodInsn(INVOKEVIRTUAL,
[0147] "com / netease / parkinson / ClickGuarder","watch","(Ljava / lang / Object;)Z",false);
[0148] Label l1 = new Label();
[0149] mv.visitJumpInsn(IFEQ,l1);
[0150] Label l2 = new Label();
[0151] mv.visitLabel(l2);
[0152] mv.visitInsn(RETURN);
[0153] mv.visitLabel(l1);
[0154] mv.visitFrame(Opcodes.F_SAME,0,null,0,null);
[0155] Among them, mv is the class that can write bytecode provided by MethodVisitor, and mParamPosition is the index where the view parameter is located.
[0156] In some embodiments, the logic of the anti-shake bytecode segment may include the following steps:
[0157] (1) If the target view control is clicked, determine whether there is a target time point when the target view control was last clicked based on the correspondence between the view controls saved before the current time point and the time point when the response view control was clicked.
[0158] In this step, for example, a Key-Value relationship graph of the timestamps of View click responses with a maximum number of set numbers can be cached, where Key-Value is the correspondence between the view control and the time point when the view control is clicked, where the Key can be the hash code corresponding to the view control. For example, the identifier of the view control can be hashed to obtain the hash code, and the Value is the time point.
[0159] Exemplarily, when view control 1 is clicked, the hash code Key1 of the view control is first determined, and then the cached relationship graph is searched to see whether Key1 exists. If so, the most recent time point Value1 corresponding to Key1 can be determined, that is, the target time point of the last response to view control 1 being clicked.
[0160] (2) If there is a target time point, and the interval between the current time point and the target time point is less than the set time, the click event of the target view control is intercepted.
[0161] Among them, the set duration can be set as needed, for example, it can be 400 milliseconds, and the embodiment of the present disclosure is not limited to this. If the interval between the current time point and the target time point is less than the set duration, it is considered that the view control is accidentally touched, and it is forced to return, and the click event of the view control is not responded to.
[0162] Furthermore, the situations of responding to the click event of the target view control include the following two situations:
[0163] First, if the interval between the current time point and the target time point is greater than the set time, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked.
[0164] The second method is to respond to the click event of the target view control if the target time point does not exist, and save the corresponding relationship between the target view control and the current time point when the target view control is clicked.
[0165] For example, the target view control is the above-mentioned view control 1. If Key1 does not exist in the cached relationship graph, it means that there is no target time point for the last response to view control 1 being clicked. At this time, it is necessary to respond to the click event of view control 1 and save the correspondence between view control 1 and the current response time point when view control 1 is clicked.
[0166] When saving the above correspondence, it can also be determined whether the number of correspondences in the cache exceeds a set number. If it exceeds the set number, the correspondences are cleared according to a preset rule.
[0167] The set number can be set as needed, for example, it can be 10. When cleaning, the first few corresponding relationships saved can be deleted. For example, if the maximum number of caches is 10, the first 5 corresponding relationships can be deleted. The number of deletions can be set as needed, and the embodiment of the present disclosure does not limit this.
[0168] In some embodiments, in order to facilitate setting the above-mentioned set duration, the set duration may be set in an application initialization bytecode segment in the target bytecode.
[0169] For example, when the APP is initialized, the set duration can be set by the following method:
[0170] ClickGuarder.INSTANCE.setup(400L);
[0171] Among them, 400L refers to the set duration.
[0172] Below Figure 3 Taking the example of FIG. 1 , the logic of the anti-shake bytecode fragment is introduced exemplarily.
[0173] Reference Figure 3 As shown, if the target view control is clicked, the following steps are performed:
[0174] Step S301, querying the target time point of the last response to the target view control being clicked;
[0175] Step S302, if there is a target time point, determine whether the interval between the current time point and the target time point is less than the set time length; if yes, execute step S303, otherwise execute steps S304-S306;
[0176] Step S303, intercepting the click event of the target view control;
[0177] Step S304, responding to a click event of the target view control;
[0178] Step S305, recording the correspondence between the target view control and the time point of responding to the target view control this time;
[0179] Step S306, determining whether the number of corresponding relationships in the cache exceeds a set number, if yes, executing step S307;
[0180] Step S307, clean up according to preset rules.
[0181] In some embodiments, some target methods may not require anti-shake protection. For example, in a live broadcast scenario, when the audience continuously likes the host, continuous clicks on the like control require repeated responses. At this time, an annotation source code can be set in the source code of the corresponding target method in the development source code, where the annotation source code is used to indicate that the target method is not protected against jitter.
[0182] Exemplarily, the annotated source code may be “@Parkinson(needGuard=false)”, and the following source code is the source code of the target method with the annotated source code set.
[0183]
[0184] Furthermore, if the bytecode of the identified target method includes an annotation bytecode, the anti-shake bytecode fragment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
[0185] In an optional implementation, the development source code is set in different code packages. In order to set the scope of inserting anti-jitter bytecode fragments, the configuration information of the target code package can be added to the target configuration file. The configuration information of the target code package is used to indicate anti-jitter protection for the target method in the target code package.
[0186] For example, you can add the following configuration to the ext part of the build.gradle file at the outermost layer of the project:
[0187] ext{
[0188] clickGuarderScope=['com.netease.newsreader','com.netease.nr']
[0189] }
[0190] Among them, 'com.netease.newsreader' and 'com.netease.nr' indicate the names of the code packages, and the target methods in these code packages need to be protected against jitter.
[0191] Based on the same inventive concept, the present disclosure also provides a device for generating an application installation package. The principle of solving the problem by the device is similar to that of the method in the above embodiment. Therefore, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated. Figure 4 As shown, the device for generating an application installation package includes:
[0192] The acquisition module 41 is used to compile the development source code of the application and obtain the target bytecode of the application;
[0193] An identification module 42, used for identifying the bytecode of the target method in the target bytecode; wherein the bytecode of the target method is used for setting a click event for the view control;
[0194] An inserting module 43, used for inserting an anti-shake bytecode segment into the bytecode of the target method;
[0195] The generating module 44 is used to generate an installation package of the application based on the target bytecode after the anti-shake bytecode segment is inserted.
[0196] In an optional implementation, the identification module 42 may also be used to:
[0197] Traverse the bytecode of the method in the target bytecode to determine whether the bytecode of the method contains the target feature information;
[0198] If the target feature information is included, the bytecode of the method is determined to be the bytecode of the target method.
[0199] In an optional implementation, the target feature information may include one or more of the following:
[0200] The interface attributes include the first bytecode fragment;
[0201] The method name is the target name;
[0202] The method description includes a second bytecode fragment;
[0203] The method calling mode is the target mode;
[0204] The method description ends with the third bytecode fragment;
[0205] The view control's parameter position is located at the target position in the method description.
[0206] In an optional embodiment, the insertion module 43 can also be used for:
[0207] An anti-jitter bytecode segment is inserted before the fourth bytecode segment in the bytecode of the target method; wherein the fourth target bytecode segment is a bytecode segment for starting to execute the target method.
[0208] In an optional implementation, the logic of the anti-shake bytecode segment may include:
[0209] If the target view control is clicked, determine whether there is a target time point when the target view control was last clicked based on the correspondence between the view controls saved before the current time point and the time point when the response view control was clicked;
[0210] If there is a target time point, and the interval between the current time point and the target time point is less than the set duration, the click event of the target view control is intercepted.
[0211] In an optional implementation, the logic of the anti-shake bytecode segment may further include:
[0212] If there is a target time point, and the interval between the current time point and the target time point is greater than the set time length, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked; or
[0213] If the target time point does not exist, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point when the target view control is clicked.
[0214] In an optional implementation, the logic of the anti-shake bytecode segment may further include:
[0215] If the number of saved correspondences exceeds the set number, they are cleaned up according to the preset rules.
[0216] In an optional implementation, the device may further include a setting module, configured to:
[0217] The set duration is set in the application initialization bytecode segment in the target bytecode.
[0218] In an optional implementation, the target bytecode may be one or both of the following:
[0219] Bytecode compiled from development source code, bytecode of third-party software development kit SDK.
[0220] In an optional implementation, an annotation source code is provided in the source code of the corresponding target method in the development source code, wherein the annotation source code is used to indicate that anti-shake protection is not performed on the target method;
[0221] The device may further include a module for prohibiting insertion:
[0222] If the bytecode of the identified target method includes an annotation bytecode, then the anti-shake bytecode fragment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
[0223] In an optional implementation, the development source code is provided in different code packages, and the apparatus may further include a configuration module for:
[0224] The configuration information of the target code package is added to the target configuration file, where the configuration information of the target code package is used to indicate that anti-shake protection is performed on the target method in the target code package.
[0225] Based on the same inventive concept, an embodiment of the present application further provides an electronic device, the principle of solving the problem by the electronic device is similar to the method of the above embodiment, so the implementation of the electronic device can refer to the implementation of the method, and the repeated parts will not be repeated. Figure 5 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown.
[0226] See also Figure 5 As shown, the electronic device may include a processor 502 and a memory 501. The memory 501 provides the processor 502 with program instructions and data stored in the memory 501. In the embodiment of the present application, the memory 501 may be used to store a program for generating an application installation package in the embodiment of the present application.
[0227] The processor 502 calls the program instructions stored in the memory 501, and the processor 502 is used to execute the method for generating an application installation package in any of the above method embodiments, for example Figure 1 The illustrated embodiment provides a method for generating an application installation package.
[0228] The specific connection medium between the memory 501 and the processor 502 is not limited in the embodiment of the present application. Figure 5 In the embodiment, the memory 501 and the processor 502 are connected via a bus 503. The bus 503 is connected to the processor 502 via a bus 503. Figure 5 The connections between other components are shown in bold lines, and are not intended to be limiting. Bus 503 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0229] The memory may include a read-only memory (ROM) and a random access memory (RAM), and may also include a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0230] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0231] An embodiment of the present application also provides a computer storage medium, in which a computer program is stored. A processor of a computer device reads the computer program from the computer readable storage medium, and the processor executes the computer program, so that the computer device executes the method for generating an application installation package in any of the above method embodiments.
[0232] In the specific implementation process, the computer storage medium may include: Universal Serial Bus Flash Drive (USB), mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and other storage media that can store program codes.
[0233] In some possible implementations, various aspects of the method for generating an application installation package provided in the present application may also be implemented in the form of a program product, which includes a program code. When the program product is run on a computer device, the program code is used to enable the computer device to execute the steps of generating an application installation package according to various exemplary implementations of the present application described above in this specification. For example, the computer device may execute the following steps: Figure 1 The process of generating an application installation package in steps S101 to S104 is shown.
[0234] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0235] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0236] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0237] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0238] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for generating an application installation package, characterized in that: include: After compiling the development source code of the application, the target bytecode of the application is obtained; Traversing the bytecodes of the methods in the target bytecodes to determine whether the bytecodes of the methods contain target feature information; If the target feature information is included, determining that the bytecode of the method is the bytecode of the target method; wherein the bytecode of the target method is used to set a click event for the view control; Inserting an anti-jitter bytecode segment into the bytecode of the target method; The multiple bytecode files where the target bytecode is located after the anti-shake bytecode fragment is inserted are integrated into an executable file, and the executable file is packaged to generate an installation package of the application.
2. The method according to claim 1, characterized in that The target feature information includes one or more of the following: The interface attributes include the first bytecode fragment; The method name is the target name; The method description includes a second bytecode fragment; The method calling mode is the target mode; The method description ends with the third bytecode fragment; The view control's parameter position is located at the target position in the method description.
3. The method according to claim 1, characterized in that The step of inserting an anti-jitter bytecode segment into the bytecode of the target method comprises: The anti-shake bytecode segment is inserted before a fourth bytecode segment in the bytecode of the target method; wherein the fourth bytecode segment is a bytecode segment for starting to execute the target method.
4. The method according to any one of claims 1 to 3, characterized in that: The logic of the anti-shake bytecode segment includes: If the target view control is clicked, determine whether there is a target time point in response to the last click of the target view control based on the correspondence between the view controls saved before the current time point and the time point in response to the click of the view control; If the target time point exists, and the interval between the current time point and the target time point is less than the set duration, the click event of the target view control is intercepted.
5. The method according to claim 4, characterized in that The logic of the anti-shake bytecode segment also includes: If the target time point exists, and the interval between the current time point and the target time point is greater than the set time length, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked; or If the target time point does not exist, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked.
6. The method according to claim 5, characterized in that The logic of the anti-shake bytecode segment also includes: If the number of saved correspondences exceeds the set number, they are cleaned up according to the preset rules.
7. The method according to claim 5, characterized in that The method further comprises: The set duration is set in an application initialization bytecode segment in the target bytecode.
8. The method according to any one of claims 1 to 3, characterized in that: The target bytecode is one or both of the following: Bytecode compiled from development source code, bytecode of third-party software development kit SDK.
9. The method according to any one of claims 1 to 3, characterized in that: Annotation source code is provided in the source code of the corresponding target method in the development source code, wherein the annotation source code is used to indicate that anti-shake protection is not performed on the target method; The method further comprises: If the identified bytecode of the target method includes an annotation bytecode, the anti-shake bytecode fragment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
10. The method according to any one of claims 1 to 3, characterized in that: The development source code is arranged in different code packages, and the method further comprises: The configuration information of the target code package is added to the target configuration file, where the configuration information of the target code package is used to indicate that anti-shake protection is performed on the target method in the target code package.
11. A device for generating an application installation package, characterized in that: include: An acquisition module is used to compile the development source code of the application to obtain the target bytecode of the application; an identification module, configured to traverse the bytecode of the method in the target bytecode, determine whether the bytecode of the method contains target feature information, and if so, determine that the bytecode of the method is the bytecode of the target method; wherein the bytecode of the target method is used to set a click event for a view control; An insertion module, used for inserting an anti-shake bytecode segment into the bytecode of the target method; The generating module is used to integrate the multiple bytecode files where the target bytecode is located after the anti-shake bytecode fragment is inserted into an executable file, and package the executable file to generate an installation package of the application.
12. The device according to claim 11, characterized in that The target feature information includes one or more of the following: The interface attributes include the first bytecode fragment; The method name is the target name; The method description includes a second bytecode fragment; The method calling mode is the target mode; The method description ends with the third bytecode fragment; The view control's parameter position is located at the target position in the method description.
13. The device according to claim 12, characterized in that The plug-in module is also used for: The anti-shake bytecode segment is inserted before a fourth bytecode segment in the bytecode of the target method; wherein the fourth bytecode segment is a bytecode segment for starting to execute the target method.
14. The device according to any one of claims 11 to 13, characterized in that The logic of the anti-shake bytecode segment includes: If the target view control is clicked, determine whether there is a target time point in response to the last click of the target view control based on the correspondence between the view controls saved before the current time point and the time point in response to the click of the view control; If the target time point exists, and the interval between the current time point and the target time point is less than the set duration, the click event of the target view control is intercepted.
15. The device according to claim 14, characterized in that The logic of the anti-shake bytecode segment also includes: If the target time point exists, and the interval between the current time point and the target time point is greater than the set time length, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked; or If the target time point does not exist, respond to the click event of the target view control, and save the corresponding relationship between the target view control and the current time point in response to the target view control being clicked.
16. The device according to claim 15, characterized in that The logic of the anti-shake bytecode segment also includes: If the number of saved correspondences exceeds the set number, they are cleaned up according to the preset rules.
17. The device according to claim 15, characterized in that The device also includes a setting module, which is used to: The set duration is set in an application initialization bytecode segment in the target bytecode.
18. The device according to any one of claims 11 to 13, characterized in that The target bytecode is one or both of the following: Bytecode compiled from development source code, bytecode of third-party software development kit SDK.
19. The device according to any one of claims 11 to 13, characterized in that Annotation source code is provided in the source code of the corresponding target method in the development source code, wherein the annotation source code is used to indicate that anti-shake protection is not performed on the target method; The device also includes a module for prohibiting insertion: If the identified bytecode of the target method includes an annotation bytecode, the anti-shake bytecode fragment is not inserted into the bytecode of the target method; wherein the annotation bytecode is compiled from the annotation source code.
20. The device according to any one of claims 11 to 13, characterized in that The development source code is arranged in different code packages, and the device further comprises a configuration module for: The configuration information of the target code package is added to the target configuration file, where the configuration information of the target code package is used to indicate that anti-shake protection is performed on the target method in the target code package.
21. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the method according to any one of claims 1 to 10.
22. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Method and device for preventing clicking jitter of View controls via Android side
CN107168757A
Application function customizing method and device, computing equipment and storage medium
CN108121563A