From b853e930228e4e8039c8df2bfac1e55de00230b0 Mon Sep 17 00:00:00 2001 From: corysmith Date: Mon, 6 Aug 2018 10:49:47 -0700 Subject: Added functionality to let the ResourceLinker link ProtoApks. RELNOTES: None PiperOrigin-RevId: 207570745 --- .../build/android/aapt2/ResourceLinker.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/tools/android/java/com/google/devtools/build/android/aapt2') diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java index 5d8ecfb4f2..8930883dd8 100644 --- a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java +++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java @@ -532,6 +532,34 @@ public class ResourceLinker { } } + /** Link a proto apk to produce an apk. */ + public Path link(ProtoApk protoApk) { + try { + final Path protoApkPath = protoApk.asApkPath(); + final Path working = + workingDirectory + .resolve("link-proto") + .resolve(replaceExtension(protoApkPath.getFileName().toString(), "working")); + final Path manifest = protoApk.writeManifestAsXmlTo(working); + final Path apk = working.resolve("binary.apk"); + logger.fine( + new AaptCommandBuilder(aapt2) + .forBuildToolsVersion(buildToolsVersion) + .forVariantType(VariantType.DEFAULT) + .add("link") + .when(Objects.equals(logger.getLevel(), Level.FINE)) + .thenAdd("-v") + .add("--manifest", manifest) + .addRepeated("-I", StaticLibrary.toPathStrings(linkAgainst)) + .add("-R", convertToBinary(protoApkPath)) + .add("-o", apk.toString()) + .execute(String.format("Re-linking %s", protoApkPath))); + return apk; + } catch (IOException e) { + throw new LinkError(e); + } + } + public ResourceLinker storeUncompressed(List uncompressedExtensions) { this.uncompressedExtensions = uncompressedExtensions; return this; -- cgit v1.2.3