So, what do you get when you cross an android with a rhinoceros? I have no idea, but that’s exactly what I’ve been doing over the past few weeks.
I recently downloaded the Android Scripting Environment> (ASE) that I discovered on Google Labs. ASE is a nifty little project that allows you to write scripts for your Android device. At the time, the project supported the following languages:
- Ruby (via JRuby)
Later that day, I got to thinking: “You know, that issue is five months old. They’ve already implemented five different interpreters. I may not know anything about Rhino or ASE, but I’m a pretty capable developer and could probably get it working in a matter of days if I really tried.” So, I asked them if they’d accept a user-contributed patch. They said they’d be glad to. I got to work on making it happen.
I immediately started getting errors the first time I went to test it. Using the interactive shell, I was able to call
methods through the proxy class but wouldn’t get any return values, and the executing saved scripts just spewed an ugly
stack trace all over the screen. The first problem (no return values) was caused by an ambiguity in the
eval() method instead. The next problem was not so straight forward. Investigating the ugly stack trace
showed that it was yet another out-of-memory error. I fixed that problem (again by increasing the stack size), but yet
another error appeared: Class format not accepted. This threw me off. At first, I thought Dalvik (Android’s JVM) was
After a few days of meditating and some ritual sacrifices to the programming gods, it hit me: Rhino was compiling the
(since it only understands Dex files). So I turned off Rhino’s optimization (thus causing it to interpret and not
compile the scripts), and all was well. The Rhinodroid was complete!