Dynamically Generating Dalvik Bytecode into a running Dalvik/Android application

后端 未结 5 972
我在风中等你
我在风中等你 2020-12-08 01:09

This question has been asked(and answered) many times about dynamically generating and loading java bytecodes at runtime into a running Dalvik VM, but is there any way to lo

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 01:31

    The Dalvik team would like to build a first-class runtime code generation library. We're tracking the feature request as Android bug 6322. Unfortunately, we have a very long list of performance and correctness issues, so I can't give you a timeline for when we'll spend time on this issue.

    There are some alternatives, but they will all take some work:

    • Run your application on a standard JVM and exercise all runtime code generation there. Dump the .class files from memory to files, and then run dx on those files. If you're quite sophisticated, you could integrate all of this work into your build.

    • Include the open source dx tool as a project library, and execute it programatically from within your application, possibly in your application's classloader. This will bloat your application's binary.

提交回复
热议问题