private 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(new Dex[] {dexA, dexB}, CollisionPolicy.KEEP_FIRST, context).merge();
    }

    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    result.writeTo(bytesOut);
    return bytesOut.toByteArray();
  }
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.
android/android_framework/dex-maker/src/main/java/com/android/dx/command/dexer/Main.java