This paper introduces 58.com’s practice of aar packet size statistical monitoring.

“Spring Dawn” Spring sleep is not aware of xiao, everywhere smell crow birds. Wind and rain at night, how much do flowers fall? Meng haoran –

background

As business version of iteration, the apk is becoming more and more big, after each version online need output accounts for different business size analysis report, in order to realize the monitoring of each business package size growth curve, convenient provide powerful basis for reduce packet size, at present the industry is not a good method for calculating aar in apk size. Why not just look at the AAR file size? Because an AAR may contain a multi-architecture SO, it will not be used in practical applications.

The problem

Since 58APP can be relied on by full AAR, app project is just a shell project, so we can obtain the dependency tree and rely on the AAR to be calculated in a demo project, and then calculate the size difference before and after the dependency to produce aar size. However, if the AAR to be calculated has POM to depend on other AAR, After removing POM dependencies, packaging may fail due to resource loss. The size of the specified AAR in the APK cannot be calculated.

There are two problems with missing resources: one is missing resources such as images, and the other is missing placeholder resources in the manifest file.

The solution

It can be seen from the error log that if aapT2, the missing resource, cannot be found during the execution of link, we just want to calculate the proportion of AAR in APK and do not care whether the output APK can run. Therefore, we can modify the aapT2 source code to search for resources with fixed names from the Demo project when resources cannot be found. If an error occurs during compilation and related resources cannot be found, we only need to create placeholder resources with the same type of fixed names (ids.xml) in the Demo project. For more information about aAPT, see Do-it-yourself AAPT

For the second problem, the missing placeholder in the manifest file can be fixed by modifying the gradle plugin source code to assign fixed values to placeholder.

Configure the REQUIRED CPU architecture and remote warehouse in the Demo project, and then type a basic APK in the Demo project and obtain the size, and then add aar dependencies to the Demo project to obtain the size of the aar package. In order to simplify the process, we can obtain the dependency tree of the original project and use Python script to automate the Demo project.

The unique dependencies of the business

Is due to the actual situation according to the business to the size of the statistical, by relying on tree is not entirely correct analysis of aar belongs to business, considering the changes in each version of the aar is lesser, so we are through the configuration file manually according to the actual situation will business aar belonging to the same group, the final output of the business size and a list of aar.

Local output results

Following the steps above, we have implemented a single line of Python script command at the terminal to automatically generate all business sizes:

The final results

In order to facilitate the monitoring and rapid output of each version of data, we made a simple and easy to use visual platform, through the remote server to perform packaging and finally upload the output data to the background, can automatically generate reports and send emails, greatly improving the efficiency of output reports.

Figure 1 Statistics of package sizes of different versions

FIG. 2 Business size curve

Figure 3 Aar package size details Of the version On the details page, you can view the size of each service and aar details, or compare versions to view the incremental size.

conclusion

By modifying aAPT source code and Gradle plug-in source code, the problem of package failure caused by lack of resources is solved. By obtaining the dependency tree, the Aar size data is automatically generated by using Python script in Demo project. Finally, the efficiency of package size report output is greatly improved through visualization platform.

For Demo project source code, wechat search attention “Yu Weiguo” public number reply “AAR” to obtain.