Gradle plugin 0.14.2 dx task error

476 views
Skip to first unread message

Alex Lipov

unread,
Nov 16, 2014, 12:34:06 PM11/16/14
to adt...@googlegroups.com
After upgrading to version 0.14.2 of Gradle plugin, I'm receiving the following error during the dx task:

> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\bin\sdk\build-tools\21.1.0\dx.bat -JXmx4g --dex --force-jumbo --multi-dex --main-dex-list D:\x\y\build\intermediates\multi-dex\debug\maindexlist.txt --set-max-idx-number=60000 --output D:\x\y\build\intermediates\dex\debug --input-list=D:\x\y\build\intermediates\tmp\dex\debug\libraryList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:494)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
at com.android.dx.command.dexer.Main.run(Main.java:243)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)

Attaching some dex statistics as well:
  annotation: 2853 items; 52698 bytes total
    4..406 bytes/item; average 18
  annotation set: 2652 items; 28340 bytes total
    4..28 bytes/item; average 10
  annotation set ref list: 23 items; 268 bytes total
    8..20 bytes/item; average 11
  annotations directory: 1911 items; 55808 bytes total
    16..784 bytes/item; average 29
  class data: 2606 items; 267584 bytes total
    9..6687 bytes/item; average 102
  class def: 2686 items; 85952 bytes total
    32 bytes/item
  code: 21150 items; 2589324 bytes total
    20..27328 bytes/item; average 122
  debug info: 21127 items; 561607 bytes total
    5..2189 bytes/item; average 26
  encoded array: 601 items; 169167 bytes total
    2..16682 bytes/item; average 281
  field id: 55438 items; 443504 bytes total
    8 bytes/item
  header: 1 item; 112 bytes total
    112 bytes/item
  map list: 1 item; 220 bytes total
    220 bytes/item
  method id: 33015 items; 264120 bytes total
    8 bytes/item
  proto id: 7015 items; 84180 bytes total
    12 bytes/item
  string data: 62775 items; 1537311 bytes total
    2..1599 bytes/item; average 24
  string id: 62775 items; 251100 bytes total
    4 bytes/item
  type id: 5637 items; 22548 bytes total
    4 bytes/item
  type list: 4202 items; 38558 bytes total
    6..68 bytes/item; average 9

Everything works well on v.0.14.0. Any suggestions for what could go wrong?

Xavier Ducrohet

unread,
Nov 16, 2014, 1:33:18 PM11/16/14
to adt...@googlegroups.com
Can you look in D:\x\y\build\intermediates\multi-dex\debug\maindexlist.txt and count the number of classes?

We added --set-max-idx-number=60000 to work around some problem on much older platforms (Gingerbread), but this is independent from the computation of the main dex list (and one is methods and the other classes)

You could get into a situation where the required list of classes for the main dex list is too big for one dex, in which case it just won't work.

--
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!

liatsineam

unread,
Nov 16, 2014, 10:56:37 PM11/16/14
to adt...@googlegroups.com
After upgrading to version 0.14.2 of Gradle plugin, I'm also receiving the error during the dx task

Alex Lipov

unread,
Nov 17, 2014, 1:57:26 AM11/17/14
to adt...@googlegroups.com
Can you look in D:\x\y\build\intermediates\multi-dex\debug\maindexlist.txt and count the number of classes?

There are 2689 classes.

We added --set-max-idx-number=60000 to work around some problem on much older platforms (Gingerbread)..

I can confirm that without this parameter everything works well with 0.14.2.
Is there a way to remove it from dx's parameter list? Our minSdk is ICS, so I don't actually need it in any case..

liatsineam

unread,
Nov 17, 2014, 3:03:32 AM11/17/14
to adt...@googlegroups.com
There are 4520 classes. Is there a way to change 60000 to a smaller number?


On Monday, November 17, 2014 2:33:18 AM UTC+8, Xavier Ducrohet wrote:
Message has been deleted

liatsineam

unread,
Nov 18, 2014, 12:02:28 AM11/18/14
to adt...@googlegroups.com
buildToolsVersion "21.1.1" is ok

Alex Lipov

unread,
Nov 18, 2014, 1:45:15 AM11/18/14
to adt...@googlegroups.com
I'm having the same behavior with build tools 21.1.1.
The error thrown in dx, whose version (1.10) is the same in both 21.1.0 and 21.1.1, so I don't understand how it works for you.

Alex Lipov

unread,
Nov 30, 2014, 6:15:15 AM11/30/14
to adt...@googlegroups.com
Indeed our main-dex classes list is too big (amount of methods is greater than 65k). 
I'm currently checking what are the options in this situation. The simple one will be to revert to our pre-multidex solution, even though it is very painful.

I have one more question regarding multidex. Why Activities are configured as roots for main dex file? 
I can understand why Application (and all its direct reference hierarchy) class has to be there, since it is loaded and verified before the ClassLoader patching. But why Activities?

Just to test that, I created a test app that uses --minimal-main-dex flag, and its main-dex list includes only the android.support.multidex classes. 
This app has a main activity, which is (according to configuration) packaged into a second dex. Everything works well, which makes me wonder why in android-gradle-plugin activities are configured as main-dex roots..

Could you please elaborate on this?

-Alex


On Sunday, November 16, 2014 8:33:18 PM UTC+2, Xavier Ducrohet wrote:

Alex Lipov

unread,
Dec 6, 2014, 8:20:02 AM12/6/14
to adt...@googlegroups.com
If anyone interested, we're eventually removed all the activities (and their reference hierarchy) from the main dex.
I've posted a short summary here.
Reply all
Reply to author
Forward
0 new messages