What is needed to run ELF binaries compiled from Android APKs?
A simple hello world app which does nothing except printing Hello World! (no animations, no sounds, no menus), running on Android 9 device:
30+ files, anonymous inodes and UNIX sockets explicitly.
500+ memory-mapped files from
- Communicates, at least, to Surface Flinger (through Window Manager in
system_server) to display something on screen. There can possibly be more IPCs (Binders or others).
- Needs Activity Manager, Package Manager and possibly other services running in
system_server which manage app's classes related to activity creation and permissions.
zygote process running to fork VMs for
system_server and the app itself.
So all of these requirements must be fulfilled to run ELF binary (shared object:
/data/app/com.ravipatel.helloworld.test-*/oat/arm64/base.odex) compiled from APK.
As a comparison, a hello world Java program compiled with GCJ dynamically links to less than 5 libraries. While a similar C program (statically linked) has no runtime dependencies except the required architecture.
I guess it created a Dalkiv process in 'Linux' kernel which was simply a VM that ran the
No. Dalvik wasn't a Kernel-based Virtual Machine (KVM; if that's what you mean). Both Dalvik and ART are Process VMs which run in userspace.
For ART, the dex bytecode is compiled into instructions in the processor's architecture (happens during the installation process).
It's profile-guided, rarely happens during the installation process.
/runtime? Is it a program, a library?
Runtime is an environment in which programs written in a specific language run. ART is a runtime for Java. It mainly consists of native executable binaries / shared libraries (including a VM / interpreter / JIT compiler and OAT compiler) and standard Java class libraries (mostly in the from of
.jar files) saved in
Other well-known example is Java Runtime Environment (JRE) by Oracle/Sun which is found on mostly PCs.
Is Android Runtime something that is linked together with the ELF binary generated from
Is this ELF binary simply launched as a Linux process?
No. The ELF binary compiled from
.dex file in APK is not an executable but a shared object. So it needs to be loaded in memory along with other dependencies by some other process, which is ART (VM).
So suppose I wanted to run this ELF binary on Linux. Besides
binder kernel modules, what more would I need? Which libraries do this ELF binary require?
First of all you cannot run the ELF binary on a non-Android Linux system because the binary is not a statically linked executable. But even if it is, there are even bigger constraints, particularly Android's hardware abstraction.
ashmem are IPC mechanisms. They make sense only if the processes to whom the app wants to communicate also exist, which is not the case. With Linux based Java SDKs it's relatively easy to achieve.