6

Is there a way to fully integrate Python with Java code on Android platform?

Yes, I saw the question about running Python on Android and Android Scripting Environment (ASE).

But that doesn't seem to be enough (correct me if I am wrong). I wanted to be able not only to invoke a Python script from within Java code, but have a full integration. The feature I need the most is the ability to have a state of execution of python code saved and be able to run several parts of code on demand against the same execution state.

On JavaSE I would rely on Jython. I believe its simplest example shows it all (and some other features too, like something I would call variable state introspection):

    // http://www.jython.org/archive/21/docs/embedding.html
    PythonInterpreter interp = new PythonInterpreter();

    System.out.println("Hello, brave new world");
    interp.exec("import sys");
    interp.exec("print sys");

    interp.set("a", new PyInteger(42));
    interp.exec("print a");
    interp.exec("x = 2+2");
    PyObject x = interp.get("x");

    System.out.println("x: "+x);
    System.out.println("Goodbye, cruel world");

Is it possible on Android? Is ASE a way to go?

Community
  • 1
  • 1
Grzegorz Oledzki
  • 23,614
  • 16
  • 68
  • 106

1 Answers1

0

ASE is probably the way to go.

I'm not a Jython expert, but I expect part of the problem with trying to go that route is that Android isn't really Java -- while the base language is the same, Android Java code does not share any of the "standard" Java libraries and it compiles into its own bytecode language.

Having said that, there is a defunct project for using Jython with Android. Its author has killed the project and is directing users to ASE:

http://code.google.com/p/jythonroid/

Ken Kinder
  • 12,654
  • 6
  • 50
  • 70
  • Thanks. 'any of the "standard" Java libraries' - that's not 100% true. It does share some packages, only some of them are left out. Jythonroid - yes, I saw that. – Grzegorz Oledzki Jan 11 '11 at 14:05