use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class ProcessAwbAndroidResources method makeAapt.
private Aapt makeAapt() throws IOException {
AndroidBuilder builder = getBuilder();
MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
FileCache fileCache = appVariantContext.getScope().getGlobalScope().getBuildCache();
ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(aaptGeneration == AaptGeneration.AAPT_V1 ? new AaptOutputParser() : new Aapt2OutputParser(), getILogger()), new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));
return AaptGradleFactory.make(aaptGeneration, builder, processOutputHandler, fileCache, true, FileUtils.mkdirs(new File(getIncrementalFolder(), "awb-aapt-temp/" + awbBundle.getName())), aaptOptions.getCruncherProcesses());
}
use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class AtlasDesugarTransform method initDesugarJar.
/**
* Set this location of extracted desugar jar that is used for processing.
*/
private static void initDesugarJar(@Nullable FileCache cache) throws IOException {
if (isDesugarJarInitialized()) {
return;
}
URL url = DesugarProcessBuilder.class.getClassLoader().getResource(DESUGAR_JAR);
Preconditions.checkNotNull(url);
Path extractedDesugar = null;
if (cache != null) {
try {
String fileHash;
try (HashingInputStream stream = new HashingInputStream(Hashing.sha256(), url.openStream())) {
fileHash = stream.hash().toString();
}
FileCache.Inputs inputs = new FileCache.Inputs.Builder(FileCache.Command.EXTRACT_DESUGAR_JAR).putString("pluginVersion", Version.ANDROID_GRADLE_PLUGIN_VERSION).putString("jarUrl", url.toString()).putString("fileHash", fileHash).build();
File cachedFile = cache.createFileInCacheIfAbsent(inputs, file -> copyDesugarJar(url, file.toPath())).getCachedFile();
Preconditions.checkNotNull(cachedFile);
extractedDesugar = cachedFile.toPath();
} catch (IOException | ExecutionException e) {
logger.error(e, "Unable to cache Desugar jar. Extracting to temp dir.");
}
}
synchronized (desugarJar) {
if (isDesugarJarInitialized()) {
return;
}
if (extractedDesugar == null) {
extractedDesugar = PathUtils.createTmpToRemoveOnShutdown(DESUGAR_JAR);
copyDesugarJar(url, extractedDesugar);
}
desugarJar.set(extractedDesugar);
}
}
use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class TransformReplacer method replaceDexArchiveBuilderTransform.
public void replaceDexArchiveBuilderTransform(BaseVariantOutput vod) {
List<TransformTask> list = TransformManager.findTransformTaskByTransformType(variantContext, DexArchiveBuilderTransform.class);
DefaultDexOptions dexOptions = variantContext.getAppExtension().getDexOptions();
boolean minified = variantContext.getScope().getCodeShrinker() != null;
ProjectOptions projectOptions = variantContext.getScope().getGlobalScope().getProjectOptions();
FileCache userLevelCache = getUserDexCache(minified, dexOptions.getPreDexLibraries());
for (TransformTask transformTask : list) {
AtlasDexArchiveBuilderTransform atlasDexArchiveBuilderTransform = new AtlasDexArchiveBuilderTransform(variantContext, vod, dexOptions, variantContext.getScope().getGlobalScope().getAndroidBuilder().getErrorReporter(), userLevelCache, variantContext.getScope().getMinSdkVersion().getFeatureLevel(), variantContext.getScope().getDexer(), projectOptions.get(BooleanOption.ENABLE_GRADLE_WORKERS), projectOptions.get(IntegerOption.DEXING_READ_BUFFER_SIZE), projectOptions.get(IntegerOption.DEXING_WRITE_BUFFER_SIZE), variantContext.getScope().getVariantConfiguration().getBuildType().isDebuggable());
atlasDexArchiveBuilderTransform.setTransformTask(transformTask);
ReflectUtils.updateField(transformTask, "transform", atlasDexArchiveBuilderTransform);
if (variantContext.getScope().getInstantRunBuildContext().isInInstantRunMode() && variantContext.getVariantConfiguration().getMinSdkVersion().getApiLevel() < 21) {
transformTask.doLast(task -> {
task.getLogger().info("generate maindexList......");
generateMainDexList(variantContext.getScope());
});
}
}
}
use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class AtlasDexArchiveBuilderCacheHander method getCachedVersionIfPresent.
@Nullable
public File getCachedVersionIfPresent(File input) throws Exception {
assert input.isFile();
FileCache cache = getBuildCache(input, true, userLevelCache);
if (cache == null) {
return null;
}
FileCache.Inputs buildCacheInputs = getBuildCacheInputs(input, dexOptions, dexer, minSdkVersion, isDebuggable);
return cache.cacheEntryExists(buildCacheInputs) ? cache.getFileInCache(buildCacheInputs) : null;
}
use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class AtlasDexArchiveBuilderCacheHander method populateCache.
public void populateCache(File input, File out) throws Exception {
FileCache cache = getBuildCache(input, true, userLevelCache);
if (cache != null) {
FileCache.Inputs buildCacheInputs = AtlasDexArchiveBuilderCacheHander.getBuildCacheInputs(input, dexOptions, dexer, minSdkVersion, isDebuggable);
FileCache.QueryResult result = cache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
Files.copy(out.toPath(), in.toPath());
});
if (result.getQueryEvent().equals(FileCache.QueryEvent.CORRUPTED)) {
Verify.verifyNotNull(result.getCauseOfCorruption());
logger.info("The build cache at '%1$s' contained an invalid cache entry.\n" + "Cause: %2$s\n" + "We have recreated the cache entry.\n" + "%3$s", cache.getCacheDirectory().getAbsolutePath(), Throwables.getStackTraceAsString(result.getCauseOfCorruption()), BuildCacheUtils.BUILD_CACHE_TROUBLESHOOTING_MESSAGE);
} else if (result.getQueryEvent().equals(FileCache.QueryEvent.MISSED)) {
logger.warning("miss D8 cache:" + input.getAbsolutePath());
} else if (result.getQueryEvent().equals(FileCache.QueryEvent.HIT)) {
logger.warning("hit D8 cache:" + input.getAbsolutePath());
}
}
}
Aggregations