Search in sources :

Example 1 with Dex

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

the class MergePatch method getDexFromJar.

private Dex getDexFromJar(File file) throws IOException {
    JarFile jarFile = null;
    try {
        jarFile = new JarFile(file);
        JarEntry dexEntry = jarFile.getJarEntry("classes.dex");
        return new Dex(jarFile.getInputStream(dexEntry));
    } finally {
        if (jarFile != null) {
            jarFile.close();
        }
    }
}
Also used : Dex(com.taobao.android.dex.Dex) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 2 with Dex

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

the class Main method main.

public static void main(String[] args) throws IOException {
    String dexFile = args[0];
    String pattern = args[1];
    Dex dex = new Dex(new File(dexFile));
    int count = new Grep(dex, Pattern.compile(pattern), new PrintWriter(System.out)).grep();
    System.exit((count > 0) ? 0 : 1);
}
Also used : Dex(com.taobao.android.dex.Dex) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 3 with Dex

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

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.taobao.android.dex.Dex) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 4 with Dex

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

the class DexMerger method merge.

public Dex merge() throws IOException {
    long start = System.nanoTime();
    Dex result = mergeDexes();
    /*
         * We use pessimistic sizes when merging dex files. If those sizes
         * result in too many bytes wasted, compact the result. To compact,
         * simply merge the result with itself.
         */
    WriterSizes compactedSizes = new WriterSizes(this);
    int wastedByteCount = writerSizes.size() - compactedSizes.size();
    if (wastedByteCount > +compactWasteThreshold) {
        DexMerger compacter = new DexMerger(ImmutableList.of(dexOut, new Dex(0)), CollisionPolicy.FAIL, compactedSizes);
        result = compacter.mergeDexes();
    //            System.out.printf("Result compacted from %.1fKiB to %.1fKiB to save %.1fKiB%n",
    //                    dexOut.getLength() / 1024f,
    //                    result.getLength() / 1024f,
    //                    wastedByteCount / 1024f);
    }
    int origDefs = 0;
    int origSizes = 0;
    for (Dex d : dexs) {
        origDefs += d.getTableOfContents().classDefs.size;
        origSizes += d.getLength();
    }
    long elapsed = System.nanoTime() - start;
    return result;
}
Also used : Dex(com.taobao.android.dex.Dex)

Example 5 with Dex

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

the class DexBuilderUtils method mergeDex.

/**
     * 合并dex
     * @param dexs
     * @param outDexFile
     * @param policy
     * @return
     * @throws IOException
     */
public static File mergeDex(List<File> dexs, File outDexFile, CollisionPolicy policy) throws IOException {
    List<Dex> dexList = new ArrayList<Dex>();
    for (File dexFile : dexs) {
        dexList.add(new Dex(dexFile));
    }
    //        Dex[] dexArray = new Dex[dexList.size()];
    //        dexList.toArray(dexArray);
    DexMerger merger = new DexMerger(dexList, policy);
    Dex outDex = merger.merge();
    outDex.writeTo(outDexFile);
    return outDexFile;
}
Also used : Dex(com.taobao.android.dex.Dex) ArrayList(java.util.ArrayList) DexMerger(com.taobao.android.dx.merge.DexMerger) File(java.io.File)

Aggregations

Dex (com.taobao.android.dex.Dex)10 File (java.io.File)5 DexMerger (com.taobao.android.dx.merge.DexMerger)3 PrintWriter (java.io.PrintWriter)2 JarFile (java.util.jar.JarFile)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1