use of com.taobao.android.dx.merge.DexMerger in project atlas by alibaba.
the class Main method mergeIncremental.
/**
* Merges the dex files {@code update} and {@code base}, preferring
* {@code update}'s definition for types defined in both dex files.
*
* @param base a file to find the previous dex file. May be a .dex file, a
* jar file possibly containing a .dex file, or null.
* @return the bytes of the merged dex file, or null if both the update
* and the base dex do not exist.
*/
private static byte[] mergeIncremental(byte[] update, File base) throws IOException {
Dex dexA = null;
Dex dexB = null;
if (update != null) {
dexA = new Dex(update);
}
if (base.exists()) {
dexB = new Dex(base);
}
Dex result;
if (dexA == null && dexB == null) {
return null;
} else if (dexA == null) {
result = dexB;
} else if (dexB == null) {
result = dexA;
} else {
result = new DexMerger(ImmutableList.of(dexA, dexB), CollisionPolicy.KEEP_FIRST).merge();
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
result.writeTo(bytesOut);
return bytesOut.toByteArray();
}
use of com.taobao.android.dx.merge.DexMerger 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;
}
use of com.taobao.android.dx.merge.DexMerger in project atlas by alibaba.
the class MergePatch method mergeCode.
private void mergeCode(File dexFile) throws IOException {
Dex dexA = null;
Dex dexB = null;
for (File file : patchs) {
if (!dexFile.exists() && dexA == null) {
dexA = getDexFromJar(file);
continue;
} else if (dexFile.exists()) {
dexA = new Dex(dexFile);
}
dexB = getDexFromJar(file);
Dex[] dexs = new Dex[2];
dexs[0] = dexA;
dexs[1] = dexB;
// List<Dex>dexes = new ArrayList<>();
List<Dex> dexes = Arrays.asList(dexs);
DexMerger dexMerger = new DexMerger(dexes, CollisionPolicy.FAIL);
dexMerger.merge().writeTo(dexFile);
}
}