I'm looking for an open-source remote REPL for Android's Java API that runs on Linux. That is, the commands will be typed into my Linux desktop, but they will be executed using the Java API on an Android device of my choosing. I'm looking for an alternative to creating and running an .apk each time I want to play with API methods and objects.

Java on the desktop has a number of REPLs, such as those for Jython, BeanShell, and Groovy. A motivating example from Jython:

$ jython
Jython 2.5.3 (, Oct 8 2014, 03:39:09) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_102
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import String
>>> String('one two three').substring(4, 8)
u'two '

I would like to be able to test things like this on a real Android device, without having to type them on my phone's keyboard.

It looks to me like Clojure might have this feature, but I'm not yet comfortable at all with Lisp-like languages, so that won't work for me. Anything with a syntax similar to C, shell scripting, BASIC, or even non-Lisp-like functional programming, should be fine.

It's fine for me if not everything in the API works, as long as most things do. I'm looking to experiment, not embed this into a final product. I'd really prefer this to be able to be run on non-rooted devices.

Features that I don't require, but would make this even more useful for me:

  • easy introspection of objects in the REPL (finding the names, and possibly signatures, of their methods and fields, without having to go look them up myself)
  • some way to add third-party Android libraries and then test them. Even if this requires creating and uploading an .apk to the device, so long as afterwards they can be tested in the same remote REPL.
  • anything that makes it easier to write and test multi-line code in the REPL
  • an easy way to save my REPL's history

I found that BeanShell can be easily embedded into an Android app, so I wrote an Android project named MercerShell that uses BeanShell to provide a remote Android REPL. I've released it under the GPLv3 license on GitHub. It's currently (v0.1) got a lot of rough edges, and not many features, but it works for many simple things.

It requires creating a self-signed certificate, building from source, and installing the resulting app onto the Android device. It does not require a rooted device.

An example of usage:

> import android.net.Uri
> import android.content.Intent
> uri = Uri.parse("http://softwarerecs.stackexchange.com/q/37211")
> activity.startActivity(new Intent(Intent.ACTION_VIEW, uri))


Multi-line code

This is technically possible right now, but it's about as ugly as can be. ## starts and ends blocks of code, and #- cancels mid-block:

> ##
> sayHi() {z
> oops!
> #-
> ##
> sayHi() {
>   print("Hi!");
> }
> ##
> sayHi()


No special features to make this easier, other than those already in Java and BeanShell:

> Arrays.toString(uri.getClass().methods)
[public android.net.Uri$Builder android.net.Uri$StringUri.buildUpon(), ...]

Adding 3rd-party libraries

There's no special way to do this, but since the app works by being built from source and installed to a device, this can be accomplished by adding compile dependencies to the build.gradle for the app or server Gradle subproject. For example, Mockito has already been added this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.