paint-brush
How to Use APK Analyzer in Android Studioby@leonidivankin
2,788 reads
2,788 reads

How to Use APK Analyzer in Android Studio

by Leonid Ivankin
Leonid Ivankin HackerNoon profile picture

Leonid Ivankin

@leonidivankin

I'm an android developer

October 14th, 2022
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The 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.

Company Mentioned

Mention Thumbnail
Super
featured image - How to Use APK Analyzer in Android Studio
1x
Read by Dr. One voice-avatar

Listen to this story

Leonid Ivankin HackerNoon profile picture
Leonid Ivankin

Leonid Ivankin

@leonidivankin

I'm an android developer

Learn More
LEARN MORE ABOUT @LEONIDIVANKIN'S
EXPERTISE AND PLACE ON THE INTERNET.


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:

image

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

image

A window with a list of files will open:


image

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:

image

image

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:


image

You can view the bytecode of the current ApkAnalyzerActivity here:


image

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


image

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:


image

Click on any classes.dexfile:

image

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.


L O A D I N G
. . . comments & more!

About Author

Leonid Ivankin HackerNoon profile picture
Leonid Ivankin@leonidivankin
I'm an android developer

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Glarity
Unni
Coffee-web
Hashnode
Learnrepo
X REMOVE AD