This series of articles is thought for a long time but has not been put into action, taking advantage of the two-day holiday is not over,
Hurriedly pen, afraid to work there is no time to calm down to write these articles, so a little rush, performance in the series of articles
Content arrangement on is not very reasonable, some content also need to enrich, but better than nothing bar, first write down again revise, if
Some feedback can also be modified according to feedback. OK, start the second article.
This article can be a DX HelloWorld, in this article I will describe if you compile a Java file
into a dex file. Ok,go!
Step1: Prepare Java file, file name Helloworld.java, content as follows
public class HelloWorld {public void SayHello () { System.out.println ("Hello world!");} }
What a familiar HelloWorld:)
Step2: Write a script that reads as follows:
mkdir classesjavac-d Classes src/*.javadx-jxmx500m--debug--dex--no-optimize--positions=none--no-locals -- Dump-to=classes.lst--output=classes.dex classeszip Test.jar classes.dex
Here are some explanations to be made using Javac to compile Java source files, generate class files, and then use DX to
class file into the Dalvik directive, and package the build Classes.dex, and finally package Dex into a jar package. Although just
Just a few words, but the internal logic of the DX process is actually very complex, and I'll write a separate article about DX's
Process. Briefly summarize the above compilation process:
. java------------->. class---------->. dex
Javac DX
The corresponding reverse process is as follows:
. java <-------------. class <------------. Dex
Jd-gui Dex2jar
step3: Executing the above script will generate the Classes.dex file
This article mainly introduces the process of Java to Dex through scripts, and subsequent articles will detail the DX process, as well as the Dex
The structure of the file.
Dalvik instruction Analysis (ii) from Java file to Dex