use of com.android.apkzlib.utils.IOExceptionWrapper in project atlas by alibaba.
the class AwbApkPackageTask method doTask.
private void doTask(@NonNull ApkData apkData, @NonNull File incrementalDirForSplit, @NonNull File outputFile, @NonNull FileCacheByPath cacheByPath, @NonNull Collection<BuildOutput> manifestOutputs, @NonNull ImmutableMap<RelativeFile, FileStatus> changedDex, @NonNull ImmutableMap<RelativeFile, FileStatus> changedJavaResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAssets, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAndroidResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedNLibs) throws IOException {
ImmutableMap.Builder<RelativeFile, FileStatus> javaResourcesForApk = ImmutableMap.builder();
javaResourcesForApk.putAll(changedJavaResources);
if (dexPackagingPolicy == DexPackagingPolicy.INSTANT_RUN_MULTI_APK) {
changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(dexFolders.getFiles()), RelativeFile::getBase)));
}
final ImmutableMap<RelativeFile, FileStatus> dexFilesToPackage = changedDex;
String abiFilter = apkData.getFilter(com.android.build.OutputFile.FilterType.ABI);
// find the manifest file for this split.
BuildOutput manifestForSplit = OutputScope.getOutput(manifestOutputs, TaskOutputHolder.TaskOutputType.MERGED_MANIFESTS, apkData);
FileUtils.mkdirs(outputFile.getParentFile());
try (IncrementalPackager packager = new IncrementalPackagerBuilder().withOutputFile(outputFile).withSigning(null).withCreatedBy(androidBuilder.getCreatedBy()).withMinSdk(miniSdkVersion).withNativeLibraryPackagingMode(PackagingUtils.getNativeLibrariesLibrariesPackagingMode(manifestForSplit == null ? awbManifestFolder.getSingleFile() : manifestForSplit.getOutputFile())).withNoCompressPredicate(PackagingUtils.getNoCompressPredicate(aaptOptionsNoCompress, manifestForSplit == null ? awbManifestFolder.getSingleFile() : manifestForSplit.getOutputFile())).withIntermediateDir(incrementalDirForSplit).withProject(appVariantOutputContext.getScope().getGlobalScope().getProject()).withDebuggableBuild(debug).withAcceptedAbis(abiFilter == null ? supportAbis : ImmutableSet.of(abiFilter)).withJniDebuggableBuild(jniDebug).build()) {
packager.updateDex(dexFilesToPackage);
packager.updateJavaResources(changedJavaResources);
packager.updateAssets(changedAssets);
packager.updateAndroidResources(changedAndroidResources);
packager.updateNativeLibraries(changedNLibs);
// Only report APK as built if it has actually changed.
if (packager.hasPendingChangesWithWait()) {
// FIX-ME : below would not work in multi apk situations. There is code somewhere
// to ensure we only build ONE multi APK for the target device, make sure it is still
// active.
instantRunContext.addChangedFile(FileType.MAIN, outputFile);
}
}
/*
* Save all used zips in the cache.
*/
Stream.concat(dexFilesToPackage.keySet().stream(), Stream.concat(changedJavaResources.keySet().stream(), Stream.concat(changedAndroidResources.keySet().stream(), changedNLibs.keySet().stream()))).map(RelativeFile::getBase).filter(File::isFile).distinct().forEach((File f) -> {
try {
cacheByPath.add(f);
} catch (IOException e) {
throw new IOExceptionWrapper(e);
}
});
}
Aggregations