Search in sources :

Example 1 with IncrementalPackager

use of com.android.builder.internal.packaging.IncrementalPackager 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);
        }
    });
}
Also used : FileStatus(com.android.ide.common.res2.FileStatus) BuildOutput(com.android.build.gradle.internal.scope.BuildOutput) IOExceptionWrapper(com.android.apkzlib.utils.IOExceptionWrapper) RelativeFile(com.android.builder.files.RelativeFile) IncrementalPackager(com.android.builder.internal.packaging.IncrementalPackager) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) RelativeFile(com.android.builder.files.RelativeFile) File(java.io.File) ImmutableMap(com.google.common.collect.ImmutableMap) IncrementalPackagerBuilder(com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder)

Aggregations

IOExceptionWrapper (com.android.apkzlib.utils.IOExceptionWrapper)1 IncrementalPackagerBuilder (com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder)1 BuildOutput (com.android.build.gradle.internal.scope.BuildOutput)1 RelativeFile (com.android.builder.files.RelativeFile)1 IncrementalPackager (com.android.builder.internal.packaging.IncrementalPackager)1 FileStatus (com.android.ide.common.res2.FileStatus)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1