What is Android Pre-Dexing and how to does it increase performance?

12,551

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.

Share:
12,551

Related videos on Youtube

Gustavo Alexandre
Author by

Gustavo Alexandre

Seasoned Java/JS/Android Product Solution Architect, with deep skills in Refactoring and Test Automation. As C.T.O of TejaSoft, associate, with SME's, for premium product engineering mindset and knowledge. Do provide Enterprise Quality at Indian IT services way. Has expertise of working with 100+ million lines of code, 10k plus developers in last 14 years.

Updated on June 04, 2022

Comments

  • Gustavo Alexandre
    Gustavo Alexandre about 2 years

    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'
    
    • 10101010
      10101010 over 10 years
      This pre-dexing process is done for the external libraries that you might have included in your project. The second dexing process is for your app (.class to .dex [DEX is more suitable for systems constrained in memory and speed]). Pre-Dexing is required everytime you build the app because : 1) Some code in the app (taken from external library) might not run properly. 2) The library (which you might have downloaded from an external site) might have been compiled with an old java compiler (SDK Tools issues a warning for this).