use of com.android.dx.merge.DexMerger in project bazel by bazelbuild.
the class DexFileAggregator method merge.
private Dex merge(Dex... dexes) throws IOException {
switch(dexes.length) {
case 0:
return new Dex(0);
case 1:
return dexes[0];
default:
try {
DexMerger dexMerger = new DexMerger(dexes, CollisionPolicy.FAIL);
dexMerger.setCompactWasteThreshold(wasteThresholdPerDex);
return dexMerger.merge();
} catch (BufferOverflowException e) {
// Bug in dx can cause this for ~1500 or more classes
Dex[] left = Arrays.copyOf(dexes, dexes.length / 2);
Dex[] right = Arrays.copyOfRange(dexes, left.length, dexes.length);
System.err.printf("Couldn't merge %d classes, trying %d%n", dexes.length, left.length);
try {
return merge(merge(left), merge(right));
} catch (RuntimeException e2) {
e2.addSuppressed(e);
throw e2;
}
}
}
}
use of com.android.dx.merge.DexMerger in project buck by facebook.
the class Main method mergeLibraryDexBuffers.
/**
* Merges the dex files in library jars. If multiple dex files define the
* same type, this fails with an exception.
*/
private byte[] mergeLibraryDexBuffers(byte[] outArray) throws IOException {
ArrayList<Dex> dexes = new ArrayList<Dex>();
if (outArray != null) {
dexes.add(new Dex(outArray));
}
for (byte[] libraryDex : libraryDexBuffers) {
dexes.add(new Dex(libraryDex));
}
if (dexes.isEmpty()) {
return null;
}
DexMerger dexMerger = new DexMerger(dexes.toArray(new Dex[dexes.size()]), CollisionPolicy.FAIL, context);
Dex merged = dexMerger.merge();
return merged.getBytes();
}
use of com.android.dx.merge.DexMerger in project buck by facebook.
the class Main method mergeIncremental.
/**
* Merges the dex files {@code update} and {@code base}, preferring
* {@code update}'s definition for types defined in both dex files.
*
* @param base a file to find the previous dex file. May be a .dex file, a
* jar file possibly containing a .dex file, or null.
* @return the bytes of the merged dex file, or null if both the update
* and the base dex do not exist.
*/
private byte[] mergeIncremental(byte[] update, File base) throws IOException {
Dex dexA = null;
Dex dexB = null;
if (update != null) {
dexA = new Dex(update);
}
if (base.exists()) {
dexB = new Dex(base);
}
Dex result;
if (dexA == null && dexB == null) {
return null;
} else if (dexA == null) {
result = dexB;
} else if (dexB == null) {
result = dexA;
} else {
DexMerger dexMerger = new DexMerger(new Dex[] { dexA, dexB }, CollisionPolicy.KEEP_FIRST, context);
result = dexMerger.merge();
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
result.writeTo(bytesOut);
return bytesOut.toByteArray();
}
use of com.android.dx.merge.DexMerger in project J2ME-Loader by nikita36078.
the class Main method mergeLibraryDexBuffers.
/**
* Merges the dex files in library jars. If multiple dex files define the
* same type, this fails with an exception.
*/
private byte[] mergeLibraryDexBuffers(byte[] outArray) throws IOException {
ArrayList<Dex> dexes = new ArrayList<Dex>();
if (outArray != null) {
dexes.add(new Dex(outArray));
}
for (byte[] libraryDex : libraryDexBuffers) {
dexes.add(new Dex(libraryDex));
}
if (dexes.isEmpty()) {
return null;
}
Dex merged = new DexMerger(dexes.toArray(new Dex[dexes.size()]), CollisionPolicy.FAIL, context).merge();
return merged.getBytes();
}
use of com.android.dx.merge.DexMerger in project J2ME-Loader by nikita36078.
the class Main method mergeIncremental.
/**
* Merges the dex files {@code update} and {@code base}, preferring
* {@code update}'s definition for types defined in both dex files.
*
* @param base a file to find the previous dex file. May be a .dex file, a
* jar file possibly containing a .dex file, or null.
* @return the bytes of the merged dex file, or null if both the update
* and the base dex do not exist.
*/
private byte[] mergeIncremental(byte[] update, File base) throws IOException {
Dex dexA = null;
Dex dexB = null;
if (update != null) {
dexA = new Dex(update);
}
if (base.exists()) {
dexB = new Dex(base);
}
Dex result;
if (dexA == null && dexB == null) {
return null;
} else if (dexA == null) {
result = dexB;
} else if (dexB == null) {
result = dexA;
} else {
result = new DexMerger(new Dex[] { dexA, dexB }, CollisionPolicy.KEEP_FIRST, context).merge();
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
result.writeTo(bytesOut);
return bytesOut.toByteArray();
}
Aggregations