How to execute Java commands in Android

Source: Internet
Author: User

Android 's program is based on Java Development, when we connect the debugger, execute the adb shell, you can execute the Linux command, but can not execute the java command.

Is it possible to execute Java programs in the Android shell ?

the answer is in the negative. We can execute Java programs through App_process .

Write a Hello world, that is, when you first started to learn Java, write the Hello World, this time in Android run on.

Create a new Hello.java file with Notepad and write the following code:

public static class Hello {

public void Main (String args[]) {

System.out.println ("Hello Android");

}

}

Javac Hello.java

get The hello.class file execute "java Hello" to see the output results

So how do you get this simplest Java program to run on Android ?

The. Class file can be run on a regular JVM and will need to be converted to Dex under Android,using the DX in the Android SDK Tools to convert

DX--dex--output=hello.dex Hello.class

get hello.dex, this hello.dex can be put on Android to execute.

Connect your phone, turn on USB debugging

ADB push hello.dex/sdcard/

ADB shell enters android command line

run hello.dex with app_process

App_process-djava.class.path=/sdcard/hello.dex/sdcard Hello

Well, so far we've managed to run a normal Java program on Android . In addition to the APP for a full range of detection, I will use this:www.ineice.com.


How to execute Java commands in Android

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.