10

What is the dex in Gradle or in Android?

In Gradle, what's the meaning of dexoptions?

Sometimes my project does not compile because of some dexerrors. I need to activate ProGuard to compile my Android app.

Jonik
  • 80,077
  • 70
  • 264
  • 372
psv
  • 3,147
  • 5
  • 32
  • 67

1 Answers1

40

In the standard java world:

When you compile standard java code : the compiler produce *.class file. A *class file contains standard java bytecode that can be executed on a standard JVM.

In the Android world:

It is different. You use the java language to write your code, but the compiler don't produce *.class files, it produce *.dex file. A *.dex file contains bytecode that can be executed on the Android Virtual Machine (dalvik) and this is not a standard Java Virtual Machine.

To be clear: a dex file in android is the equivalent of class in standard java.

So dexoptions is a gradle object where some options to configure this java-code-to-android-bytecode transformation are defined. The options configured via this object are :

  • targetAPILevel
  • force-jumbo mode (when enabled it allows a larger number of strings in the dex files)

To enable jumboMode :

android {
    dexOptions {
        jumboMode = true
    }
}
ben75
  • 29,217
  • 10
  • 88
  • 134
  • Ok, thank you for the explanation ! And what about the ART vm ? Is it still .dex files ? The dex seems to have a limited size when compiling java code. Sometimes I get an dexError, something like "there are too much classes to be compiling in 65535 bits". I need to activate proguard even in debug mode, and I cannot debug my app (breakpoints don't stop because of obfuscation) Do you have an advice for me ? – psv Jun 15 '14 at 12:16
  • @psv see my edit about jumbo mode and try that. It's probable that activating proguard reduce the amount of code in your dex files – ben75 Jun 15 '14 at 12:55