use of com.android.build.gradle.internal.tasks.KnownFilesSaveData in project atlas by alibaba.
the class AwbApkPackageTask method splitIncrementalAction.
private File splitIncrementalAction(ApkData apkData, @Nullable File processedResources, Map<File, FileStatus> changedInputs) throws IOException {
Set<File> androidResources = getAndroidResources(apkData, processedResources);
File incrementalDirForSplit = new File(getIncrementalFolder(awbBundle), apkData.getFullName());
File cacheByPathDir = new File(incrementalDirForSplit, ZIP_DIFF_CACHE_DIR);
if (!cacheByPathDir.exists()) {
FileUtils.mkdirs(cacheByPathDir);
}
FileCacheByPath cacheByPath = new FileCacheByPath(cacheByPathDir);
KnownFilesSaveData saveData = KnownFilesSaveData.make(incrementalDirForSplit);
final Set<File> assetsFiles = assets.getFiles();
Set<Runnable> cacheUpdates = new HashSet<>();
ImmutableMap<RelativeFile, FileStatus> changedDexFiles = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.DEX, dexFolders.getFiles(), cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedJavaResources;
try {
changedJavaResources = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.JAVA_RESOURCE, javaResouresFiles.getFiles(), cacheByPath, cacheUpdates);
} catch (Zip64NotSupportedException e) {
// copy all changedInputs into a smaller jar and rerun.
ImmutableMap.Builder<File, FileStatus> copiedInputs = ImmutableMap.builder();
for (Map.Entry<File, FileStatus> fileFileStatusEntry : changedInputs.entrySet()) {
copiedInputs.put(copyJavaResourcesOnly(getIncrementalFolder(awbBundle), fileFileStatusEntry.getKey()), fileFileStatusEntry.getValue());
}
changedJavaResources = KnownFilesSaveData.getChangedInputs(copiedInputs.build(), saveData, KnownFilesSaveData.InputSet.JAVA_RESOURCE, javaResouresFiles.getFiles(), cacheByPath, cacheUpdates);
}
ImmutableMap<RelativeFile, FileStatus> changedAssets = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.ASSET, assetsFiles, cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedAndroidResources = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.ANDROID_RESOURCE, androidResources, cacheByPath, cacheUpdates);
ImmutableMap<RelativeFile, FileStatus> changedNLibs = KnownFilesSaveData.getChangedInputs(changedInputs, saveData, KnownFilesSaveData.InputSet.NATIVE_RESOURCE, jniFolders.getFiles(), cacheByPath, cacheUpdates);
File outputFile = getOutputFile(awbBundle);
Collection<BuildOutput> manifestOutputs = BuildOutputs.load(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, awbManifestFolder.getSingleFile().getParentFile());
doTask(apkData, incrementalDirForSplit, outputFile, cacheByPath, manifestOutputs, changedDexFiles, changedJavaResources, changedAssets, changedAndroidResources, changedNLibs);
/*
* Update the cache
*/
cacheUpdates.forEach(Runnable::run);
/*
* Update the save data keep files.
*/
ImmutableMap<RelativeFile, FileStatus> allDex = IncrementalRelativeFileSets.fromZipsAndDirectories(dexFolders);
ImmutableMap<RelativeFile, FileStatus> allJavaResources = IncrementalRelativeFileSets.fromZipsAndDirectories(javaResouresFiles);
ImmutableMap<RelativeFile, FileStatus> allAssets = IncrementalRelativeFileSets.fromZipsAndDirectories(assetsFiles);
ImmutableMap<RelativeFile, FileStatus> allAndroidResources = IncrementalRelativeFileSets.fromZipsAndDirectories(androidResources);
ImmutableMap<RelativeFile, FileStatus> allJniResources = IncrementalRelativeFileSets.fromZipsAndDirectories(jniFolders);
saveData.setInputSet(allDex.keySet(), KnownFilesSaveData.InputSet.DEX);
saveData.setInputSet(allJavaResources.keySet(), KnownFilesSaveData.InputSet.JAVA_RESOURCE);
saveData.setInputSet(allAssets.keySet(), KnownFilesSaveData.InputSet.ASSET);
saveData.setInputSet(allAndroidResources.keySet(), KnownFilesSaveData.InputSet.ANDROID_RESOURCE);
saveData.setInputSet(allJniResources.keySet(), KnownFilesSaveData.InputSet.NATIVE_RESOURCE);
saveData.saveCurrentData();
return outputFile;
}
use of com.android.build.gradle.internal.tasks.KnownFilesSaveData in project atlas by alibaba.
the class AwbApkPackageTask method splitFullAction.
public File splitFullAction(@NonNull ApkData apkData, @Nullable File processedResources) throws IOException {
File incrementalDirForSplit = new File(getIncrementalFolder(awbBundle), apkData.getFullName());
/*
* Clear the intermediate build directory. We don't know if anything is in there and
* since this is a full build, we don't want to get any interference from previous state.
*/
if (incrementalDirForSplit.exists()) {
FileUtils.deleteDirectoryContents(incrementalDirForSplit);
} else {
FileUtils.mkdirs(incrementalDirForSplit);
}
File cacheByPathDir = new File(incrementalDirForSplit, ZIP_DIFF_CACHE_DIR);
FileUtils.mkdirs(cacheByPathDir);
FileCacheByPath cacheByPath = new FileCacheByPath(cacheByPathDir);
/*
* Clear the cache to make sure we have do not do an incremental build.
*/
cacheByPath.clear();
Set<File> androidResources = getAndroidResources(apkData, processedResources);
appVariantOutputContext.getVariantContext().getProject().getLogger().warn(awbBundle.getName() + " androidResources File:" + androidResources.iterator().next().getAbsolutePath());
FileUtils.mkdirs(outputDirectory);
File outputFile = getOutputFile(awbBundle);
/*
* Additionally, make sure we have no previous package, if it exists.
*/
FileUtils.deleteIfExists(outputFile);
ImmutableMap<RelativeFile, FileStatus> updatedDex = IncrementalRelativeFileSets.fromZipsAndDirectories(dexFolders);
ImmutableMap<RelativeFile, FileStatus> updatedJavaResources = getJavaResourcesChanges();
ImmutableMap<RelativeFile, FileStatus> updatedAssets = IncrementalRelativeFileSets.fromZipsAndDirectories(assets.getFiles());
ImmutableMap<RelativeFile, FileStatus> updatedAndroidResources = IncrementalRelativeFileSets.fromZipsAndDirectories(androidResources);
ImmutableMap<RelativeFile, FileStatus> updatedJniResources = IncrementalRelativeFileSets.fromZipsAndDirectories(jniFolders);
Collection<BuildOutput> manifestOutputs = BuildOutputs.load(TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, awbManifestFolder.getSingleFile().getParentFile());
doTask(apkData, incrementalDirForSplit, outputFile, cacheByPath, manifestOutputs, updatedDex, updatedJavaResources, updatedAssets, updatedAndroidResources, updatedJniResources);
/*
* Update the known files.
*/
KnownFilesSaveData saveData = KnownFilesSaveData.make(incrementalDirForSplit);
saveData.setInputSet(updatedDex.keySet(), KnownFilesSaveData.InputSet.DEX);
saveData.setInputSet(updatedJavaResources.keySet(), KnownFilesSaveData.InputSet.JAVA_RESOURCE);
saveData.setInputSet(updatedAssets.keySet(), KnownFilesSaveData.InputSet.ASSET);
saveData.setInputSet(updatedAndroidResources.keySet(), KnownFilesSaveData.InputSet.ANDROID_RESOURCE);
saveData.setInputSet(updatedJniResources.keySet(), KnownFilesSaveData.InputSet.NATIVE_RESOURCE);
saveData.saveCurrentData();
File file;
String outputFileName = outputFile.getName();
file = getAwbPackageOutputFile(appVariantOutputContext.getVariantContext(), outputFileName);
FileUtils.copyFileToDirectory(outputFile, file.getParentFile());
return new File(file.getParentFile(), outputFileName);
}
Aggregations