Search code examples
androidnative-codefile-accessandroid-runtime

Android ART - Usage of .oat file in /dalvik-cache/?


while playing around with Android ART and the "native" code file .oat/.elf which is created at the app installation process, I did notice something odd.

For my understanding, if the device is using ART (Android >= 5.0), the app will start with the compiled oat file (/data/dalvik-cache/arm64/).

Thats why I was kinda surprised when checking the used fd's of an app and did not find the file there. Only the normal apk (/data/app//base.apk) is listed there.

Check this output of my "ls -l /proc/PID/fd"

enter image description here

So I thought maybe it's just not listed there. So I did exchange the oat file of that app by myself by compiling another classes.dex with the dex2oat tool.

So even after changing the file, the app starts normally without any strange messages or errors (also in logcat).

What is the explanation for this? What is the detailed process Android does when starting an app under ART?

I hope someone can clear that up for me. Thanks a lot.


Solution

  • Based on @Paschalis comment, I investigated here and the oat file is indeed memory mapped on Android 5.0 devices (emulator):

    a6af4000-a6af9000 r--p 00000000 1f:01 7366 /data/dalvik-cache/x86/data@[email protected]@[email protected]

    Check via:

    cat /proc/<PID>/maps | grep dex

    Sadly this isn't true anymore for Android 6.0 devices (Nexus 5 & arm-Emulator).

    The odex file is within the /data/app/<APP>/oat/<ARCHITECTURE>/ folder as 'base.odex`

    /data/app/app.app.works-1/oat/arm/base.odex

    I still haven't found a valid reference for this, it is based on experiments and observations