"dalvikvm" Command to Run Java Application

This section provides a tutorial example on how to use 'dalvikvm' command line tool to run a Java application on the Dalvik VM (Virtual Machine).

Since "dalvikvm" is a Java virtual machine, you can use it to run regular Java applications as shown in this tutorial:

1. Write a simple Java application called Hello.java:

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

2. Compile the application with Java SE 6:

herong> "%java_home%/bin/java" -version
java version "1.8.0_45"
...

herong> "%java_home%/bin/javac" Hello.java

3. Convert .class file to .dex file:

herong> copy Hello.class \local\platform-tools
   (dx.bat requires class files in the same folder as the command)

herong> dx.bat
   --dex --output=Hello.dex Hello.class

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe)
   or version (0034.0000)
   at com.android.dx.cf.direct.DirectClassFile.parse0
      (DirectClassFile.java:472)
...

4. Recompile with lower JDK version:

herong> "%java_home%/bin/javac" -target 1.7 -source 1.7 Hello.java
warning: [options] bootstrap class path not set in conjunction with
-source 1.7
1 warning

5. Convert .class file to .dex file:

herong> copy Hello.class \local\platform-tools

herong> \local\platform-tools\dx.bat
   --dex --output=Hello.dex Hello.class

6. Copy .dex file to the Android system:

herong> adb push Hello.dex /sdcard/Download
4 KB/s (736 bytes in 0.167s)

7. Run the application with "dalvikvm":

herong> adb shell

# cd /sdcard/Download
cd /sdcard/Download

# dalvikvm -cp Hello.dex Hello
dalvikvm -cp Hello.dex Hello

Hello world!

Very nice! This confirms that dalvikvm is just another JVM that can run Java applications.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

 AboutAndroid - Application to Retrieve System Information

 android.app.Activity Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

 Building Your Own Web Browser

Android Command Line Shell

 What Is the Bourne Shell?

 Bourne Shell Command Line Examples

 Unix/Linux Command Line Programs

 Android Command Line Tools

"dalvikvm" Command to Run Java Application

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials

 References

 Full Version in PDF/EPUB