Android system executes Java JAR Program--Dalvik running Dex Java Project

Source: Internet
Author: User

This article is only for pure Java Project execution interpretation, generally in the PC platform as a jar package exists, on the Android platform in the form of Dex package.

Java is a high-level programming language, and Java programs need to run in a specific virtual machine, and the virtual machine translates Java bytecode into corresponding machine instructions for execution. Different platforms have different virtual machines that correspond to their respective machine instructions. The PC side typically uses the JVM virtual machine and the Android side uses the Dalvik virtual machine.

You need to configure the environment:
    1. Java JDK Development environment
    2. IDEA Development tools
    3. Android SDK Development Environment
    4. Android build-tools environment variable (optionally specify a version)
JVM in Dalvik

The JVM:PC platform Java Virtual Machine provides the execution environment for Java application execution.
The Dalvik:android platform Java Virtual Machine provides a runtime environment for Java applications, distinguished from JVM bytecode.

Java program execution PC execute idea configuration executable jar package

1. Create a Java project
2, Idea choice file->project structure---artifacts ()-click + after select Jar, from module with dependencies
3. Configure the compiled module, specify the entry class (must overwrite the Main method)
4. Modify the directory for Meta-inf/mainfest. MF: Remove the main (for example: E:\CloudFiles\project\TestJar\testlib\src\META-INF\MANIFEST. MF)

Package and Execute

1, select Build, build artifacts, select Build to start hitting Jar package, jar package output path is \out\artifacts\modulename
2, run the jar package will be executed through the specified Java class, execute the command as follows:

java -jar  
Android execution

Executing Java programs on the Android platform relies on the Dalvik virtual machine, so you need to convert the jar package to the corresponding bytecode file, as follows:
1. Generate Java jar package with PC execution
3. Java jar package to Dex package, execute the following command

4. Connect the Android phone and push the Dex execution program into the Android device path:

adb push E:\test.dex /data/local/tmp/

5, through the Dalvik command to execute the DEX program, the program through the specified entry Java class Main method to start execution

dalvikvm -cp  /data/local/tmp/test.dex com.qihoo.trace.TestMain

Android system executes Java JAR Program--Dalvik running Dex Java Project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.