Skip to content

Commit 418c847

Browse files
Yohann Rousselbdcgoogle
Yohann Roussel
authored andcommitted
Make a more verbose too many id error message.
This restores the old message, replacing "ids" by "references" and advertising for multidex otpions. Updates dalvik/tests/089-many-methods accordingly. (cherry picked from commit d352de04f03b848e0246119344ea13e7233018f0) Change-Id: I5934bc9fb7812b66c0e38935946cacdf1c35a402
1 parent 82e8334 commit 418c847

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

dx/src/com/android/dx/command/dexer/Main.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@
7676
* Main class for the class file translator.
7777
*/
7878
public class Main {
79-
/**
80-
* {@code non-null;} Error message for too many method/field/type ids.
81-
*/
82-
public static final String TO_MANY_ID_ERROR_MESSAGE =
83-
"Dex limit exceeded. You may try option " + Arguments.MULTI_DEX_OPTION;
84-
8579
/**
8680
* File extension of a {@code .dex} file.
8781
*/
@@ -240,6 +234,18 @@ public static int run(Arguments arguments) throws IOException {
240234
}
241235
}
242236

237+
/**
238+
* {@code non-null;} Error message for too many method/field/type ids.
239+
*/
240+
public static String getTooManyIdsErrorMessage() {
241+
if (args.multiDex) {
242+
return "The list of classes given in " + Arguments.MAIN_DEX_LIST_OPTION +
243+
" is too big and does not fit in the main dex.";
244+
} else {
245+
return "You may try using " + Arguments.MULTI_DEX_OPTION + " option.";
246+
}
247+
}
248+
243249
private static int runMonoDex() throws IOException {
244250

245251
File incrementalOutFile = null;

dx/src/com/android/dx/dex/file/MemberIdsSection.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import com.android.dex.DexFormat;
2121
import com.android.dx.command.dexer.Main;
2222

23+
import java.util.Formatter;
24+
import java.util.Map;
25+
import java.util.TreeMap;
26+
import java.util.concurrent.atomic.AtomicInteger;
27+
2328
/**
2429
* Member (field or method) refs list section of a {@code .dex} file.
2530
*/
@@ -42,12 +47,41 @@ protected void orderItems() {
4247
int idx = 0;
4348

4449
if (items().size() > DexFormat.MAX_MEMBER_IDX + 1) {
45-
throw new DexException(Main.TO_MANY_ID_ERROR_MESSAGE);
50+
throw new DexException(getTooManyMembersMessage());
4651
}
4752

4853
for (Object i : items()) {
4954
((MemberIdItem) i).setIndex(idx);
5055
idx++;
5156
}
5257
}
58+
59+
private String getTooManyMembersMessage() {
60+
Map<String, AtomicInteger> membersByPackage = new TreeMap<String, AtomicInteger>();
61+
for (Object member : items()) {
62+
String packageName = ((MemberIdItem) member).getDefiningClass().getPackageName();
63+
AtomicInteger count = membersByPackage.get(packageName);
64+
if (count == null) {
65+
count = new AtomicInteger();
66+
membersByPackage.put(packageName, count);
67+
}
68+
count.incrementAndGet();
69+
}
70+
71+
Formatter formatter = new Formatter();
72+
try {
73+
String memberType = this instanceof MethodIdsSection ? "method" : "field";
74+
formatter.format("Too many %s references: %d; max is %d.%n" +
75+
Main.getTooManyIdsErrorMessage() + "%n" +
76+
"References by package:",
77+
memberType, items().size(), DexFormat.MAX_MEMBER_IDX + 1);
78+
for (Map.Entry<String, AtomicInteger> entry : membersByPackage.entrySet()) {
79+
formatter.format("%n%6d %s", entry.getValue().get(), entry.getKey());
80+
}
81+
return formatter.toString();
82+
} finally {
83+
formatter.close();
84+
}
85+
}
86+
5387
}

dx/src/com/android/dx/dex/file/TypeIdsSection.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public void writeHeaderPart(AnnotatedOutput out) {
8585
int offset = (sz == 0) ? 0 : getFileOffset();
8686

8787
if (sz > DexFormat.MAX_TYPE_IDX + 1) {
88-
throw new DexException(Main.TO_MANY_ID_ERROR_MESSAGE);
88+
throw new DexException("Too many type references: " + sz +
89+
"; max is " + (DexFormat.MAX_TYPE_IDX + 1) + ".\n" +
90+
Main.getTooManyIdsErrorMessage());
8991
}
9092

9193
if (out.annotates()) {

tests/089-many-methods/expected.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2-
trouble writing output: Too many fields: 131000; max is 65536. By package:
2+
trouble writing output: Too many field references: 131000; max is 65536.
3+
You may try using --multi-dex option.
4+
References by package:
35
131000 default
46
build exit status: 2

0 commit comments

Comments
 (0)