Search in sources :

Example 1 with DexFile

use of com.android.dx.dex.file.DexFile in project kotlin by JetBrains.

the class DxChecker method checkFileWithDx.

private static void checkFileWithDx(byte[] bytes, @NotNull String relativePath, @NotNull Main.Arguments arguments) {
    DirectClassFile cf = new DirectClassFile(bytes, relativePath, true);
    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    CfTranslator.translate(cf, bytes, arguments.cfOptions, arguments.dexOptions, new DexFile(arguments.dexOptions));
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) DexFile(com.android.dx.dex.file.DexFile)

Example 2 with DexFile

use of com.android.dx.dex.file.DexFile in project bazel by bazelbuild.

the class DexConverter method toDexFile.

public DexFile toDexFile(byte[] classfile, String classfilePath) {
    DexFile result = dexing.newDexFile();
    dexing.addToDexFile(result, Dexing.parseClassFile(classfile, classfilePath));
    return result;
}
Also used : DexFile(com.android.dx.dex.file.DexFile)

Example 3 with DexFile

use of com.android.dx.dex.file.DexFile in project buck by facebook.

the class Main method runMultiDex.

private int runMultiDex() throws IOException {
    assert !args.incremental;
    if (args.mainDexListFile != null) {
        classesInMainDex = new HashSet<String>();
        readPathsFromFile(args.mainDexListFile, classesInMainDex);
    }
    dexOutPool = Executors.newFixedThreadPool(args.numThreads);
    if (!processAllFiles()) {
        return 1;
    }
    if (!libraryDexBuffers.isEmpty()) {
        throw new DexException("Library dex files are not supported in multi-dex mode");
    }
    if (outputDex != null) {
        // this array is null if no classes were defined
        dexOutputFutures.add(dexOutPool.submit(new DexWriter(outputDex)));
        // Effectively free up the (often massive) DexFile memory.
        outputDex = null;
    }
    try {
        dexOutPool.shutdown();
        if (!dexOutPool.awaitTermination(600L, TimeUnit.SECONDS)) {
            throw new RuntimeException("Timed out waiting for dex writer threads.");
        }
        for (Future<byte[]> f : dexOutputFutures) {
            dexOutputArrays.add(f.get());
        }
    } catch (InterruptedException ex) {
        dexOutPool.shutdownNow();
        throw new RuntimeException("A dex writer thread has been interrupted.");
    } catch (Exception e) {
        dexOutPool.shutdownNow();
        throw new RuntimeException("Unexpected exception in dex writer thread");
    }
    if (args.jarOutput) {
        for (int i = 0; i < dexOutputArrays.size(); i++) {
            outputResources.put(getDexFileName(i), dexOutputArrays.get(i));
        }
        if (!createJar(args.outName)) {
            return 3;
        }
    } else if (args.outName != null) {
        File outDir = new File(args.outName);
        assert outDir.isDirectory();
        for (int i = 0; i < dexOutputArrays.size(); i++) {
            OutputStream out = new FileOutputStream(new File(outDir, getDexFileName(i)));
            try {
                out.write(dexOutputArrays.get(i));
            } finally {
                closeOutput(out);
            }
        }
    }
    return 0;
}
Also used : DexException(com.android.dex.DexException) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) CstString(com.android.dx.rop.cst.CstString) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) DexFile(com.android.dx.dex.file.DexFile) File(java.io.File) SimException(com.android.dx.cf.code.SimException) UsageException(com.android.dx.command.UsageException) ParseException(com.android.dx.cf.iface.ParseException) DexException(com.android.dex.DexException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with DexFile

use of com.android.dx.dex.file.DexFile in project dexmaker by linkedin.

the class DexMaker method getDexFile.

DexFile getDexFile() {
    if (outputDex == null) {
        DexOptions options = new DexOptions();
        options.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES;
        outputDex = new DexFile(options);
    }
    return outputDex;
}
Also used : DexOptions(com.android.dx.dex.DexOptions) DexFile(com.android.dx.dex.file.DexFile)

Example 5 with DexFile

use of com.android.dx.dex.file.DexFile in project buck by facebook.

the class Main method runMonoDex.

private int runMonoDex() throws IOException {
    File incrementalOutFile = null;
    if (args.incremental) {
        if (args.outName == null) {
            err.println("error: no incremental output name specified");
            return -1;
        }
        incrementalOutFile = new File(args.outName);
        if (incrementalOutFile.exists()) {
            minimumFileAge = incrementalOutFile.lastModified();
        }
    }
    if (!processAllFiles()) {
        return 1;
    }
    if (args.incremental && !anyFilesProcessed) {
        // this was a no-op incremental build
        return 0;
    }
    // this array is null if no classes were defined
    byte[] outArray = null;
    if (!outputDex.isEmpty() || (args.humanOutName != null)) {
        outArray = writeDex(outputDex);
        if (outArray == null) {
            return 2;
        }
        computeReferencedResources();
    }
    if (args.incremental) {
        outArray = mergeIncremental(outArray, incrementalOutFile);
    }
    outArray = mergeLibraryDexBuffers(outArray);
    if (args.jarOutput) {
        // Effectively free up the (often massive) DexFile memory.
        outputDex = null;
        if (outArray != null) {
            outputResources.put(DexFormat.DEX_IN_JAR_NAME, outArray);
        }
        if (!createJar(args.outName)) {
            return 3;
        }
    } else if (outArray != null && args.outName != null) {
        OutputStream out = openOutput(args.outName);
        out.write(outArray);
        closeOutput(out);
    }
    return 0;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) DexFile(com.android.dx.dex.file.DexFile) File(java.io.File)

Aggregations

DexFile (com.android.dx.dex.file.DexFile)9 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4 JarOutputStream (java.util.jar.JarOutputStream)4 DexOptions (com.android.dx.dex.DexOptions)3 IOException (java.io.IOException)3 DexException (com.android.dex.DexException)2 SimException (com.android.dx.cf.code.SimException)2 ParseException (com.android.dx.cf.iface.ParseException)2 UsageException (com.android.dx.command.UsageException)2 CstString (com.android.dx.rop.cst.CstString)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)1