Search in sources :

Example 6 with DexFile

use of com.android.dx.dex.file.DexFile in project byte-buddy by raphw.

the class AndroidClassLoadingStrategyTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.class).apply();
    ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.Conversion.class).create(new ObjectPropertyAssertion.Creator<DexFile>() {

        @Override
        public DexFile create() {
            return new DexFile(new DexOptions());
        }
    }).apply();
}
Also used : DexOptions(com.android.dx.dex.DexOptions) DexFile(com.android.dx.dex.file.DexFile) Test(org.junit.Test)

Example 7 with DexFile

use of com.android.dx.dex.file.DexFile in project J2ME-Loader by nikita36078.

the class Main method runMonoDex.

private int runMonoDex() throws IOException {
    File incrementalOutFile = null;
    if (args.incremental) {
        if (args.outName == null) {
            context.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;
        }
    }
    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)

Example 8 with DexFile

use of com.android.dx.dex.file.DexFile in project J2ME-Loader by nikita36078.

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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) 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 9 with DexFile

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

the class DexMaker method generate.

/**
 * Generates a dex file and returns its bytes.
 */
public byte[] generate() {
    if (outputDex == null) {
        DexOptions options = new DexOptions();
        options.targetApiLevel = DexFormat.API_NO_EXTENDED_OPCODES;
        outputDex = new DexFile(options);
    }
    for (TypeDeclaration typeDeclaration : types.values()) {
        outputDex.add(typeDeclaration.toClassDefItem());
    }
    try {
        return outputDex.toDex(null, false);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DexOptions(com.android.dx.dex.DexOptions) IOException(java.io.IOException) DexFile(com.android.dx.dex.file.DexFile)

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