Nils
Nils

Reputation: 1715

Load and execute precompiled code (oat file) dynamically

Since Google removed "openDexFile(byte[] fileContents)" in newer Android versions, we are looking for a replacement here, and in addition we would prefer to use precompiled code (cf. dex2oat), too.

Is anyone aware of a function to perform that task? We don't want to store the file on the disk, too.

What about replacing the code of an app in memory maybe? Might this be possible under the new ART VM? I'm looking for further information on this topic. I know it was possible with the former Dalvik VM.

Any help is appreciated. Thanks.

Upvotes: 2

Views: 1325

Answers (1)

JesusFreke
JesusFreke

Reputation: 20262

In general, you can't load precompiled odex/oat files. These files are heavily dependent on the exact framework that is used when they are compiled, so they're not portable between devices.

You can load a dex file dynamically on both dalvik and art using DexClassLoader. See, e.g. http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

Upvotes: 2

Related Questions