Search in sources :

Example 1 with DexMerger

use of com.taobao.atlas.dexmerge.dx.merge.DexMerger in project atlas by alibaba.

the class MergeExcutorServices method dexMergeInternal.

private void dexMergeInternal(InputStream[] inputStreams, OutputStream newDexStream, String bundleName) {
    FileOutputStream fileOutputStream = null;
    if (inputStreams[0] == null || inputStreams[1] == null) {
        try {
            mCallback.onMergeFinish(bundleName, false, "argNUll");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    try {
        //方式一
        //            DexPatchApplier dexPatchApplier = new DexPatchApplier(inputStreams[0],inputStreams[1]);
        //            dexPatchApplier.executeAndSaveTo(newDexStream);
        //方式二
        Dex dex1 = new Dex(inputStreams[1]);
        Dex dex2 = new Dex(inputStreams[0]);
        List<Dex> dexs = new ArrayList<Dex>();
        dexs.add(dex1);
        dexs.add(dex2);
        DexMerger mDexMerge = new DexMerger(new Dex[] { dex1, dex2 }, CollisionPolicy.KEEP_FIRST);
        mDexMerge.setCompactWasteThreshold(1);
        Dex outDex = mDexMerge.merge();
        outDex.writeTo(newDexStream);
        newDexStream.flush();
        mCallback.onMergeFinish(bundleName, true, "Success");
        successCount.incrementAndGet();
    } catch (Throwable e) {
        e.printStackTrace();
        try {
            mCallback.onMergeFinish(bundleName, false, "IOException 2");
        } catch (RemoteException e1) {
            e1.printStackTrace();
        }
    } finally {
        if (fileOutputStream != null) {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Dex(com.taobao.atlas.dex.Dex) ArrayList(java.util.ArrayList) DexMerger(com.taobao.atlas.dexmerge.dx.merge.DexMerger) RemoteException(android.os.RemoteException)

Example 2 with DexMerger

use of com.taobao.atlas.dexmerge.dx.merge.DexMerger in project atlas by alibaba.

the class MergeTool method processDex.

private static Dex processDex(InputStream inputStream, List<String> patchClassNames) throws IOException {
    Dex oringnalDex = new Dex(inputStream);
    DexMerger dexMerger = new DexMerger(new Dex[] { oringnalDex, new Dex(0) }, CollisionPolicy.FAIL);
    dexMerger.setRemoveTypeClasses(patchClassNames);
    dexMerger.setCompactWasteThreshold(1);
    Dex dex = dexMerger.merge();
    return dex;
}
Also used : Dex(com.taobao.atlas.dex.Dex) DexMerger(com.taobao.atlas.dexmerge.dx.merge.DexMerger)

Aggregations

Dex (com.taobao.atlas.dex.Dex)2 DexMerger (com.taobao.atlas.dexmerge.dx.merge.DexMerger)2 RemoteException (android.os.RemoteException)1 ArrayList (java.util.ArrayList)1