Android Application Package – Android APK

Android Application Package, popularly known as APK, is the executable file of an android application that can be installed on any android device. You must have operated Windows or Linux operating systems. When you need to install any application in windows, then the usual file format of that application is .exe. While when you see Linux systems, then the standard install package is of the format .deb. Similarly, when you wish to install some applications in android, then we use .apk files.

So through this article, we will try to understand what APK files are and how we generate them. Along with this, we will also see the contents of an APK file.

What is the Android Application Package(APK)?

Android Application Package or APK can be thought of as a package installer file for the Android operating system. In any other application you develop, the end product of that application is APK. Using the APK, the users can install your application on their device and can operate it.

Let’s recall Gradle’s process to convert your source code into an executable APK file. We very well know that Android comes up with a Dalvik Virtual Machine that has a Dex compiler. The Dex Compiler compiles your source code into a .dex file, and then APK Packager packages this file into an executable APK file.

How to use Android Application Package?

Android Application Package, as we know, is an installer package for the android system, and users can use our application only after installing the APK. Along with this, android applications can also be used for several other stuff as shown below:

  • It allows you to convert your source code, resources, and assets to one executable file.
  • This is used to distribute your developed applications to the user.
  • It can be signed with certificates, which helps us verify the publisher’s authenticity before installing the application.
  • It can be uploaded on Google Play Store and other app stores from where users can download it and use it.
  • This contains details about the developer, resources, and the permissions it requires from the users.

Content of an Android Application Package

Android Application Package is like an archive or package which is quite similar to the JAR packages. Android Application Package contains information about the application, and if we extract it, then we can see the below files and directories:

1. META-INF Directory: The META-INF directory consists of the metadata of the applications. Files like Manifest, certificates, and resources list are present in this directory.

2. lib: The lib directory consists of several directories and the compiled application code, which is platform-independent. Below are the directories that are present in the lib directory:

  • armeabi: armedi consist of compiled codes for the ARM Processors
  • armeabi -v7a: armeabi -v7a consists of compiled codes for the ARM Processors above ARM V7
  • armeabi -v8a: armeabi -v8a consists of compiled codes for the ARM Processors above ARM V8
  • x86: x86 consists of the compiled codes specific to x86 processors only
  • x86_64: x86_64 consists of the compiled codes specific to x86_64 processors only
  • Mips: Mips consist of compiled codes specific to Mips processors only

3. res: The res directory consists of the resources that were not able to compile while generating the resources.arsc file.

4. assets: The assets directory consists of the assets that it receives from the Asset Manager.

5. AndroidManifest: AndroidManifest file contains the app details like app name, app icon, declarations of the app components, and the permissions required for the application to run correctly.

6. classes.dex: These are the files of the form .dex and are executable by the Android Dalvik Virtual Machine and Android Runtime.

7. resources.arsc: All the XML resources are compiled and stored in the resources.arsc file.

How to install APK on your Android Device?

Android Application Package or APK can be easily installed on most Android devices by following the below procedure.

First of all, you need to download the APK file of the application you intend to run and then go for the following steps:

1: Click on the APK file.

2: Your device will prompt you to allow installing apps from unknown sources. Just confirm it if you trust the source.

3: Now, the package manager will load.

4: The Package Manager will show you the permissions which the app requires. You simply need to agree to it and click on next.

5: Now, your app will start installing. It takes around 1 minute to install the application depending upon the size of the APK and the device performance.

6: Now click on Finish and enjoy your application.

How to generate an APK file in Android Studio?

Android Application Package can easily be generated by using Android Studio. There are two types of APK that you can generate using Android Studio. One is your debug APK that is used for debugging purposes. Usually, the debug APK is distributed to a particular set of users for testing purposes. The other one is the signed APK that is used for publishing your application on Play Stores.

If you want to know more about signed APKs and how you can publish them on Google Play Store, refer to the article below.

Now, let’s see how you can generate debug APK using Android Studio by following some simple steps:

1: Open your Android Project present in the Android Studio.

2: Now navigate to Build and click on Generate Bundle(s)/APK(s) as shown below in the figure.

3: Now after pressing on Build APK(s), your Gradle will start building the APK file for you, as shown below.

4: After the build is successful, you will get a notification that your build is successful and locate your APK file.

5: Simply click on the locate option. It will take you to the directory where your debug APK is present.

If by any chance, you miss clicking on that, then you can manually browse your project folder to get the debug APK.

In my case the file path is:

D:\AndroidStudioProjects\FirstApplication\app\build\outputs\apk\debug

You can similarly replace your application and get the debug APK as shown below.

Now use this debug APK and install this application on your android device.

Summary

Through this article, you came across the Android Application Package. You saw what Android Application Package is and how it can install applications on the user device. Later on, you saw the contents of an Android Application Package. Moving forth, you came across the steps to install APK on any android device. Finally, you saw the steps to generate an APK using Android Studio.