【背景】
希望实现:
在android环境中,如何去动态的,对于输入的一个java文件,
实时地去编译该java文件,(生成对应的class)
以及在android代码中,引用此编译后的java的class,实现调用其中的函数,引用其中的变量。
先去在NeatBeans中弄了个测试的java代码:/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package demo_eddl_method_code;
/**
*
* @author CLi
*/
public class Demo_eddl_method_code {
public static int getSum(int x, int y)
{
int sum = 0;
sum = x + y;
return sum;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x = 1;
int y = 2;
int gotSum = getSum(x, y);
System.out.println(gotSum);
}
}
希望可以在android代码中,将上述的代码,动态的编译,然后且在android代码中,可以调用到对应的函数getSum。
【折腾过程】
1.貌似从:
找到的:
好像是所要的。
但是其是用的java6中的库:
此处,不知道android中是否存在和是否能够正常使用。
2.后来折腾代码,结果期间出错:
3.参考:
找到:
看其介绍,其也还是利用了javax.tools的。所以,估计还是不行。
不过,也去试试是否可用:
结果也还是不行。
4.继续参考:
先去试试BCEL:
5.再参考:
去看看:
Trove
6.