JRuby on Android (from: What would you like to know about Jruby?)


#1

In “What would you like to know about Jruby?”, Charles wrote:

We get a lot of questions about whether JRuby could work on Android
et al, and though we’re not working on it it’s most definitely
possible.

Is this just a claim or did you have a deeper look into the
platform(s)? My experiences with Android are rather bad on that
respect. The first problem is that Android only implements Java 1.4.2.
That means, that you have to base it on JRuby 1.0.x or some
backporting toolchain. On top of that it is not at all complete,
especially when it comes to Reflection, Classloading and other parts
of the Standard Library. I tried to get JRuby 1.0.x running on Android
0.8 for some time and came to the conclusion that this will only work
with non-trivial tampering on JRuby and the libraries it depends on.
Granted, I am not a JRuby Hacker and my insight is flawed. Is there
any chance to get JRuby running on Android without transforming it
into a package that cannot be called “JRuby” anymore? Has anyone else
tried it?

Regards,
Florian G.


#2

Florian G. wrote:

have to base it on JRuby 1.0.x or some backporting toolchain. On top of
that it is not at all complete, especially when it comes to Reflection,
Classloading and other parts of the Standard Library. I tried to get
JRuby 1.0.x running on Android 0.8 for some time and came to the
conclusion that this will only work with non-trivial tampering on JRuby
and the libraries it depends on.
Granted, I am not a JRuby Hacker and my insight is flawed. Is there any
chance to get JRuby running on Android without transforming it into a
package that cannot be called “JRuby” anymore? Has anyone else tried it?

Admittedly, I have not spent a lot of time looking at Android, but I’m
certain it would be possible to produce a modified version of JRuby that
could run on it. In the end, there’s only a few key pieces that would
need to work:

  • The code would either need to be always interpreted or precompiled,
    since we can’t generate Java bytecode on Android at runtime.

  • We would need to trim the core classes to those that would work on
    Android, and then to methods supported by Android.

  • Finally, we’d need a bytecode backporting tool if 1.5 bytecode was not
    acceptable. There are various “retro” tools that do a pretty good job.

So it’s certainly possible, but I don’t think anyone’s started looking
at it. It would take a bit of work.

  • Charlie

#3

First of all, thanks for the answer. As I see, it is not just a wild
guess.

On Nov 19, 2008, at 2:04 PM, Charles Oliver N. wrote:

Admittedly, I have not spent a lot of time looking at Android, but
I’m certain it would be possible to produce a modified version of
JRuby that could run on it. In the end, there’s only a few key
pieces that would need to work:

  • The code would either need to be always interpreted or
    precompiled, since we can’t generate Java bytecode on Android at
    runtime.

Okay, this was the first problem I ran into. But i had a hard time to
asses how far JRuby depends on this. So I lost interest (you know…
fun project). Do you think this is solvable in a clean way with not
too much of work?

  • We would need to trim the core classes to those that would work on
    Android, and then to methods supported by Android.

Trimming the package would be needed anyways, I don’t see a problem
there.

  • Finally, we’d need a bytecode backporting tool if 1.5 bytecode was
    not acceptable. There are various “retro” tools that do a pretty
    good job.

I played around with some, but they were a bit troublesome. The
biggest problem is that they generate JVM Bytecode which is different
from the Bytecode the Android VM uses. There is a converter, but I had
my problems with that one, too.

So it’s certainly possible, but I don’t think anyone’s started
looking at it. It would take a bit of work.

  • Charlie

Thanks for the info. Maybe I will have a look into it again.

Regards,
Florian G.


#4

Florian G. wrote:

  • The code would either need to be always interpreted or precompiled,
    since we can’t generate Java bytecode on Android at runtime.

Okay, this was the first problem I ran into. But i had a hard time to
asses how far JRuby depends on this. So I lost interest (you know… fun
project). Do you think this is solvable in a clean way with not too much
of work?

I believe so. We’d just want to pull off the compilation and code
generation bits into separate modules we load through reflection or
something similar. I’ve thought through a few scenarios.

  • Finally, we’d need a bytecode backporting tool if 1.5 bytecode was
    not acceptable. There are various “retro” tools that do a pretty good
    job.

I played around with some, but they were a bit troublesome. The biggest
problem is that they generate JVM Bytecode which is different from the
Bytecode the Android VM uses. There is a converter, but I had my
problems with that one, too.

Perhaps the SDK has improved since? Up until recently we had support for
retroweaving in the JRuby builds, though we didn’t actually test against
it.

  • Charlie