Search in sources :

Example 1 with DexException

use of com.taobao.android.dex.DexException in project atlas by alibaba.

the class Main method processAllFiles.

/**
     * Constructs the output {@link DexFile}, fill it in with all the
     * specified classes, and populate the resources map if required.
     *
     * @return whether processing was successful
     */
private boolean processAllFiles() {
    createDexFile();
    if (args.jarOutput) {
        outputResources = new TreeMap<String, byte[]>();
    }
    anyFilesProcessed = false;
    String[] fileNames = args.fileNames;
    if (args.numThreads > 1) {
        threadPool = Executors.newFixedThreadPool(args.numThreads);
        parallelProcessorFutures = new ArrayList<Future<Void>>();
    }
    try {
        if (args.mainDexListFile != null) {
            // with --main-dex-list
            FileNameFilter mainPassFilter = args.strictNameCheck ? new MainDexListFilter() : new BestEffortMainDexListFilter();
            // forced in main dex
            for (int i = 0; i < fileNames.length; i++) {
                processOne(fileNames[i], mainPassFilter);
            }
            if (dexOutputArrays.size() > 0) {
                throw new DexException("Too many classes in " + Arguments.MAIN_DEX_LIST_OPTION + ", main dex capacity exceeded");
            }
            if (args.minimalMainDex) {
                // start second pass directly in a secondary dex file.
                createDexFile();
            }
            // remaining files
            for (int i = 0; i < fileNames.length; i++) {
                processOne(fileNames[i], new NotFilter(mainPassFilter));
            }
        } else {
            // without --main-dex-list
            for (int i = 0; i < fileNames.length; i++) {
                processOne(fileNames[i], ClassPathOpener.acceptAll);
            }
        }
    } catch (StopProcessing ex) {
    /*
             * Ignore it and just let the error reporting do
             * their things.
             */
    }
    if (args.numThreads > 1) {
        try {
            threadPool.shutdown();
            if (!threadPool.awaitTermination(600L, TimeUnit.SECONDS)) {
                throw new RuntimeException("Timed out waiting for threads.");
            }
        } catch (InterruptedException ex) {
            threadPool.shutdownNow();
            throw new RuntimeException("A thread has been interrupted.");
        }
        try {
            for (Future<?> future : parallelProcessorFutures) {
                future.get();
            }
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            // should remain
            if (cause instanceof Error) {
                throw (Error) e.getCause();
            } else {
                throw new AssertionError(e.getCause());
            }
        } catch (InterruptedException e) {
            // any InterruptedException
            throw new AssertionError(e);
        }
    }
    int errorNum = errors.get();
    if (errorNum != 0) {
        dxConsole.err.println(errorNum + " error" + ((errorNum == 1) ? "" : "s") + "; aborting");
        return false;
    }
    if (args.incremental && !anyFilesProcessed) {
        return true;
    }
    if (!(anyFilesProcessed || args.emptyOk)) {
        dxConsole.err.println("no classfiles specified");
        return false;
    }
    if (args.optimize && args.statistics) {
        args.cfOptions.codeStatistics.dumpStatistics(dxConsole.out);
    }
    return true;
}
Also used : DexException(com.taobao.android.dex.DexException) CstString(com.taobao.android.dx.rop.cst.CstString) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) FileNameFilter(com.taobao.android.dx.cf.direct.ClassPathOpener.FileNameFilter)

Example 2 with DexException

use of com.taobao.android.dex.DexException in project atlas by alibaba.

the class Main method runMultiDex.

private int runMultiDex() throws IOException {
    assert !args.incremental;
    assert args.numThreads == 1;
    if (args.mainDexListFile != null) {
        classesInMainDex = new HashSet<String>();
        readPathsFromFile(args.mainDexListFile, classesInMainDex);
    }
    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
        dexOutputArrays.add(writeDex());
        // Effectively free up the (often massive) DexFile memory.
        outputDex = null;
    }
    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.taobao.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.taobao.android.dx.rop.cst.CstString) DexFile(com.taobao.android.dx.dex.file.DexFile) DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) File(java.io.File)

Example 3 with DexException

use of com.taobao.android.dex.DexException in project atlas by alibaba.

the class DecodedInstruction method decodeAll.

/**
     * Decodes an array of instructions. The result has non-null
     * elements at each offset that represents the start of an
     * instruction.
     */
public static DecodedInstruction[] decodeAll(short[] encodedInstructions) {
    int size = encodedInstructions.length;
    DecodedInstruction[] decoded = new DecodedInstruction[size];
    ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);
    try {
        while (in.hasMore()) {
            decoded[in.cursor()] = DecodedInstruction.decode(in);
        }
    } catch (EOFException ex) {
        throw new DexException(ex);
    }
    return decoded;
}
Also used : DexException(com.taobao.android.dex.DexException) EOFException(java.io.EOFException)

Example 4 with DexException

use of com.taobao.android.dex.DexException in project atlas by alibaba.

the class DexMerger method readSortableTypes.

/**
     * Reads just enough data on each class so that we can sort it and then find
     * it later.
     */
private void readSortableTypes(SortableType[] sortableTypes, Dex buffer, IndexMap indexMap) {
    for (ClassDef classDef : buffer.classDefs()) {
        SortableType sortableType = indexMap.adjust(new SortableType(buffer, classDef));
        int t = sortableType.getTypeIndex();
        if (sortableTypes[t] == null) {
            sortableTypes[t] = sortableType;
        } else if (collisionPolicy != CollisionPolicy.KEEP_FIRST) {
            throw new DexException("Multiple dex files define " + buffer.typeNames().get(classDef.getTypeIndex()));
        }
    }
}
Also used : DexException(com.taobao.android.dex.DexException) ClassDef(com.taobao.android.dex.ClassDef)

Aggregations

DexException (com.taobao.android.dex.DexException)4 CstString (com.taobao.android.dx.rop.cst.CstString)2 ClassDef (com.taobao.android.dex.ClassDef)1 FileNameFilter (com.taobao.android.dx.cf.direct.ClassPathOpener.FileNameFilter)1 DirectClassFile (com.taobao.android.dx.cf.direct.DirectClassFile)1 DexFile (com.taobao.android.dx.dex.file.DexFile)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 JarOutputStream (java.util.jar.JarOutputStream)1