java – android platfrom,Dalvik字节码或本地机器代码过程中的哪种代码?

我不太确定在
android平台上的linux进程中加载​​了哪种代码.

如果android采用Dalvik,该进程包含Dalvik VM和应用程序的代码,是Dalvik字节码形式的代码吗?如果是,代码是否与.apk文件中的classes.dex相同?

如果android采用Android Runtime(ART),因为classes.dex已被翻译成本机机器码,所以我认为Linux进程中的应用程序代码不是Dalvik字节码,而是本机机器码.如果我的理解是对的,那么Dalvik VM仍然包含在这个过程中吗?

最佳答案 从Android 5.0(Lollipop)开始,Dalvik已完全被Android Runtime(ART)取代,后者处理原生二进制文件.

Verifying App Behavior on the Android Runtime

The Android runtime (ART) is the default runtime for devices running Android 5.0 (API level 21) and higher.

At install time, ART compiles apps using the on-device dex2oat tool. This utility accepts DEX files as input and generates a compiled app executable for the target device

更具体地说,Dalvik推广使用odex文件,这些文件是Dalvik的dex文件的预处理优化版本,可以解释或JIT编译.

ART促进了ELF文件的使用,ELF文件是一种通用格式,用于指导将某些功能和对象链接到设备的本机指令,并在安装时执行.

Wikipedia – Android Runtime

Unlike Dalvik, ART introduces the use of ahead-of-time (AOT) compilation by compiling entire applications into native machine code upon their installation.

ART uses the same input bytecode as Dalvik, supplied through standard .dex files as part of APK files, while the .odex files are replaced with Executable and Linkable Format (ELF) executables. Once an application is compiled by using ART’s on-device dex2oat utility, it is run solely from the compiled ELF executable

Executable and Linkable Format – Applications

Android uses ELF .so (shared object) libraries for the Java Native Interface. With Android Runtime (ART), the default since Android 5.0 “Lollipop”, all applications are compiled into native ELF binaries on installation

ART不包含Dalvik的实例,虽然大多数都是兼容的,但是提到了不支持Dalvik支持的某些功能.

Verifying App Behavior on the Android Runtime

However, some techniques that work on Dalvik do not work on ART. This document lets you know about things to watch for when migrating an existing app to be compatible with ART. Most apps should just work when running with ART.

点赞