When is incremental dexing disabled?

3,924 views
Skip to first unread message

merono...@gmail.com

unread,
Mar 16, 2014, 9:34:47 PM3/16/14
to adt...@googlegroups.com
Our project seems to have incremental dexing disabled and we would like to know why, and if there is any way to enable it.

The release notes for gradle 0.8 state that, "Incremental dexing re-enabled (though it'll be automatically disabled in some builds for some cases that dx doesn't support yet.)". So we figure that our project is one of the cases which isn't supported yet.

We have predexing enabled, and when building using the command,
./gradlew --parallel --daemon --offline --debug assembleProductionDebug

We see this in the output:

/Applications/Android Studio.app/sdk/build-tools/19.0.1/dx --dex --verbose --output /Users/me/Documents/workspace/Android/MyProject/build/dex/production/debug /Users/me/Documents/workspace/Android/MyProject/build/classes/production/debug /Users/me/Documents/workspace/Android/MyProject/build/dependency-cache/production/debug /Users/me/Documents/workspace/Android/MyProject/build/pre-dexed/production/debug/android-agent-2.444.0-9cb8d30d445e9cf76dfafa72c76262831b460938.jar
(and 25 more jars after)

However, the incremental flag is not included here.

We get the same output even with:

android {
    dexOptions {
        incremental true
    }
}

in our build.gradle.

Manually running the above dx command with the incremental flag causes an "Unable to execute dex: Multiple dex files" error

Below is the output of ./gradlew --version
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------

Build time:   2013-12-17 09:28:15 UTC
Build number: none
Revision:     36ced393628875ff15575fa03d16c1349ffe8bb6

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.6.0_37 (Apple Inc. 20.12-b01-434)
OS:           Mac OS X 10.8.2 x86_64

We are using version 0.8.3 of the android gradle plugin

If there is any other information which can help determine the cause of this problem, we would be happy to provide it

Xavier Ducrohet

unread,
Mar 17, 2014, 1:56:28 PM3/17/14
to adt...@googlegroups.com
Incremental is disabled if a jar file changed. If a class file changed it's fine.

So if any of your dependencies changed then incremental is disabled.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

merono...@gmail.com

unread,
Mar 19, 2014, 10:44:18 AM3/19/14
to adt...@googlegroups.com
Is there any way to tell which jar has changed that would cause this to happen? I'm only changing code in my main project which I would think wouldn't cause this to happen

Xavier Ducrohet

unread,
Mar 19, 2014, 11:48:33 AM3/19/14
to adt...@googlegroups.com
If you run from the command line with --info it should tell you what changed. Can you check if you see that it's not using incremental and yet no jar files changed?


On Wed, Mar 19, 2014 at 7:44 AM, <merono...@gmail.com> wrote:
Is there any way to tell which jar has changed that would cause this to happen? I'm only changing code in my main project which I would think wouldn't cause this to happen
--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

merono...@gmail.com

unread,
Mar 19, 2014, 2:26:47 PM3/19/14
to adt...@googlegroups.com
Here is the relevant part of the output from the command ./gradlew --parallel --daemon --offline --info assembleProductionDebug

:MyProject:preDexProductionDebug (Thread[Task worker Thread 2,5,main]) started.
:MyProject:preDexProductionDebug
Skipping task ':MyProject:preDexProductionDebug' as it is up-to-date (took 0.0050 secs).
:MyProject:preDexProductionDebug UP-TO-DATE
:MyProject:preDexProductionDebug (Thread[Task worker Thread 2,5,main]) completed. Took 0.0070 secs.
:MyProject:dexProductionDebug (Thread[Task worker Thread 2,5,main]) started.
:MyProject:dexProductionDebug
Executing task ':MyProject:dexProductionDebug' (up-to-date check took 0.089 secs) due to:
  Input file /Users/me/Documents/workspace/Android/MyProject/build/classes/production/debug/com/projectname/models/Language.class has changed.
  command: /Applications/Android Studio.app/sdk/build-tools/19.0.1/dx --dex --output /Users/me/Documents/workspace/Android/MyProject/build/dex/production/debug /Users/me/Documents/workspace/Android/MyProject/build/classes/production/debug /Users/me/Documents/workspace/Android/MyProject/build/dependency-cache/production/debug /Users/me/Documents/workspace/Android/MyProject/build/pre-dexed/production/debug/android-agent-2.444.0-9cb8d30d445e9cf76dfafa72c76262831b460938.jar
(and 25 more jars after)

Language.java was the file I made the change to and I can see from the output that Language.class changed. But it doesn't seem like any jars changed

Xavier Ducrohet

unread,
Mar 19, 2014, 2:48:52 PM3/19/14
to adt...@googlegroups.com
hmm looking at this I discovered that it's turn off by default!

Try with 

android {
  dexOptions {
    incremental true
  }
}

merono...@gmail.com

unread,
Mar 19, 2014, 3:03:27 PM3/19/14
to adt...@googlegroups.com
I put that in the build.gradle of my main project and I still get the same output (i.e. no incremental flag when dexing). The build also takes the same amount of time so it didn't seem to have an effect

merono...@gmail.com

unread,
Mar 21, 2014, 9:26:54 AM3/21/14
to adt...@googlegroups.com
Here is a small example project where the same behaviour can be seen: https://github.com/cagricakir/FirstTraining/
Change the build.gradle to use gradle plugin 0.9.+, build tools 19.0.3 and add the dexOptions to turn incremental dexing on. Also change the gradle-wrapper.properties to use gradle 1.11.

With this setup, make a one line change to MainActivity.java and run
./gradlew --daemon --parallel --offline --info assembleDebug
It can be seen that the incremental flag isn't used when dexing, with similar output as when run on my own project

Kyle Fowler

unread,
Mar 21, 2014, 1:56:05 PM3/21/14
to adt...@googlegroups.com
I am seeing the same behavior. If I add incremental true, and make a one line change in my mainactivity after doing a clean compile once it still re-dexs all of the classes in my app but not in any of the dependencies.

Riccardo Ciovati

unread,
May 6, 2014, 9:44:44 AM5/6/14
to adt...@googlegroups.com
Il giorno mercoledì 19 marzo 2014 19:48:52 UTC+1, Xavier Ducrohet ha scritto:
hmm looking at this I discovered that it's turn off by default!

Try with 

android {
  dexOptions {
    incremental true
  }
}

I was looking around the source code (goo.gl/zNXocQ) when I spotted what this problem: at the line 91, instead of

doTaskAction(!forceFullRun)

it should be:

doTaskAction(!forceFullRun.get())

otherwise the parameters will be always false.

Regards,
Riccardo
 

Xavier Ducrohet

unread,
May 6, 2014, 2:26:20 PM5/6/14
to adt...@googlegroups.com
ugh, thanks for looking into this. I fixed it.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Riccardo Ciovati

unread,
May 7, 2014, 5:10:10 AM5/7/14
to adt...@googlegroups.com
Il giorno martedì 6 maggio 2014 20:26:20 UTC+2, Xavier Ducrohet ha scritto:
ugh, thanks for looking into this. I fixed it.

Thanks Xavier, it was fast!

I tried the SNAPSHOT version. Now the --incremental flag is added properly but I'm getting a "com.android.dex.DexException: Multiple dex files define..." error.
Here the output with --info of a sample project I built:
https://gist.github.com/rciovati/ede56a70c8828b4d737f

Thanks again.

Regards,
Riccardo

Martynas Jurkus

unread,
May 26, 2014, 6:33:40 AM5/26/14
to adt...@googlegroups.com
I'm getting similar error with released 0.10.2 version.

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/facebook/AccessToken$1;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)

Thasso Griebel

unread,
May 27, 2014, 4:45:54 AM5/27/14
to adt...@googlegroups.com
Hey all,

I am also seeing the "Multiple dex files" error if I have both predexing and incremental set to true. If I only use incremental, the --incremental flag is passed correctly and it seems to work.

Best,
-Thasso
Message has been deleted

Mike Kulasinski

unread,
Jun 20, 2014, 10:28:18 AM6/20/14
to adt...@googlegroups.com
Hi 

I have also experienced the Multiple dex problem, I have turned of incremental dexing and this fixed the issue, I am running Gradle 1.12, Android Studio 0.6.1, Android Gradle Plugin 1.11.1. I have experienced this problem from early version 0.10.

Any idea how to fix this problem?

Thanks

Mike

Michael Wallstedt

unread,
Sep 18, 2014, 5:18:45 PM9/18/14
to adt...@googlegroups.com
I can confirm that the "multiple dex files define x" error occurs in Android Studio 0.8.2 with a multi module project. Is there a bug to track this and/or an ETA for a fix?

Thasso Griebel

unread,
Sep 19, 2014, 12:55:11 PM9/19/14
to adt...@googlegroups.com
Hey,

just to confirm, I also still see the issue with the latest 0.13.0 gradle plugin. The duplicated class is found first in :

<submodule_folder>/build/intermediates/dex/debug/classes.dex

as well as in 

<submodule_folder>/build/intermediates/pre-dexed/debug/acra-4.4.0-4f3087dc293438b0cfab28d844cf164e6fb101ba.jar

acra is a third party dependency used by the module.

The following stacktrace is printed:

   UNEXPECTED TOP-LEVEL EXCEPTION:
   com.android.dex.DexException: Multiple dex files define Lorg/acra/ACRA$1;
          at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
          at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
          at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
          at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
          at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
          at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
          at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
          at com.android.dx.command.dexer.Main.run(Main.java:230)
          at com.android.dx.command.dexer.Main.main(Main.java:199)
          at com.android.dx.command.Main.main(Main.java:103)

Any advice if the combination of incremental dexing + predexing is suppose to work or how we could get it to work would be much appreciated.

Best,
-Thasso

Kirill Rakhman

unread,
Sep 19, 2014, 2:17:20 PM9/19/14
to adt...@googlegroups.com
Thanks to your comment I just realized that predexed libraries are causing this behaviour. If you disable predexing incremental dexing seems to work and is also quiet a bit faster. My guess is: Since incremental dexing doesn't dex everything predexing isn't a speedup anymore. Libraries are dexed once because their class files don't change.

Marcos Barreto

unread,
Nov 3, 2014, 1:18:00 PM11/3/14
to adt...@googlegroups.com
Hi,

I'm running with this problem having the latest gradle plugin (i'm trying out the new multidex config).

Just changing a line in one source file takes up to 1m 50s to build and as the original post stated, the --incremental flag is not included and a "Force full dx run" is triggered.

My config:
Gradle plugin version: 0.14.0
AS version: 0.9 (Canary Channel)

Output of ./gradlew --version
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------

Build time:   2014-09-08 10:40:39 UTC
Build number: none
Revision:     e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_25 (Oracle Corporation 23.25-b01)
OS:           Mac OS X 10.9.5 x86_64


The command output is something like:

$ANDROID_SDK/build-tools/21.0.2/dx --dex --multi-dex --main-dex-list $PROJECT_HOME/build/intermediates/multi-dex/debug/maindexlist.txt --output $PROJECT_HOME/build/intermediates/dex/debug --input-list=$PROJECT_HOME/build/intermediates/tmp/dex/debug/libraryList.txt


I have the incremental option enabled in my build.gradle:
android {
.....
    dexOptions {
        incremental true
    }
}

Thanks!

Regards,
marcos.

박병선

unread,
Apr 2, 2015, 8:30:32 PM4/2/15
to adt...@googlegroups.com
Is this problem solved? I am using gradle plugin 1.1.0, but I am experiencing that.


2014년 9월 20일 토요일 오전 3시 17분 20초 UTC+9, Kirill Rakhman 님의 말:

rodgerpodactermurder

unread,
Jun 17, 2015, 1:52:09 PM6/17/15
to adt...@googlegroups.com
I added this to the android section of my gradle build script and it resolved the problem for me.

dexOptions {
    incremental
true
    preDexLibraries
false
}


Bruno
Reply all
Reply to author
Forward
0 new messages