Search in sources :

Example 1 with Main

use of com.taobao.android.dx.command.dexer.Main in project atlas by alibaba.

the class MemberIdsSection method getTooManyMembersMessage.

private String getTooManyMembersMessage() {
    Map<String, AtomicInteger> membersByPackage = new TreeMap<String, AtomicInteger>();
    for (Object member : items()) {
        String packageName = ((MemberIdItem) member).getDefiningClass().getPackageName();
        AtomicInteger count = membersByPackage.get(packageName);
        if (count == null) {
            count = new AtomicInteger();
            membersByPackage.put(packageName, count);
        }
        count.incrementAndGet();
    }
    Formatter formatter = new Formatter();
    try {
        String memberType = this instanceof MethodIdsSection ? "method" : "field";
        formatter.format("Too many %s references: %d; max is %d.%n" + new Main().getTooManyIdsErrorMessage() + "%n" + "References by package:", memberType, items().size(), DexFormat.MAX_MEMBER_IDX + 1);
        for (Map.Entry<String, AtomicInteger> entry : membersByPackage.entrySet()) {
            formatter.format("%n%6d %s", entry.getValue().get(), entry.getKey());
        }
        return formatter.toString();
    } finally {
        formatter.close();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Formatter(java.util.Formatter) TreeMap(java.util.TreeMap) Main(com.taobao.android.dx.command.dexer.Main) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with Main

use of com.taobao.android.dx.command.dexer.Main in project atlas by alibaba.

the class TypeIdsSection method writeHeaderPart.

/**
 * Writes the portion of the file header that refers to this instance.
 *
 * @param out {@code non-null;} where to write
 */
public void writeHeaderPart(AnnotatedOutput out) {
    throwIfNotPrepared();
    int sz = typeIds.size();
    int offset = (sz == 0) ? 0 : getFileOffset();
    if (sz > DexFormat.MAX_TYPE_IDX + 1) {
        throw new DexIndexOverflowException("Too many type references: " + sz + "; max is " + (DexFormat.MAX_TYPE_IDX + 1) + ".\n" + new Main().getTooManyIdsErrorMessage());
    }
    if (out.annotates()) {
        out.annotate(4, "type_ids_size:   " + Hex.u4(sz));
        out.annotate(4, "type_ids_off:    " + Hex.u4(offset));
    }
    out.writeInt(sz);
    out.writeInt(offset);
}
Also used : DexIndexOverflowException(com.taobao.android.dex.DexIndexOverflowException) Main(com.taobao.android.dx.command.dexer.Main)

Example 3 with Main

use of com.taobao.android.dx.command.dexer.Main in project atlas by alibaba.

the class DexBuilderUtils method buildDexInJvm.

/**
 * 在jvm中编译dex
 * @param inJar
 * @param outDex
 * @param commandArgs
 * @return
 * @throws IOException
 */
public static File buildDexInJvm(File inJar, File outDex, List<String> commandArgs) throws IOException {
    File parentDir = outDex.getParentFile();
    parentDir.mkdirs();
    // 先用3个线程来运行
    commandArgs.add("--num-threads=3");
    commandArgs.add("--output=" + outDex.getAbsolutePath());
    commandArgs.add(inJar.getAbsolutePath());
    String[] args = new String[commandArgs.size()];
    commandArgs.toArray(args);
    // Main.Arguments arguments = new Main.Arguments();
    // arguments.parse(args);
    new Main().main(args);
    return outDex;
}
Also used : File(java.io.File) Main(com.taobao.android.dx.command.dexer.Main)

Example 4 with Main

use of com.taobao.android.dx.command.dexer.Main in project atlas by alibaba.

the class DexWrapperHook method run.

public static ProcessResult run(@NonNull DexProcessBuilder processBuilder, @NonNull DexOptions dexOptions, @NonNull ProcessOutputHandler outputHandler) throws IOException, ProcessException {
    ProcessOutput output = outputHandler.createOutput();
    int res;
    try {
        // DxConsole.out = outputHandler.createOutput().getStandardOutput();
        // DxConsole.err = outputHandler.createOutput().getErrorOutput();
        DxConsole dxConsole = new DxConsole();
        Main.Arguments args = buildArguments(processBuilder, dexOptions, dxConsole);
        res = new Main().run(args);
    } finally {
        output.close();
    }
    outputHandler.handleOutput(output);
    return new DexProcessResult(res);
}
Also used : ProcessOutput(com.android.ide.common.process.ProcessOutput) DxConsole(com.taobao.android.dx.command.DxConsole) Main(com.taobao.android.dx.command.dexer.Main)

Aggregations

Main (com.taobao.android.dx.command.dexer.Main)4 ProcessOutput (com.android.ide.common.process.ProcessOutput)1 DexIndexOverflowException (com.taobao.android.dex.DexIndexOverflowException)1 DxConsole (com.taobao.android.dx.command.DxConsole)1 File (java.io.File)1 Formatter (java.util.Formatter)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1