diff options
author | ajmichael <ajmichael@google.com> | 2018-04-02 09:26:42 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-02 09:27:48 -0700 |
commit | cb16c5089953127690c8971d32dc3d4cf01b7620 (patch) | |
tree | 9769c8f778ef4eed4f3e241f60d4c929b985dcd0 /src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java | |
parent | 1592238818ce4235e689f7a77dd4fefc1a7dfc8a (diff) |
Create proguard.txt in android_library AAR output.
The proguard.txt is the concatenation of the proguard_specs on the android_library rule itself. Note that it does not include transitively defined proguard_specs.
Fixes https://github.com/bazelbuild/bazel/issues/4467
RELNOTES: android_library AAR output now contains proguard.txt
PiperOrigin-RevId: 191302610
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java b/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java index 88618ed835..d5bd4944d5 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AarGeneratorAction.java @@ -13,6 +13,8 @@ // limitations under the License. package com.google.devtools.build.android; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.android.builder.core.VariantType; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; @@ -125,6 +127,18 @@ public class AarGeneratorAction { public Path classes; @Option( + name = "proguardSpec", + defaultValue = "", + converter = ExistingPathConverter.class, + allowMultiple = true, + category = "input", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Path to proguard spec file." + ) + public List<Path> proguardSpecs; + + @Option( name = "aarOutput", defaultValue = "null", converter = PathConverter.class, @@ -179,7 +193,13 @@ public class AarGeneratorAction { options.throwOnResourceConflict); logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); - writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes); + writeAar( + options.aarOutput, + mergedData, + options.manifest, + options.rtxt, + options.classes, + options.proguardSpecs); logger.fine( String.format("Packaging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); } catch (MergeConflictException e) { @@ -214,7 +234,12 @@ public class AarGeneratorAction { @VisibleForTesting static void writeAar( - Path aar, final MergedAndroidData data, Path manifest, Path rtxt, Path classes) + Path aar, + final MergedAndroidData data, + Path manifest, + Path rtxt, + Path classes, + List<Path> proguardSpecs) throws IOException { try (final ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(aar)))) { @@ -240,6 +265,17 @@ public class AarGeneratorAction { zipOut.write(Files.readAllBytes(rtxt)); zipOut.closeEntry(); + if (!proguardSpecs.isEmpty()) { + ZipEntry proguardTxt = new ZipEntry("proguard.txt"); + proguardTxt.setTime(DEFAULT_TIMESTAMP); + zipOut.putNextEntry(proguardTxt); + for (Path proguardSpec : proguardSpecs) { + zipOut.write(Files.readAllBytes(proguardSpec)); + zipOut.write("\r\n".getBytes(UTF_8)); + } + zipOut.closeEntry(); + } + if (Files.exists(data.getAssetDir()) && data.getAssetDir().toFile().list().length > 0) { ZipDirectoryWriter assetWriter = new ZipDirectoryWriter(zipOut, data.getAssetDir(), "assets"); |