What is Android Pre-Dexing and how to does it incr

2019-02-11 12:17发布

问题:

I see ant script of Android has message that it is "pre-dexing". However dex and pre-dex uses same options, except that in one case one jar at a time, in other case multiple jars at a time.

What is the real need? Is pre-dex mandatory?

e.g

The ' characters around the executable and arguments are
not part of the command.
      [dex] Pre-Dexing F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\libs\pinit-sdk-1.0.jar -> pinit-sdk-1.0-e3bebafa2727504605edf3d8d85b5d46.jar
       [dx] Current OS is Windows 7
       [dx] Executing 'D:\Apps\java\embd\cmn\android\oems\google\adt\4.x\4.3.x\4.3\sdk\build-tools\18.1.0\dx.bat' with arguments:
       [dx] '--dex'
       [dx] '--output'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\dexedLibs\pinit-sdk-1.0-e3bebafa2727504605edf3d8d85b5d46.jar'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\libs\pinit-sdk-1.0.jar'
       [dx] 
       [dx] The ' characters around the executable and arguments are
       [dx] not part of the command.
Execute:Java13CommandLauncher: Executing 'D:\Apps\java\embd\cmn\android\oems\google\adt\4.x\4.3.x\4.3\sdk\build-tools\18.1.0\dx.bat' with arguments:
'--dex'
'--output'
'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\dexedLibs\pinit-sdk-1.0-e3bebafa2727504605edf3d8d85b5d46.jar'
'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\libs\pinit-sdk-1.0.jar'

The ' characters around the executable and arguments are
not part of the command.
      [dex] Converting compiled files and external libraries into F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\classes.dex...
       [dx] Current OS is Windows 7
       [dx] Executing 'D:\Apps\java\embd\cmn\android\oems\google\adt\4.x\4.3.x\4.3\sdk\build-tools\18.1.0\dx.bat' with arguments:
       [dx] '--dex'
       [dx] '--output'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\classes.dex'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\classes'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\dexedLibs\classes-144740ee5cf8b90b747300d19fb8201e.jar'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\dexedLibs\classes-1593da1bb60c5ec741aca494963e04a3.jar'
       [dx] 'F:\users\tejasoft\work\fnd\cmn\tools\social\sz\demo\bin\dexedLibs\classes-37bb5269e4fbd6dda9900fea95c0c29b.jar'

回答1:

It's useful to remember in this case that you are working in Java, which is not exactly the same thing as the Dalvik runtime. Java, from Oracle, uses a completely different virtual machine, while Dalvik is specifically fine-tuned for mobile devices.

The DEX processes take your Java compiled JAR files and converts them into Dalvik Executable Files (.dex) files that will run on Android. The Oracle JVM uses different bytecode than the Dalvik runtime, making this step a necessity.

There is a process for libraries you might have included in your project, as they are also compiled with a standard Java compiler, and then another process for your actual project.

It's done in two steps as the final process, your application, requires access to already dexed library files to avoid having references to code change while the process is busy.

You can find out more at http://source.android.com/devices/tech/dalvik/index.html - where you will also see that Dalvik is scheduled for replacement with something called ART.



标签: android dex