How to Use APK Analyzer in Android Studio

Written by leonidivankin | Published 2022/10/14
Tech Story Tags: android | android-studio | android-app-development | apk-analyzer | plugins | android-studio-plugin | mobile-app-development | app-development

TLDRThe Apk Analyzer is quite a powerful tool that should not be ignored during development. It is especially useful in cases where: Observing the result of obfuscation. Examination of the resulting AndroidManifest.xml. Detection of abnormal file sizes. Studying the compiled resources.via the TL;DR App

Android Studio introduces another quite useful tool that allows you to see what the resulting apk has produced - the Apk Analyzer.

Create an ApkAnalyzerActivity, insert the following code, and run the project:

class ApkAnalyserActivity : AppCompatActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
   }
}

Run the Apk Analyzer and select the current app-debug.apk:

If b didn't find it on its own, find it yourself at the following address:

A window with a list of files will open:

In it, you can find the familiar folders and files: res, assets, AndroidManifest.xml, as well as classes.dex files and folders with libraries, such as okhttp3. For this article, I specially inserted ApkAnalizerActivity into a large project, so that you can see the difference.

Go to the build.gradle file, insert multiDexEnabled falseand restart the project:

Note that there are fewer classes.dex files. In one of these files, at the package address of the current ApkAnalyzerActivity, you can find it.


Right-click it and chooseShow Bytecode:

You can view the bytecode of the current ApkAnalyzerActivity here:

Select AndroidManifest.xml from the list and view the contents of this file:

Note that AndroidManifest.xml is not only a version of the current application but a mortal version of the current application and all the modules and libraries that are part of it.

Go back to the build.gradle file, enable obfuscation (change the minifyEnabled true line), restart the project and open Apk Analyzer:

Click on any classes.dexfile:

Note that all files and methods have changed their names because of obfuscation and are now a random set of characters.

Also, note the rightmost column with the file sizes:

You can use this column to monitor file size and keep track of anomalies, such as when a file is too heavy.

Conclusion

The Apk Analyzer is quite a powerful tool that should not be ignored during development. It is especially useful in cases where:

  1. Observing the result of obfuscation.
  2. Examination of the resulting AndroidManifest.xml.
  3. Detection of abnormal file sizes.
  4. Studying the compiled resources.



Written by leonidivankin | I'm an android developer
Published by HackerNoon on 2022/10/14