My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Tutorial1  
How to run a program
tutorial
Updated Mar 3, 2009 by his...@gmail.com

Introduction

This tutorial describes how to run a simple program on this vm step by step.

Details

1. Compile the below code and package it as App.jar

package tutorial1;

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

2. Convert App.jar to App.dex which is a Dalvik Executable file

dx --dex --output=<absolute file path to tutorial1/App.dex> <absolute file path to tutorial1/App.jar>

3. Write a launcher code and run it

import java.io.*;

import jp.eflow.hisano.dalvikvm.VirtualMachine;

public final class RunHelloWorld {
	public static void main(final String[] args) {
		final File dexFile = new File("tutorial1", "App.dex");
		final String absoluteMainClassName = "tutorial1.HelloWorld";

		final VirtualMachine vm = new VirtualMachine();
		vm.load(toBytes(dexFile));
		vm.run(absoluteMainClassName, new String[0]);
	}

	private static byte[] toBytes(final File dexFile) {
		final byte[] bytes = new byte[(int)dexFile.length()];
		DataInputStream in = null;
		try {
			in = new DataInputStream(new BufferedInputStream(new FileInputStream(dexFile)));
			in.readFully(bytes);
		} catch (IOException e) {
			System.err.println("The specified dex file path is invalid: " + dexFile.getName());
			System.exit(-1);
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
		return bytes;
	}
}
Comment by spk2p...@gmail.com, Jul 24, 2009

Really Good

Comment by araving....@gmail.com, Feb 22, 2010

Step4 1. copy the jp folder in "src" directory to "dalvik vm" folder 2. copy helloworld.java from tutorial1 to dalvik vm folder 3. now javac helloworld.java and run

Comment by xxSparc...@gmail.com, Feb 22, 2010

App.jar contains a simple java .only command line outputs are working..

It doesnt support J2me UI to be run Android?

Comment by thaitb....@gmail.com, Dec 21, 2010

Thanks very much!

Comment by fatpengu...@gmail.com, Jan 6, 2012

Will some one please translate this fromu techie to english?

Comment by w...@139f.net, Jan 15, 2012

This is very good!

Comment by jpgpsan...@gmail.com, Apr 11, 2012

Hello. I am developing a java applet ising Swing, included in a webPage running in tomcat server. Running this applet in android plataform is starting to be a requirement. This applet has various jar dependencies, so there is not only one jar to convert to android platform.

Is it possible to convert applets using the dx tool in server side? In other words, when a request to that page (from an android device) is performed, the server responds to the client (android device) with this applet converted to android in some way.

From what i understand about dx tool, this is only applicable to standalone java programs that are eventually packaged as a jar file and we want to run that application in android, but this application is not browser dependent.

Awaiting feedback.

Thanks!

Best regards.


Sign in to add a comment
Powered by Google Project Hosting