Jun 4, 2013

Run Android Java console program

$ cat Hello.java
class Hello {
        public static void main(String[] args) {
                System.out.println("Hello World!");
        }
}

$ javac Hello.java

$ dx --version
dx version 1.7

$ dx --dex --output=Hello.dex Hello.class

$ ls
Hello.class  Hello.dex  Hello.java

$ adb push Hello.dex /data/local/tmp/

4.0 User:
$ adb shell dalvikvm -cp /data/local/tmp/Hello.dex Hello
Dalvik VM unable to locate class 'Hello'
java.lang.NoClassDefFoundError: Hello
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Hello
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        ... 1 more

4.0 Eng:
$ adb shell dalvikvm -cp /data/local/tmp/Hello.dex Hello

Hello World!