Table of contents |
|
How Does Android App Work? |
|
Step 1: Building the APK File |
|
Step 2: Deploy the Application |
|
Step 3: Running the Application |
|
Summary of Android App Execution Process |
|
Developing an android application involves several processes that happen in a sequential manner. After writing the source code files, when developers click the Run button on the Android studio, plenty of operations and process starts at the backend. Every operation happening in the background is a crucial step and are interdependent. The IDE builds all the application files, make them device compatible in order to deploy, and assure that the application runs successfully on the device. This article broadly explains each and every critical step involved in the journey of an android app, from the IDE files to a working device application.
Run buttonThe android application source files are written in either Java (*.java files) or Kotlin (*.kt files) programming languages. Although the syntax of writing code in these two languages differs, their compilation processes are quite similar. Both languages produce code that can be compiled into Java byte-code, which is executable on the Java Virtual Machine (JVM).
The Java class (*.class) file generated in the previous step is designed to run on the Java Virtual Machine (JVM) since it contains standard Oracle JVM Java byte-codes. However, this format is not compatible with Android devices. Android utilizes its unique byte-code format called Dalvik byte-code.
Java regular code:
At the core of Android app launches lies the Zygote process, acting as the progenitor to all Android applications. When a user triggers an app launch, this process springs into action. Essentially, the Zygote process, a specialized Android OS entity, facilitates code sharing among diverse instances operating on Android virtual devices (Dalvik/Android Runtime). It preloads essential resources, classes, and code libraries into its memory space, ensuring swift and efficient app launches. Upon receiving a request to initiate a new application, the Zygote process clones itself using the fork system call (a characteristic of the Linux-based Android system) and kickstarts the new app. The preloaded resources play a pivotal role in expediting app launches within the Android ecosystem.
Zygote ProcessUpon installing a new application, Android undertakes the optimization of app data, culminating in the creation of an OAT (Optimized Application Technique) file. This file, generated by the Android OS, accelerates application loading times significantly. The process commences with the extraction of the classes.dex file housed within the .apk application package. Subsequently, the classes.dex file is segregated into a distinct directory, where Android undertakes the compilation of Dalvik byte-code through an ahead-of-time (AOT) conversion into native machine code. By leveraging this native OAT file, the Android system enhances user experience through rapid and seamless application loading.
.apk, ahead-of-time (AOT, also as OAT)Prior to the advent of AOT, the dexopt tool was utilized to transform .dex files into .odex files (optimized DEX) containing refined byte-code. However, with AOT's integration into Android, the dex2oat tool now converts and optimizes .dex files into OAT file formats housing machine code inscribed in ELF (Executable and Linkable Format). This native library is subsequently linked to the application process's memory. OAT files are conventionally stored in the directory: /data/dalvik-cache/.
Upon completion of the above processes, the Android application will initiate, and the primary activity will become visible on the device screen.