@VisibleForTesting protected void convertByteCode(List<File> inputFiles, File outputFolder) throws InterruptedException, ProcessException, IOException { dexByteCodeConverter.get().convertByteCode(inputFiles, outputFolder, false /* multiDexEnabled */, null /*getMainDexListFile */, dexOptions, new LoggedProcessOutputHandler(logger)); }
/** * Returns true if the library (jar or folder) contains class files, false otherwise. */ private static boolean checkLibraryClassesJar(@NonNull File input) throws IOException { if (!input.exists()) { return false; } if (input.isDirectory()) { return checkFolder(input); } try (ZipFile zipFile = new ZipFile(input)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.endsWith(DOT_CLASS) || name.endsWith(DOT_DEX)) { return true; } } return false; } }
public void runDexer( @NonNull final DexProcessBuilder builder, @NonNull final DexOptions dexOptions, @NonNull final ProcessOutputHandler processOutputHandler) throws ProcessException, IOException, InterruptedException { initDexExecutorService(dexOptions); if (dexOptions.getAdditionalParameters().contains("--no-optimize")) { mLogger.warning(DefaultDexOptions.OPTIMIZE_WARNING); } if (shouldDexInProcess(dexOptions)) { dexInProcess(builder, dexOptions, processOutputHandler); } else { dexOutOfProcess(builder, dexOptions, processOutputHandler); } }
Optional<Long> heapSize = parseSizeToBytes(dexOptions.getJavaMaxHeapSize()); if (heapSize.isPresent()) { requestedHeapSize = heapSize.get(); long maxMemory = getUserDefinedHeapSize();
long maxMemory = DexByteCodeConverter.getUserDefinedHeapSize();
if (checkLibraryClassesJar(input)) { verifiedInputs.add(input); .addInputs(verifiedInputs.build()); runDexer(builder, dexOptions, processOutputHandler);
/** * Returns the heap size that was specified by the -Xmx value from the user, or an approximated * value if the -Xmx value was not set or was set improperly. */ public static long getUserDefinedHeapSize() { for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { if (arg.startsWith("-Xmx")) { Optional<Long> heapSize = parseSizeToBytes(arg.substring("-Xmx".length())); if (heapSize.isPresent()) { return heapSize.get(); } break; } } // If the -Xmx value was not set or was set improperly, get an approximation of the // heap size long heapSize = 0; for (MemoryPoolMXBean mpBean : ManagementFactory.getMemoryPoolMXBeans()) { if (mpBean.getType() == MemoryType.HEAP) { heapSize += mpBean.getUsage().getMax(); } } return heapSize; }
.addInput(inputFile); getDexByteCodeConverter().runDexer(builder, dexOptions, processOutputHandler);
/** * Sets the SdkInfo and the targetInfo on the builder. This is required to actually * build (some of the steps). * * @see com.android.builder.sdk.SdkLoader */ public void setTargetInfo(@NonNull TargetInfo targetInfo) { mTargetInfo = targetInfo; mDexByteCodeConverter = new DexByteCodeConverter( getLogger(), mTargetInfo, mJavaProcessExecutor, mVerboseExec); if (mTargetInfo.getBuildTools().getRevision().compareTo(MIN_BUILD_TOOLS_REV) < 0) { mErrorReporter.handleSyncError( MIN_BUILD_TOOLS_REV.toString(), SyncIssue.TYPE_BUILD_TOOLS_TOO_LOW, String.format( "The SDK Build Tools revision (%1$s) is too low for project '%2$s'. " + "Minimum required is %3$s", mTargetInfo.getBuildTools().getRevision(), mProjectId, MIN_BUILD_TOOLS_REV)); } }
/** * Converts the bytecode to Dalvik format * @param inputs the input files * @param outDexFolder the location of the output folder * @param dexOptions dex options * @throws IOException failed * @throws InterruptedException failed * @throws ProcessException failed */ public void convertByteCode( @NonNull Collection<File> inputs, @NonNull File outDexFolder, boolean multidex, @Nullable File mainDexList, @NonNull DexOptions dexOptions, @NonNull ProcessOutputHandler processOutputHandler) throws IOException, InterruptedException, ProcessException { getDexByteCodeConverter().convertByteCode(inputs, outDexFolder, multidex, mainDexList, dexOptions, processOutputHandler); }
/** * Returns true if this folder or one of its subfolder contains a class file, false otherwise. */ private static boolean checkFolder(@NonNull File folder) { File[] subFolders = folder.listFiles(); if (subFolders != null) { for (File childFolder : subFolders) { if (childFolder.isFile()) { String name = childFolder.getName(); if (name.endsWith(DOT_CLASS) || name.endsWith(DOT_DEX)) { return true; } } if (childFolder.isDirectory()) { // if childFolder returns false, continue search otherwise return success. if (checkFolder(childFolder)) { return true; } } } } return false; } }