File: hello-world.html

package info (click to toggle)
android-platform-dalvik 10.0.0%2Br36-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 26,132 kB
  • sloc: java: 270,758; cpp: 8,766; sh: 2,004; javascript: 976; ansic: 534; awk: 368; makefile: 26
file content (95 lines) | stat: -rw-r--r-- 3,485 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html>
<head>
    <title>Basic Dalvik VM Invocation</title>
</head>

<body>
<h1>Basic Dalvik VM Invocation</h1>

<p>
On an Android device, the Dalvik virtual machine usually executes embedded
in the Android application framework.  It's also possible to run it directly,
just as you would a virtual machine on your desktop system.
</p><p>
After compiling your Java language sources, convert and combine the .class
files into a DEX file, and push that to the device.  Here's a simple example:

</p><p><code>
% <font color="green">echo 'class Foo {'\</font><br>
&gt; <font color="green">'public static void main(String[] args) {'\</font><br>
&gt; <font color="green">'System.out.println("Hello, world"); }}' &gt; Foo.java</font><br>
% <font color="green">javac Foo.java</font><br>
% <font color="green">dx --dex --output=foo.jar Foo.class</font><br>
% <font color="green">adb push foo.jar /sdcard</font><br>
% <font color="green">adb shell dalvikvm -cp /sdcard/foo.jar Foo</font><br>
Hello, world
</code>
</p><p>
The <code>-cp</code> option sets the classpath.  The initial directory
for <code>adb shell</code> may not be what you expect it to be, so it's
usually best to specify absolute pathnames.

</p><p>
The <code>dx</code> command accepts lists of individual class files,
directories, or Jar archives.  When the <code>--output</code> filename
ends with <code>.jar</code>, <code>.zip</code>, or <code>.apk</code>,
a file called <code>classes.dex</code> is created and stored inside the
archive.
</p><p>
Run <code>adb shell dalvikvm -help</code> to see a list of command-line
options.
</p><p>



<h2>Using a debugger</h2>

<p>
You can debug stand-alone applications with any JDWP-compliant debugger.
There are two basic approaches.
</p><p>
The first way is to connect directly through TCP.  Add, to the "dalvikvm"
invocation line above, an argument like:
</p><p>
<code>&nbsp;&nbsp;-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y</code>
</p><p>
This tells the VM to wait for a debugger to connect to it on TCP port 8000.
You need to tell adb to forward local port 8000 to device port 8000:
</p><p>
<code>% <font color="green">adb forward tcp:8000 tcp:8000</font></code>
</p><p>
and then connect to it with your favorite debugger (using <code>jdb</code>
as an example here):
</p><p>
<code>% <font color="green">jdb -attach localhost:8000</font></code>
</p><p>
When the debugger attaches, the VM will be in a suspended state.  You can
set breakpoints and then tell it to continue.


</p><p>
You can also connect through DDMS, like you would for an Android application.
Add, to the "dalvikvm" command line:
</p><p>
<code>&nbsp;&nbsp;-agentlib:jdwp=transport=dt_android_adb,suspend=y,server=y</code>
</p><p>
Note the <code>transport</code> has changed, and you no longer need to
specify a TCP port number.  When your application starts, it will appear
in DDMS, with "?" as the application name.  Select it in DDMS, and connect
to it as usual, e.g.:
</p><p>
<code>% <font color="green">jdb -attach localhost:8700</font></code>
</p><p>
Because command-line applications don't include the client-side
DDM setup, features like thread monitoring and allocation tracking will not
be available in DDMS.  It's strictly a debugger pass-through in this mode.
</p><p>
See <a href="debugger.html">Dalvik Debugger Support</a> for more information
about using debuggers with Dalvik.


</p></p>
<address>Copyright &copy; 2009 The Android Open Source Project</address>

</body>
</html>