4

I recently got a bluetooth keyboard for my Motorola Xoom tablet, and upon realizing that BusyBox comes with vi for text editing I started wondering about writing and executing code on android.

I tried running $ javac in Terminal Emulator but to no avail; I got javac: not found

I looked around a bit and found a post saying that since android is run on Dalvik there is no way for the JVM to run, but it seems counter-intuitive that an operating system built on java wouldn't be able to compile and run a java program.

I managed to find an app called AIDE that allows one to write and execute android apps (in java), but that's still not quite what I'm looking for.

I want to be able to compile and run a standard java command line application on android. Does anybody know a way of doing this?

John Dorian
  • 161
  • 1
  • 1
  • 4

2 Answers2

2

I found an app on the play store that let me answer this question. Below are the steps I used to get javac and java running.

Install Terminal IDE

Go to the play store and install Terminal IDE, this supports everything needed to write and run java applications: vim, javac, and java.

Once the app is installed, make sure you open the app and go to Install System to install everything needed.

Compile and Run Program

Now press the Terminal IDE button to open the terminal.

Use vim to write and save your hello world program.

Then to execute it has to be compiled to a JAR file:

# javac hello.java
# dx --dex --output=hello.jar hello.class
# java -jar hello.jar hello

Pitfalls

When I first tried to compile and execute I got

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: hello.class: file not readable

This issue was fixed by compiling and running as superuser. Here's the full terminal output of my issue

[email protected]:~$ javac hello.java
[email protected]:~$ dx --dex --output=hello.jar hello.class

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: hello.class: file not readable
        at com.android.dx.util.FileUtils.readFile(FileUtils.java:63)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:139)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:113)
        at com.android.dx.command.dexer.Main.processOne(Main.java:247)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
        at com.android.dx.command.dexer.Main.run(Main.java:139)
        at com.android.dx.command.dexer.Main.main(Main.java:120)
        at com.android.dx.command.Main.main(Main.java:89)
        at com.spartacusrex.spartacuside.external.dx.main(dx.java:14)
        at dalvik.system.NativeStart.main(Native Method)
1 error; aborting
[email protected]:~$ su
# dx --dex --output=hello.jar hello.class
# java -jar hello.jar hello
Hello world
#

More Information

Everything you could possibly want to know can be found in the Help section of the Terminal IDE app, especially in the Java sections of the Tutorial.

John Dorian
  • 161
  • 1
  • 1
  • 4
1

Well, what do you mean by a regular Java program? I don't think that anything beyond the basic namespaces and libraries are supported and supported on android. So even if you were to find javac, it's unlikely that you'd be able to "full" Java programs on an android device.

abjbhat
  • 199
  • 2
  • 6