Android Studio: APK Analyzer

apk-filter-tree-view_2x

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

Analyze your build with APK Analyzer | Android Developers

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.

Viewing AndroidManifest.xml

AndroidManifest.xml: everything you need to know - Android Authority

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 you need 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

Filterable TreeView - CodeProject

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:

  1. At the File list, you must choose the classes.dex file.
  2. At the Class list, you must route to and choose a class.
  3. Next, you must expand the chosen class.
  4. Toggle the Show fields for hiding or showing class fields.
  5. Toggle the Show methods for hiding or showing class methods.
  6. 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:

  1. Load the app version you must publish to the APK Analyzer.
  2. At the top-right corner, click on the “Compare With” tab.
  3. At the Selection dialog box, find the version that was last published. Click OK.
  4. A window like the one below appears. It can help you evaluate the impact the update can have on the users.

FAQs

1. What is the APK Analyzer in Android Studio?

The APK Analyzer is a tool within Android Studio that allows developers to inspect the contents of an Android Package (APK) file. It provides detailed information about the APK’s structure, including the sizes of the components, the resources used, and the AndroidManifest.xml file. This tool helps developers optimize their applications by identifying areas to reduce the APK size, improving app performance and download times.

2. How do I open the APK Analyzer in Android Studio?

To open the APK Analyzer, follow these steps:

  • Launch Android Studio and select “Profile or debug APK” from the welcome screen, or click “File” > “Profile or Debug APK” from the menu bar if you have a project open.
  • Navigate to the APK file you want to analyze and select it. The APK Analyzer will open and display the contents of the APK.

3. What can I learn from analyzing my APK?

By using the APK Analyzer, you can gain insights into:

  • The size of each component of your APK, including dex files, resources, assets, and libraries.
  • The presence of unused resources or code that could be removed to reduce APK size.
  • The detailed structure of the dex files, including class definitions, methods, and fields.
  • AndroidManifest.xml contents, such as permissions, activities, and service declarations.
  • Resource usage, including drawable resolutions and values for different configurations.

4. How can the APK Analyzer help me reduce the size of my APK?

The APK Analyzer can help identify specific areas where you can reduce the size of your APK by:

  • Highlighting unused resources and assets that can be removed.
  • Showing the impact of third-party libraries on your APK size and identifying potential alternatives with a smaller footprint.
  • Suggesting ways to optimize images and other resources for size without compromising quality.
  • Revealing the parts of your code that take up the most space, guiding potential refactoring or removal of unnecessary code.

5. Can I compare two APKs using the APK Analyzer?

Yes, the APK Analyzer allows you to compare two APKs to see the differences in size and content. This feature is particularly useful for understanding how changes between app versions affect the APK size and structure. To compare two APKs, open the APK Analyzer and click on the “Compare with…” button, then select another APK file for comparison.

6. How does the APK Analyzer display the sizes of files and folders?

The APK Analyzer displays the sizes of files and folders in two ways:

  • Raw File Size: The actual size of the file or folder.
  • Download Size: An estimate of the size the file or folder will take up after compression when being downloaded from the Google Play Store. This view helps you understand the impact of your APK’s components on download times for users.

7. Are there any limitations to what the APK Analyzer can show?

While the APK Analyzer provides comprehensive details about an APK’s structure and contents, it might not provide specific insights into runtime performance or detailed debugging information. For performance analysis and debugging, you would use other tools in Android Studio, such as the Android Profiler or Debugger.

Leave a Reply

Your email address will not be published. Required fields are marked *