Is there any way that can run android apps with dalvikvm in command line?

451 views
Skip to first unread message

Hendy

unread,
Apr 7, 2010, 9:51:41 PM4/7/10
to android-platform
like this?
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -
classpath /data/CmdLine.jar org.apache.HelloWorld

I found some information from this link:
http://davanum.wordpress.com/2007/12/04/command-line-java-on-dalvikvm/.
I have tried to do that with android apps but failed. The emulator
just auto rebooted.

the reason i want to do this is because i want to debug JNI functions.
although i can use gdb to attach the already running process and set
breakpoints, some other problems always happens when doing remote
debug with gdb in eclipse. i have found that when run the process
directly with gdbserver then everything goes well. so i want to know
how to run android java apps with dalvikvm directly so maybe i can
debug jni native codes with eclipse then. and i think it must be a
possible thing.

anybody knows? please help me. thanks.

sorry for post it here because i have posted it in group android
developers. but i think this is a cross subject problem :-)

je...@swank.ca

unread,
Apr 9, 2010, 4:06:38 AM4/9/10
to android-platform
You can run dalvikvm apps from the command line, but they need to be
of the "public static void main(String[] args)" variety, rather than
Android framework apps.

Here's a sketch of what you'll need to do:
1. Compile your classes as you would for a Java VM. You'll need at
least one class with a main method.
2. Use the dx tool to create a dalvikvm executable. This is usually
a .jar file with a single classes.dex file inside, rather than the
several .class files.
3. Copy the dalvik executable to your device. With adb, this is "adb
push mydexfile.jar /data/mydexfile.jar"
4. Run the VM: "adb shell dalvikvm -classpath /data/mydexfile.jar
com.mycompany.MyMainClass"

Hope this helps!

Cheers,
Jesse

space

unread,
Apr 9, 2010, 6:56:02 AM4/9/10
to android-platform
Check out the source code of the monkey tool.

fadden

unread,
Apr 9, 2010, 5:32:20 PM4/9/10
to android-platform
On Apr 9, 1:06 am, "je...@swank.ca" <je...@swank.ca> wrote:
> You can run dalvikvm apps from the command line, but they need to be
> of the "public static void main(String[] args)" variety, rather than
> Android framework apps.

To be even more specific, you can't use any of the Android framework
classes. Some of the utility classes might work, but without the full
app process init sequence most things won't work.

Here's a quick tutorial on executing a "hello, world" program (dalvik/
docs/hello-world.html in the source tree):

http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/hello-world.html;hb=HEAD

It also describes attaching a Java-language debugger. You can't
really test your full app this way, but you can write something that
drives your JNI code, which may be good enough for your purposes.

Reply all
Reply to author
Forward
0 new messages