在Android上运行时编译字符串为code [英] Compiling String as Code during Runtime on Android

查看:126
本文介绍了在Android上运行时编译字符串为code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用的东西试过JANINO在Android和得出的结论是,他们根本就没有的Dalvik虚拟机中运行。

I have tried using things on Janino on Android and have concluded that they simply do not work within the Dalvik VM.

所以,我只是要问一个简单的问题:在安卓,是否可以运行的应用程序中使用过程中编译包含字符串code。如果是这样,是否有让我这样做的和/或你可以分享如何做一个code例如任何库?

So Im just going to ask a simple question: On Android,Is it possible to compile a string containing code during runtime for use within the app. If so, are there any libraries that let me do so and/or can you share a code example of how to do it?

有关的(一个很简单的)的例子,如果我有一个String对象,它包含以下内容:

For (a very simple) example, If I had a String object containing the following:

public class Adder{

     int x;
     int y;

     public Adder(int x,int y) {
     this.x = x;
     this.y = y;
     }

     public int add() { return x+y;}

}

作为字符串中的一个巨大的线。有没有一种方法,我可以处理它通过反射API来创建一个加法对象的实例,这样我就可以叫添加()的方法,比方说,?

As one giant line of string. Is there a way I can process it to create an instance of an Adder object so I can call the add() method, say, via the Reflection API?

修改 我试过BeanShell的跨pretation,但它被证明是过于缓慢。林寻找的东西更快一点,就像JANINO

Edit I've tried beanshell interpretation but it proved to be too slow. Im looking for something a little faster, just like Janino

推荐答案

ImagePlayground 是一个开源的Andr​​oid应用程序,这是否使用 Dexmaker 和一个自定义的编程语言。

ImagePlayground is an open source Android app that does this using Dexmaker and a custom programming language.

这篇关于在Android上运行时编译字符串为code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆