"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:

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

C:\herong>"%java_home%/bin/javac" Hello.java

3. Convert .class file to .dex file:

C:\herong>copy Hello.class \local\android-sdk-windows\platform-tools
   (dx.bat requires class files to be located at this folder)

C:\herong>\local\android-sdk-windows\platform-tools\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:

C:\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:

C:\herong>copy Hello.class \local\android-sdk-windows\platform-tools

C:\herong>\local\android-sdk-windows\platform-tools\dx.bat
   --dex --output=Hello.dex Hello.class

6. Copy .dex file to the Android system:

C:\herong>\local\android-sdk-windows\platform-tools\adb 
   push Hello.dex /sdcard/Download
4 KB/s (736 bytes in 0.167s)

7. Run the application with "dalvikvm":

C:\herong>\local\android-sdk-windows\platform-tools\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.

Last update: 2015.

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

 Android 4.0.3 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

 Outdated Tutorials

 References

 PDF Printing Version