use of org.jf.dexlib2.writer.pool.BasePool in project atlas by alibaba.
the class PatchDexTool method writeDex.
public void writeDex(File outDexFolder, Set<ClassDef> classDefs) throws IOException {
int i = 0;
File outDexFile = getDexFile(outDexFolder, i);
if (!outDexFile.getParentFile().exists()) {
outDexFile.getParentFile().mkdirs();
}
if (mainBundle) {
List<ClassDef> sortClassDefs = sort(classDefs);
DexPool dexPool = new DexPool(Opcodes.getDefault());
Iterator<ClassDef> iterator = sortClassDefs.iterator();
while (iterator.hasNext()) {
ClassDef classDef = iterator.next();
dexPool.internClass(classDef);
if (((BasePool) dexPool.methodSection).getItemCount() > MAX_COUNT || ((BasePool) dexPool.fieldSection).getItemCount() > MAX_COUNT) {
dexPool.writeTo(new FileDataStore(outDexFile));
outDexFile = getDexFile(outDexFolder, ++i);
dexPool = new DexPool(Opcodes.getDefault());
}
}
dexPool.writeTo(new FileDataStore(outDexFile));
} else {
DexFileFactory.writeDexFile(outDexFile.getAbsolutePath(), new DexFile() {
@Nonnull
@Override
public Set<? extends ClassDef> getClasses() {
return new AbstractSet<ClassDef>() {
@Nonnull
@Override
public Iterator<ClassDef> iterator() {
return classDefs.iterator();
}
@Override
public int size() {
return classDefs.size();
}
};
}
@Nonnull
@Override
public Opcodes getOpcodes() {
return Opcodes.getDefault();
}
});
}
}
Aggregations