'dx'에 해당되는 글 1건

  1. 2010.11.02 ADB shell에서 java class 실행하기
찾는데 힘들었다. 커맨드 라인 콘솔에서 java 소스 코드를 컴파일해서 ADB shell을 통해 안드로이드 플랫폼에서 실행시키기 까지의 과정을 보여준다.
(원본 링크) http://davanum.wordpress.com/2007/12/04/command-line-java-on-dalvikvm/


December 4, 2007

Command line Java on DalvikVM

Filed under: Uncategorized — Davanum Srinivas @ 11:21 am

Found this very useful when i was trying out the JNI under android (Short Story – Could not get it to work!).

Step #1: Start with a simple java class

package org.apache;

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

Compile the java class

C:\android\CmdLine>javac -d . -g Helloworld.java

Step #2: Package the generated classes into a temporary jar

C:\android\CmdLine>jar -cvf Temp.jar *
added manifest
adding: Hello.java(in = 0) (out= 0)(stored 0%)
adding: HelloWorld.java(in = 149) (out= 122)(deflated 18%)
adding: org/(in = 0) (out= 0)(stored 0%)
adding: org/apache/(in = 0) (out= 0)(stored 0%)
adding: org/apache/HelloWorld.class(in = 556) (out= 344)(deflated 38%)

Step #3: Use the “dx” tool to generate a classes.dex from our temporary jar.

C:\android\CmdLine>dx --dex --output=c:/android/CmdLine/classes.dex c:/android/CmdLine/Temp.jar

Step #4: Use the “aapt” tool to create a new jar suitable for use with dalvikvm

C:\android\CmdLine>aapt add CmdLine.jar classes.dex
'classes.dex'...

and push it into a known location on the emulator

C:\android\CmdLine>adb push CmdLine.jar /data
30 KB/s (0 bytes in 481.000s)

Step #5: kick the tires of dalvikvm

C:\android\CmdLine>adb shell
# /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -version
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -version
DalvikVM version 0.2.0
Copyright (C) 2007 Google, Inc.
Blah blah blah LICENSE blah blah.
Dalvik VM init failed (check log file)

Step #6: Run our code

# /system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -classpath /data/CmdLine.jar org.apache.HelloWorld
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -classpath /data/CmdLine.jar org.apache.HelloWorld
Hello World!

(끝)

Posted by ingeeC
,