Search in sources :

Example 16 with Dex

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]));
}
Also used : DxContext(com.android.dx.command.dexer.DxContext) Dex(com.android.dex.Dex) File(java.io.File)

Example 17 with Dex

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();
}
Also used : Dex(com.android.dex.Dex) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 18 with Dex

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);
}
Also used : Dex(com.android.dex.Dex)

Example 19 with Dex

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());
    }
}
Also used : DexException(com.android.dex.DexException) Dex(com.android.dex.Dex)

Example 20 with Dex

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);
}
Also used : Dex(com.android.dex.Dex)

Aggregations

Dex (com.android.dex.Dex)22 File (java.io.File)7 DexMerger (com.android.dx.merge.DexMerger)5 DxContext (com.android.dx.command.dexer.DxContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 ZipEntry (java.util.zip.ZipEntry)2 DexException (com.android.dex.DexException)1 DexIndexOverflowException (com.android.dex.DexIndexOverflowException)1 StaticValuesParser (jadx.core.dex.nodes.parser.StaticValuesParser)1 DecodeException (jadx.core.utils.exceptions.DecodeException)1 JadxException (jadx.core.utils.exceptions.JadxException)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 FileOutputStream (java.io.FileOutputStream)1 BufferOverflowException (java.nio.BufferOverflowException)1 ZipFile (java.util.zip.ZipFile)1