Android is the most popular mobile operating system in the world, but few people think about what technologies are behind its operation. If you've ever wondered what programming language is Android written inthe answer is not clear cut. This is a complex multi-level system, where each layer uses its own tools: from low-level C/C++ in the kernel to Kotlin and Java in the user interface.
In this article we will go into detail Let's look at:
- ๐น Android architecture and the role of each layer (from the Linux kernel to applications).
- ๐น Main programming languagesused in the system, and their purpose.
- ๐น How code is compiled Android applications and why it is important for performance.
- ๐น Evolution of technologies: from Java to Kotlin and new trends (Jetpack Compose, Rust).
If you developer, enthusiast or just a curious user - here you will find answers to questions that are rarely covered in standard guides.
1. Android architecture: layers and their purpose
Android is built on Multi-layer architecture, where each layer is responsible for certain tasks. This allows the system to remain flexible, secure and productive. Let's look at the key layers from top to bottom:
| Layer | Technologies/Languages | Functions |
|---|---|---|
| Apps | Kotlin, Java, C++, Dart (Flutter) | User apps (Google Play, Chrome, camera, etc.) |
| Application Framework | Java, Kotlin, C++ | API for accessing hardware (Wi-Fi, Bluetooth, sensors) |
| Libraries and Android Runtime (ART) | C, C++, Java bytecode | Code execution, graphics libraries (OpenGL, Skia) |
| Hardware abstractions (HAL) | C, C++ | Interface between the kernel and device drivers |
| Linux kernel | C, assembler | Memory management, processes, security |
Interesting fact: Android uses a modified Linux kernel, but is not a Linux distribution in the usual sense.. Google has replaced many standard components (for example, glibc to Bionicto optimize for mobile devices.
Why is this important? For example, when you see an error "kernel panic" on your smartphone screen, the problem lies precisely in this layer - the Linux kernel. And if the application crashes with a message "ANR" (Application Not Responding), the layer Android Runtime or the application code itself is to blame.
2. Android kernel: why Linux and how it is modified
The basis of Android is Linux kernel, written mainly in C interspersed with assembler for critical areas. Google chose Linux for several reasons:
- ๐ง Open source (GPLv2 license), which allowed it to be modified for mobile devices.
- ๐ก๏ธ Reliability and security: Linux has been used in servers and embedded systems for decades.
- ๐ง Support for multiple architectures (ARM, x86, RISC-V), which is critical for smartphones.
However, โpureโ Linux was not suitable for mobile devices. Google has made hundreds of changes:
- ๐ Low Memory Killer (LMK): Aggressive memory management to prevent lag.
- ๐ก Wake Locks: A mechanism to allow apps to "wake up" the device (for example, for push notifications).
- ๐ SELinux: Mandatory access control.
- ๐ฎ Binder IPC: Replacement standard interprocess communication (IPC) in Linux to a faster mechanism.
โ ๏ธ Attention: If you are installing a custom kernel (for example, to overclock the processor), make sure that it supportsSELinuxinEnforcingmode. Disabling SELinux for the sake of โperformanceโ will leave your device vulnerable to attacks.
An interesting point: in 2022, Google began experimenting with replacing parts of the kernel with Rust a language that guarantees memory safety. This should reduce the number of buffer overflow vulnerabilities. So far, Rust is only used in new modules (for example, in drivers for Pixel 6), but the trend is obvious.
Why doesn't Android use the standard Linux kernel?
Google has removed many components from the kernel that are unnecessary for mobile devices (for example, support for desktop file systems like ext4 in earlier versions). In addition, our own mechanisms were added, such as ashmem (anonymous shared memory) to speed up the Android Runtime.
3. Android Runtime (ART): how application code is executed
Before version Android 5.0 Lollipop (2014), applications were executed using Dalvik Virtual Machine (DVM). It was a virtual machine, similar to the JVM, but optimized for mobile devices. However, DVM had a serious drawback: it used bytecode interpretationwhich slowed down the launch of applications.
With the advent ART (Android Runtime) everything changed. Now application code compiled in advance (AOT - Ahead-of-Time) into native machine code during installation. This gives:
- โก Fast startup applications (no need to compile code on the fly).
- ๐ Less power consumption (the processor spends less resources on execution).
- ๐ก๏ธ Greater security (the code is checked at the compilation stage).
How does this work in practice? When you install an APK file, the system:
- Extracts
.dexfiles (Dalvik Executable) from the APK. - Converts them to
.oatfiles (Optimized ART) using compilerdex2oat. - Saves the compiled code in the cache (
/data/dalvik-cache).
โ ๏ธ Attention: If you manually delete files from /data/dalvik-cache (for example, through root access), applications will begin to recompile the next time you launch them. This may cause lags and increased battery consumption until the cache is restored.
It is interesting that ART supports also JIT compilation (Just-In-Time) for dynamic optimization of code at runtime. This is used, for example, for "hot" replacement of methods in debug mode (Android Studio Profiler).
If your device is slow after updating Android, try clearing the ART cache. To do this, go to Settings โ Storage โ Cache data and select "Clear cache". This will force the system to recompile applications from scratch, which sometimes solves performance problems.
4. Programming languages in Android: what is used where
Android is not a monolith written in one language. Different parts of the system use different technologies. Here are the key languages and their role:
๐น C and C++: the basis of productivity
Most of them low level code Android is written in C low-level code C++:
- ๐ฅ๏ธ Linux kernel and device drivers.
- ๐ฎ Graphics libraries:
OpenGL ES,Vulkan,Skia(for UI rendering). - ๐ Audio stack:
AudioFlinger,OpenSL ES. - ๐ฑ Android Runtime (ART) and virtual machine.
๐น Java and Kotlin: application development
Since the creation of Android (2008), the main language for applications was Java. However, in 2017, Google announced Kotlin preferred language for development. Why?
- ๐ Concise syntax: Kotlin requires 40% less code for the same tasks.
- ๐ก๏ธ Null Safety: protection from
NullPointerExceptionat the language level. - ๐ 100% compatibility with Java: you can gradually migrate old projects.
Example code in Kotlin vs Java:
// JavaButton button = findViewById(R.id.my_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_SHORT).show();
}
});
// Kotlin
myButton.setOnClickListener {
Toast.makeText(this, "Clicked!", Toast.LENGTH_SHORT).show()
}
๐น Other languages in the Android ecosystem
- ๐ฆ Rust: Used in new parts of the kernel and for critical components (for example, in Android 12 for processing media codecs).
- ๐ฏ Dart: language for Flutter a framework from Google for cross-platform development.
- ๐ Python: sometimes used for automation scripts (for example, in Android Things for IoT).
Kotlin is not a replacement for Java, but an evolution. Google does not prohibit the use of Java, but all new APIs and tools (for example, Jetpack Compose) are optimized for Kotlin.
5. How an Android application is compiled: from code to APK
The process of building an Android application is a complex puzzle that involves several compilers and tools. Let's look at the main stages:
- Compilation of source code:
- ๐ Kotlin/Java โ bytecode (
.class-files). - ๐ง C/C++ โ native libraries (
.so-files).
- ๐ Kotlin/Java โ bytecode (
Java/Kotlin bytecode is converted to .dex-files (Dalvik Executable) using the tool d8 (or legacy dx).
All XML markup, images and strings are packaged into resources.arsc.
All files are combined into one .apk (in fact, this is a ZIP archive).
APK is signed with a digital certificate and passes through zipalign to optimize access to files.
Important nuance: since Android 8.0 Oreo Google has introduced mandatory verification 64-bit support for applications on Google Play. This means that if your application contains native libraries (.so), they must be compiled for arm64-v8a, x86_64 other 64-bit architectures.
โ ๏ธ Attention: If you are developing an application with native code (C/C++), make sure that build.gradle all necessary ABIs (Application Binary Interface) are specified, otherwise your application will not work on some devices or will take up extra memory due to the inclusion of unnecessary libraries.
Are they used? 64-bit libraries (if there is native code)?
Is the APK signed with a release key (not debug)?
Tested on devices with different versions of Android?
Is the APK size optimized (is unnecessary code removed)?
-->
6. Evolution of technologies: from Java to Jetpack Compose
Android has not stood still. Over the past 15 years, the platform has undergone a lot of changes, and programming languages are no exception. Here are the key milestones:
| Year | Event | Impact on development |
|---|---|---|
| 2008 | Output Android 1.0 | The main language is Java. Applications are compiled into bytecode for Dalvik. |
| 2014 | Android 5.0 Lollipop: transition from Dalvik to ART | Speed up application launch on 20-50%. |
| 2017 | Kotlin becomes an officially supported language | Simplifying code, reducing the number of errors. |
| 2019 | Exit Jetpack Compose (alpha version) | Declarative approach to creating UI instead XML. |
| 2021 | Android 12: the beginning of using Rust in the core | Increasing security by protecting against memory vulnerabilities. |
One of the most noticeable trends in recent years is Jetpack ComposeThis is a modern framework for creating interfaces that replaces. outdated XML + View. Code example on Compose:
@Composablefun Greeting(name: String) {
Text(text = "Hello, $name!", modifier = Modifier.padding(24.dp))
}
Advantages of Compose:
- ๐จ Declarative syntax: you describe what what should be on the screen, and not how it should be drawn.
- ๐ Reactivity: automatic update of the UI when data changes.
- ๐ฑ Cross-platform: the same code works on Android, iOS and desktop (via Compose Multiplatform).
However, Compose also has disadvantages: it requires Android 5.0+ and can increase the size of the APK due to additional libraries. However, Google is actively promoting it as the future of Android development.
7. Myths and misconceptions about languages in Android
There are many myths floating around Android technologies. Let's look at the most common ones:
๐น "Android is entirely written in Java"
This is not true. Java/Kotlin are used only for the top level (applications and framework). drivers and critical components are written in C/C++, and in new versions it appears Rust.
๐น "Kotlin is slower than Java"
In practice, the differences in performance between Kotlin and Java no. Both languages are compiled into the same bytecode and then into native code via ART. Kotlin may even be faster due to its more concise syntax, which makes it easier for the compiler to optimize.
๐น "Native code (C++) is always faster. JavaScript data-i="248">๐น "Android is just Linux with a shell"
That's right not always. For computationally intensive tasks (for example, video processing or 3D graphics), C++ is indeed preferable. But for typical UI tasks the difference is minimal, and development in Java/Kotlin is easier and safer.
๐น "Android is just Linux with a shell"
Although Android uses the Linux kernel, is not a regular Linux distributionAndroid:
- ๐ซ There is no standard shell (
bash,zsh). - ๐ซ There is no support for many Linux utilities (
grep,sedetc.). - ๐ซ Own libraries are used (
Bionicinsteadglibc).
Therefore, porting Linux applications to Android "out of the box" will not work - you need adapt them to a specific environment.
FAQ: Frequently asked questions about languages in Android
Is it possible to write Android applications in Python?
Technically yes, but with reservations there are frameworks like Kivy or BeeWare, which allow you to create Android applications in Python. However:
- ๐ข Performance will be lower than that of native applications.
- ๐ฆ The APK size will increase due to the inclusion of a Python interpreter.
- ๐ง Not all Android APIs are available from Python.
For simple utilities or prototypes this is suitable, but for serious projects it is better to use Kotlin/Java.
Why did Google switch from Java to Kotlin?
Main reasons:
- Security: Kotlin eliminates many common errors (for example,
NullPointerException). - Conciseness: less template code (boilerplate).
- Modern features: coroutines for asynchronous programming, expanding functions, etc.
- Google support: all new tools (Jetpack Compose, Room) are optimized for Kotlin.
At the same time, Java has not gone away - millions of lines of code in Android are written in it, and they will be supported for a long time.
Is it possible to replace ART with another virtual machine?
Theoretically yes, but in practice it is extremely difficult. ART is deeply integrated into Android, and its replacement will require:
- ๐ง Modifications of the kernel and libraries.
- ๐ฑ Recompilation of all system applications.
- ๐ก๏ธ Bypassing security mechanisms (for example,
SELinux).
The only known case is a project MicroGthat is trying to create an alternative ecosystem for Android, but it does not replace ART, but works on top of it.
What languages are used to develop custom firmware (for example, LineageOS)?
Development of custom firmware affects all layers of Android, so they are used:
- C/C++: to modify the kernel, HAL and native libraries.
- Java/Kotlin: to change system applications (for example,
SettingsorSystemUI). - XML: to edit interface markup.
- Makefiles: to build the firmware via
Android.mkorBlueprint.
Example command for building LineageOS:
source build/envsetup.sh
brunch [device_codename]
Why do some applications require 64-bit support?
C Android 8.0 Oreo Google has obliged developers to provide 64-bit versions native libraries (.so). This is due to:
- โก Performance: 64-bit processors work more efficiently with large amounts of data.
- ๐ Security: protection against attacks that exploit vulnerabilities of 32-bit code.
- ๐ฑ Future compatibility: new processors (for example, Apple M1 or Qualcomm Snapdragon 8 Gen 2) are optimized for 64-bit computing.
If the application does not have a 64-bit version, Google Play will not allow you to download it to devices with Android 9.0+.