use of com.android.dex.Dex in project buck by facebook.
the class DexMerger method main.
public static void main(String[] args) throws IOException {
if (args.length < 2) {
printUsage();
return;
}
Dex[] dexes = new Dex[args.length - 1];
for (int i = 1; i < args.length; i++) {
dexes[i - 1] = new Dex(new File(args[i]));
}
Dex merged = new DexMerger(dexes, CollisionPolicy.KEEP_FIRST, new DxContext()).merge();
merged.writeTo(new File(args[0]));
}
use of com.android.dex.Dex in project buck by facebook.
the class Main method main.
public static void main(String[] args) throws IOException {
String dexFile = args[0];
String declaredBy = args[1];
String memberName = args[2];
Dex dex = new Dex(new File(dexFile));
PrintWriter out = new PrintWriter(System.out);
new FindUsages(dex, declaredBy, memberName, out).findUsages();
out.flush();
}
use of com.android.dex.Dex in project buck by facebook.
the class DexMergeTest method testMergedOutputSizeIsBounded.
/**
* Merging dex files uses pessimistic sizes that naturally leave gaps in the
* output files. If those gaps grow too large, the merger is supposed to
* compact the result. This exercises that by repeatedly merging a dex with
* itself.
*/
public void testMergedOutputSizeIsBounded() throws Exception {
/*
* At the time this test was written, the output would grow ~25% with
* each merge. Setting a low 1KiB ceiling on the maximum size caused
* the file to be compacted every four merges.
*/
int steps = 100;
int compactWasteThreshold = 1024;
Dex dexA = resourceToDexBuffer("/testdata/Basic.dex");
Dex dexB = resourceToDexBuffer("/testdata/TryCatchFinally.dex");
Dex merged = new DexMerger(dexA, dexB, CollisionPolicy.KEEP_FIRST).merge();
int maxLength = 0;
for (int i = 0; i < steps; i++) {
DexMerger dexMerger = new DexMerger(dexA, merged, CollisionPolicy.KEEP_FIRST);
dexMerger.setCompactWasteThreshold(compactWasteThreshold);
merged = dexMerger.merge();
maxLength = Math.max(maxLength, merged.getLength());
}
int maxExpectedLength = dexA.getLength() + dexB.getLength() + compactWasteThreshold;
assertTrue(maxLength + " < " + maxExpectedLength, maxLength < maxExpectedLength);
}
use of com.android.dex.Dex in project buck by facebook.
the class MergeConflictTest method testMergeConflict.
public void testMergeConflict() throws IOException {
Dex a = resourceToDexBuffer("/testdata/A.dex");
Dex b = resourceToDexBuffer("/testdata/B.dex");
// a and b don't overlap; this should succeed
Dex ab = new DexMerger(a, b, CollisionPolicy.FAIL).merge();
// a and ab overlap; this should fail
DexMerger dexMerger = new DexMerger(a, ab, CollisionPolicy.FAIL);
try {
dexMerger.merge();
fail();
} catch (DexException expected) {
assertEquals("Multiple dex files define Ltestdata/A;", expected.getMessage());
}
}
use of com.android.dex.Dex in project bazel by bazelbuild.
the class DexFileAggregator method writeMergedFile.
private void writeMergedFile(Dex... dexes) throws IOException {
Dex merged = merge(dexes);
dest.addFile(nextArchiveEntry(), merged);
}
Aggregations