'Hello, World'를 Activity로 만들어서 보여주는 예제는 지천에 널렸고,
public static void main(String...) 을 실행해 보자.
일단 unix shell에 접근 하여 'dalvikvm' 이라는 명령어('java'에 대응되는)를 수행하면 이렇게 나온다.
일반 휴대폰 환경과는 달리 multi-process를 지원하는 익숙한 linux kernel을 사용하기 때문에 덜 무섭다.
-
# echo $PATH
-
/sbin:/system/sbin:/system/bin:/system/xbin
-
# /system/bin/dalvikvm
-
Dalvik VM requires a class name
-
# /system/bin/dalvikvm --help
-
Unrecognized option '--help'
-
-
dalvikvm: [options] class [argument ...]
-
dalvikvm: [options] -jar file.jar [argument ...]
-
-
The following standard options are recognized:
-
-classpath classpath
-
-Dproperty=value
-
-verbose:tag ('gc', 'jni', or 'class')
-
-ea[:<package name>... |:<class name>]
-
-da[:<package name>... |:<class name>]
-
(-enableassertions, -disableassertions)
-
-esa
-
-dsa
-
(-enablesystemassertions, -disablesystemassertions)
-
-showversion
-
-help
-
-
The following extended options are recognized:
-
-Xrunjdwp:<options>
-
-Xbootclasspath:bootclasspath
-
-Xcheck:tag (e.g. 'jni', 'jni-warnonly')
-
-XmsN (min heap, must be multiple of 1K,>= 1MB)
-
-XmxN (max heap, must be multiple of 1K,>= 2MB)
-
-XssN (stack size,>= 1KB, <= 256KB)
-
-Xverify:{none,remote,all}
-
-Xrs
-
-Xint (extended to accept ':portable' and ':fast')
-
-
These are unique to Dalvik:
-
-Xzygote
-
-Xdexopt:{none,verified,all}
-
-Xnoquithandler
-
-Xjnigreflimit:N (must be multiple of 100,>= 200)
-
-Xdeadlockpredict:{off,warn,err,abort}
-
-Xstacktracefile:<file name>
-
-
Configured with: debugger profiler hprof show_exception=1
-
-
Dalvik VM init failed (check log file)
-
#
대부분 익숙한 옵션들이다.
실행할 예제 코드..
dalvik은 .class를 모아둔 jar는 직접 실행 못하고 이를 dex(Dalvik EXecutable)로 변환해서 실행해야 한다.
dex에 대한 이야기는 나중에 다루면 좋겠지만...지금은 안중밖.
위의 코드를 컴파일하고 재주껏 helloworld.jar로 만든 뒤 다음 명령을 수행한다.(emulator말고 local에서)
dx --dex --output=hellodex.jar helloworld.jar
특이한 점은 output의 확장자가 .dex가 아닌 .jar인 점인데
이 내부에는 .class들이 생존하는 것이 아니고 변환된 classes.dex만 들어있다. 이 형태가 dalvikvm이 알아먹는 jar형태이다.

이제 hellodex.jar를 emulator의 file system에 복사해야한다.
adb push hellodex.jar /data
emulator의 shell에 접속해서 실행만 하면된다. 아래는 결과
# dalvikvm -classpath /data/hellodex.jar net.hanjava.android.HelloWorld
android.vm.dexfile=true
java.runtime.name=Android Runtime
java.vm.version=1.0.0
java.vm.vendor=The Android Project
java.vendor.url=http://www.android.com/
path.separator=:
java.vm.name=Dalvik
java.vm.vendor.url=http://www.android.com/
java.vm.specification.name=Dalvik Virtual Machine Specification
user.dir=/
java.runtime.version=0.9
os.arch=OS_ARCH
java.io.tmpdir=/tmp
line.separator=java.vm.specification.vendor=The Android Project
os.name=Linux
java.library.path=/system/lib
java.specification.name=Dalvik Core Library
java.class.version=46.0
os.version=2.6.25-00350-g40fff9a
user.home=
file.encoding=UTF-8
java.specification.version=0.9
user.name=
java.class.path=/data/hellodex.jar
java.vm.specification.version=0.9
java.home=/system
user.language=en
java.specification.vendor=The Android Project
java.version=0
java.ext.dirs=
java.boot.class.path=/system/framework/core.jar:/system/fr...
java.vendor=The Android Project
file.separator=/
java.compiler=
user.region=US