|
Tutorial1
How to run a program
tutorial IntroductionThis tutorial describes how to run a simple program on this vm step by step. Details1. 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;
}
}
|
► Sign in to add a comment
Really Good
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
App.jar contains a simple java .only command line outputs are working..
It doesnt support J2me UI to be run Android?
Thanks very much!
Will some one please translate this fromu techie to english?
This is very good!
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.