问题
Currently, it's possible to dynamically load .dex
classfiles into Android's Dalvik VM. This could probably also be used for dynamic code generation at runtime.
Is this still possible with the upcoming ART runtime?
回答1:
It seems to work just like it did with Dalvik.
Thanks to matiash for referencing the I/O 2014 talk! I've watched the video recording of it, and here is what the developers have to say on runtime code loading (taken from the transcript):
[Question from the audience:] So I was wondering how ART is going to jive[?] with byte code injection that might happen right after compilation or even at runtime.
[...]
[Answer by Ian Rogers:] So the model that Dalvik has and ART continues is that for class loaders, we have to have everything that the class loader has backed up by a file. So Dalvik never had supports for the kind of doing end memory injection of instructions, and so on.
If you have a file on the disk, then this is something we can do ahead of time compilation for and put into our cache so that we're not regenerating it all of the time. So basically, it works the same way as with Dalvik.
来源:https://stackoverflow.com/questions/23739261/does-android-art-support-runtime-dynamic-class-loading-just-like-dalvik