Search in sources :

Example 1 with Zip64NotSupportedException

use of com.android.apkzlib.zip.compress.Zip64NotSupportedException 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;
}
Also used : FileStatus(com.android.ide.common.res2.FileStatus) RelativeFile(com.android.builder.files.RelativeFile) AndroidBuilder(com.android.builder.core.AndroidBuilder) IncrementalPackagerBuilder(com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder) KnownFilesSaveData(com.android.build.gradle.internal.tasks.KnownFilesSaveData) ZipEntry(java.util.zip.ZipEntry) BuildOutput(com.android.build.gradle.internal.scope.BuildOutput) FileCacheByPath(com.android.builder.files.FileCacheByPath) Zip64NotSupportedException(com.android.apkzlib.zip.compress.Zip64NotSupportedException) ZipFile(java.util.zip.ZipFile) RelativeFile(com.android.builder.files.RelativeFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Zip64NotSupportedException (com.android.apkzlib.zip.compress.Zip64NotSupportedException)1 IncrementalPackagerBuilder (com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder)1 BuildOutput (com.android.build.gradle.internal.scope.BuildOutput)1 KnownFilesSaveData (com.android.build.gradle.internal.tasks.KnownFilesSaveData)1 AndroidBuilder (com.android.builder.core.AndroidBuilder)1 FileCacheByPath (com.android.builder.files.FileCacheByPath)1 RelativeFile (com.android.builder.files.RelativeFile)1 FileStatus (com.android.ide.common.res2.FileStatus)1 File (java.io.File)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1