diff options
author | corysmith <corysmith@google.com> | 2018-02-16 13:14:29 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-16 13:18:21 -0800 |
commit | f672a31b8b19baab95373e4f2f6d110aa8b8f0fb (patch) | |
tree | 58cef0309a67e62e3fe0ef024916d9d5c53bae8c /src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java | |
parent | 950bcf79c47484832bb4c84fbb23f6b56800e0b3 (diff) |
Normalized the serialization proto to save space and allow greater versatility in storage.
RELNOTES: None
PiperOrigin-RevId: 186036607
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java | 153 |
1 files changed, 76 insertions, 77 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java index 83b628cd9e..4ef23e76e2 100644 --- a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java @@ -125,83 +125,82 @@ public class Aapt2ResourcePackagingAction { profiler.recordEndOf("merging"); - - profiler.startTask("compile"); - final ResourceCompiler compiler = - ResourceCompiler.create( - executorService, - compiledResources, - aaptConfigOptions.aapt2, - aaptConfigOptions.buildToolsVersion); - - CompiledResources compiled = - options - .primaryData - .processDataBindings( - options.dataBindingInfoOut, options.packageForR, databindingResourcesRoot) - .compile(compiler, compiledResources) - .processManifest( - manifest -> - AndroidManifestProcessor.with(STD_LOGGER) - .processManifest( - options.applicationId, - options.versionCode, - options.versionName, - manifest, - processedManifest)) - .processManifest( - manifest -> - new DensitySpecificManifestProcessor(densities, densityManifest) - .process(manifest)); - profiler.recordEndOf("compile").startTask("link"); - // Write manifestOutput now before the dummy manifest is created. - if (options.manifestOutput != null) { - AndroidResourceOutputs.copyManifestToOutput(compiled, options.manifestOutput); - } - - List<CompiledResources> compiledResourceDeps = - // Last defined dependencies will overwrite previous one, so always place direct - // after transitive. - concat(options.transitiveData.stream(), options.directData.stream()) - .map(DependencyAndroidData::getCompiledSymbols) - .collect(toList()); - - List<Path> assetDirs = - concat(options.transitiveData.stream(), options.directData.stream()) - .flatMap(dep -> dep.assetDirs.stream()) - .collect(toList()); - assetDirs.addAll(options.primaryData.assetDirs); - - final PackagedResources packagedResources = - ResourceLinker.create(aaptConfigOptions.aapt2, linkedOut) - .profileUsing(profiler) - .customPackage(options.packageForR) - .outputAsProto(aaptConfigOptions.resourceTableAsProto) - .dependencies(ImmutableList.of(StaticLibrary.from(aaptConfigOptions.androidJar))) - .include(compiledResourceDeps) - .withAssets(assetDirs) - .buildVersion(aaptConfigOptions.buildToolsVersion) - .conditionalKeepRules(aaptConfigOptions.conditionalKeepRules == TriState.YES) - .filterToDensity(densities) - .includeOnlyConfigs(aaptConfigOptions.resourceConfigs) - .link(compiled) - .copyPackageTo(options.packagePath) - .copyProguardTo(options.proguardOutput) - .copyMainDexProguardTo(options.mainDexProguardOutput) - .createSourceJar(options.srcJarOutput) - .copyRTxtTo(options.rOutput); - profiler.recordEndOf("link"); - if (options.resourcesOutput != null) { - profiler.startTask("package"); - // The compiled resources and the merged resources should be the same. - // TODO(corysmith): Decompile or otherwise provide the exact resources in the apk. - ResourcesZip.fromApk( - mergedAndroidData.getResourceDir(), - packagedResources.getApk(), - packagedResources.getResourceIds()) - .writeTo(options.resourcesOutput, false /* compress */); - profiler.recordEndOf("package"); - } + profiler.startTask("compile"); + final ResourceCompiler compiler = + ResourceCompiler.create( + executorService, + compiledResources, + aaptConfigOptions.aapt2, + aaptConfigOptions.buildToolsVersion); + + CompiledResources compiled = + options + .primaryData + .processDataBindings( + options.dataBindingInfoOut, options.packageForR, databindingResourcesRoot) + .compile(compiler, compiledResources) + .processManifest( + manifest -> + AndroidManifestProcessor.with(STD_LOGGER) + .processManifest( + options.applicationId, + options.versionCode, + options.versionName, + manifest, + processedManifest)) + .processManifest( + manifest -> + new DensitySpecificManifestProcessor(densities, densityManifest) + .process(manifest)); + profiler.recordEndOf("compile").startTask("link"); + // Write manifestOutput now before the dummy manifest is created. + if (options.manifestOutput != null) { + AndroidResourceOutputs.copyManifestToOutput(compiled, options.manifestOutput); + } + + List<CompiledResources> compiledResourceDeps = + // Last defined dependencies will overwrite previous one, so always place direct + // after transitive. + concat(options.transitiveData.stream(), options.directData.stream()) + .map(DependencyAndroidData::getCompiledSymbols) + .collect(toList()); + + List<Path> assetDirs = + concat(options.transitiveData.stream(), options.directData.stream()) + .flatMap(dep -> dep.assetDirs.stream()) + .collect(toList()); + assetDirs.addAll(options.primaryData.assetDirs); + + final PackagedResources packagedResources = + ResourceLinker.create(aaptConfigOptions.aapt2, linkedOut) + .profileUsing(profiler) + .customPackage(options.packageForR) + .outputAsProto(aaptConfigOptions.resourceTableAsProto) + .dependencies(ImmutableList.of(StaticLibrary.from(aaptConfigOptions.androidJar))) + .include(compiledResourceDeps) + .withAssets(assetDirs) + .buildVersion(aaptConfigOptions.buildToolsVersion) + .conditionalKeepRules(aaptConfigOptions.conditionalKeepRules == TriState.YES) + .filterToDensity(densities) + .includeOnlyConfigs(aaptConfigOptions.resourceConfigs) + .link(compiled) + .copyPackageTo(options.packagePath) + .copyProguardTo(options.proguardOutput) + .copyMainDexProguardTo(options.mainDexProguardOutput) + .createSourceJar(options.srcJarOutput) + .copyRTxtTo(options.rOutput); + profiler.recordEndOf("link"); + if (options.resourcesOutput != null) { + profiler.startTask("package"); + // The compiled resources and the merged resources should be the same. + // TODO(corysmith): Decompile or otherwise provide the exact resources in the apk. + ResourcesZip.fromApk( + mergedAndroidData.getResourceDir(), + packagedResources.getApk(), + packagedResources.getResourceIds()) + .writeTo(options.resourcesOutput, false /* compress */); + profiler.recordEndOf("package"); } } } +} |