The APK Analyser, which comes with Android Studio, provides adequate information on the structure of the APK once the build is over. If you use the APK Analyser, it can help reduce the debugging time spent. The app has DEX files along with other resources that can reduce the APK size.
The APK Analyser allows developers to go through the content of the APK files they wish to cover. It can provide you with several useful information of the app, including the app size. There is a list of files and folders which you can sort according to the descending order. Once you drill down the folder, you can see the resources which take up the space in the APK.
The APK Analyzer can help you achieve these objectives on Android Studio:
- Know structure of DEX files.
- Do a comparison of two app bundles or APKs.
- Check the last versions of the files in the Play Store app faster.
- See the relative and absolute size of the files present in the app.
You can access APK Analyzer for an open project. There are three ways to achieve this:
- At the Project window, move to Project perspective. Then, at the build/output/apks/ directory, double click the APK.
- Drag the app bundle or APK into the Editor window.
- At the menu bar, choose Build > Analyze APK. Then select your APK or app bundle.
Viewing the size and file information
The APKs adhere to the ZIP file format. APK Analyzer shows each folder or file like the entity which includes the expansion functionality that can help find the way into folders. The entities’ hierarchy shows details of the form of the folders and files in the APK.
- The APK Analyzer will exhibit every entity’s download file and raw file sizes.
- The Raw File Size is the size of the unzipped part on the disk.
- The Download Size signifies the projected compressed size presented by Google Play.
- The percentage of the Total Download Size shows the percentage of the total download size of the APK as presented by the entity.
If the Android development project has several AndroidManifest.xml files or has libraries to deliver a manifest file, they can be combined into a single file in the Play Store app. The manifest file is a binary file in the app bundle or APK. The XML format is recreated and displayed when it is chosen in the APK Analyzer.
The viewer helps to know any changes made in the app at the build stage. Address in what way the AndroidManifest.xml file from the application library varies based on what was amalgamated into the final file.
The viewer gives few lint capabilities.
Viewing the DEX files
The DEX file in the APK Analyzer allows quick access for information strewn across the DEX files in the Play Store app. Declaration counts, class, total reference, package, etc., are offered within the viewer. It can help decide whether it is required to apply multidex or by what means you can eliminate dependencies to go under the 64K DEX threshold.
We will discuss about the Defined Methods and Reference Methods columns
- Referenced Methods column: Counts all the methods referenced using the DEX file. It usually covers methods defined in the dependency libraries, code, and methods specified in standard Android and Java packages. The methods are considered for the 64k method threshold in every DEX file.
- Defined Methods column: Covers only those methods specified in one of the DEX files. It is a subset of the Referenced Methods. Remember that code shrinking and minification can significantly alter the contents in a DEX file after compiling the source code.
Filtering tree view of the DEX file
The APK Analyzer offers filters to view the contents of the chosen DEX file. Developers can use filters to showcase all fields and methods inside the class.
They must undertake the following:
- At the File list, you must choose the classes.dex file.
- At the Class list, you must route to and choose a class.
- Next, you must expand the chosen class.
- Toggle the Show fields for hiding or showing class fields.
- Toggle the Show methods for hiding or showing class methods.
- Now, you must toggle “Show all referenced methods or fields” for hiding or showing the referenced classes, packages, fields, and methods. For the tree view, the references are for the italicised nodes that don’t have a definition in the chosen DEX file.
Comparing the files
Developers can use the APK Analyzer to compare the size of the entities across two different app bundle files or APKs. It can help you understand during Android development why the Play Store app size increased compared to an earlier version. You must do these activities before publishing an updated app:
- Load the app version you must publish to the APK Analyzer.
- At the top-right corner, click on the “Compare With” tab.
- At the Selection dialog box, find the version that was last published. Click OK.
- A window like the one below appears. It can help you evaluate the impact the update can have on the users.