protected boolean hasOverflowed() { if (!curPool.hasOverflowed()) { return false; } // We only support splitting for api versions since Lollipop (22). // Since Api 22, Art runtime is used which needs to extract all dex // files anyway. Thus, // we can pack classes arbitrarily and do not need to care about which // classes need to go together in // the same dex file. // For Dalvik (pre 22), it is important that at least the main dex file // (classes.dex) contains all needed // dependencies of the Main activity, which means that one would have to // determine necessary dependencies and // pack those explicitly in the first dex file. // (https://developer.android.com/studio/build/multidex.html, // http://www.fasteque.com/deep-dive-into-android-multidex/) if (!opcodes.isArt()) { throw new RuntimeException("Dex file overflow. Splitting not support for pre Lollipop Android (Api 22)."); } return true; }
public void internClass(final ClassDef clz) { curPool.mark(); curPool.internClass(clz); if (hasOverflowed()) { // reset to state before overflow occurred curPool.reset(); // we need a new dexpool newDexPool(); // re-execute on new pool since the last execution was dropped // NOTE: We do not want to call internClass recursively here, this // might end in an endless loop // if the class is to large for a single dex file! curPool.internClass(clz); // If a single class causes an overflow, we're really out of luck if (curPool.hasOverflowed()) { throw new RuntimeException("Class is bigger than a single dex file can be"); } } }