问题
Recently I answered this question, where was described whole installation process of .apk
file to android phone. The one thing it was about using Dalvik VM
. And now I'm wondered is installation process is exactly same using ART
? What are the differences?
I mean the work of PackageManager, path, convertion to dex
format etc.
Googling didn't give much info, only about performance power, managing memory and something similar.
I would be very thankful if someone with knowledge could share this information.
回答1:
Android apps come in the .apk
file format, with Java classes converted into DEX
bytecode. The DEX
bytecode format is independent of device architecture and needs to be translated to native machine code to run on the device. This is the same for both the ART
and the Dalvik
runtimes.
The most significant change from Dalvik
to ART
is that Dalvik
is based on Just-in-Time (JIT
) compilation, while ART
is based on Ahead-of-Time (AOT
) compilation.
With the Dalvik JIT compiler, each time when the app is run, it dynamically translates a part of the Dalvik
bytecode into machine code. As the execution progresses, more bytecode is compiled and cached. On the other hand, ART is equipped with an Ahead-of-Time compiler. During the app’s installation phase, it statically translates the DEX
bytecode into machine code and stores in the device’s storage. This is a one-time event which happens when the app is installed on the device.
Performance
The most important benefit of ART
runtime over Dalvik
runtime is that the app runs faster on ART
. Because DEX
bytecode has been translated into machine code during installation, no extra time is needed to compile it during the runtime. The app starts faster as well when launched with ART
for the same reason.
Because Dalvik
requires extra memory for JIT
code cache, an app occupies a smaller memory footprint when it runs on ART
.
Battery Life
With Dalvi
k runtime, the JIT
compilation is CPU
bound. Because of AOT
compilation, ART
frees the CPU from translating DEX
bytecode to machine code during the app’s execution, thus reducing energy consumption. Using ART
leads to a longer battery life, which is the time interval when a battery recharging is needed.
Installation Time
Because the AOT
compiler translates DEX
bytecode into machine code during the app installation, an app takes longer to install on a device with ART
runtime. Considering the benefits of faster execution and shorter launch time we discussed in the previous section, this extra time which happens only once during the app’s installation is well worth it.
Storage Footprint
With ART
runtime, the AOT
compiler translates the app’s DEX
bytecode into machine code and stores it in the device’s storage. The pre-compiled binary occupies more space than the DEX bytecode. Thus results in a larger storage footprint comparing with Dalvik
runtime.
Summary
To this point we have introduced the new ART
runtime for Android. We also discussed its benefits and compromises, centralizing in its Ahead-of-Time compilation and performance improvement. Currently released for preview and still under active development and optimization, at this point of time we cannot provide a quantitative conclusion on how much performance gained by switching to ART Runtime
. One thing for sure is ART will replace Dalvik
as the Android runtime on the x86
based devices.
Source.
回答2:
In dvm architecture, at each time when the application launches the entire application byte code converted into dex and then execute the dex files. So when at each Time of launch same thing going to done, so to overcome this problem ART comes into picture. In ART while at the time of application installation only converts byte to Dex and then at every launch execute that same dex files, here no need to require conversion at each launch., so less time take to launch an app in ART compare to dvm.
来源:https://stackoverflow.com/questions/30442481/installation-process-of-apk-within-art-difference-from-dalvik-vm-installation