From 2968cbf4aa67e952d79dd57e39806dbe92a0148e Mon Sep 17 00:00:00 2001 From: Pierre Lecesne Date: Thu, 2 Feb 2017 22:38:40 +0000 Subject: [PATCH] Strip the resources from the APK using the TableSplitter. Test: Unit tests pass. Change-Id: I1dd71581113fb9a6feeefa9c794cc282529c3754 --- tools/aapt2/strip/Strip.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/aapt2/strip/Strip.cpp b/tools/aapt2/strip/Strip.cpp index ac3f244b090f9..c34cfbf3580e3 100644 --- a/tools/aapt2/strip/Strip.cpp +++ b/tools/aapt2/strip/Strip.cpp @@ -22,6 +22,7 @@ #include "Diagnostics.h" #include "Flags.h" #include "LoadedApk.h" +#include "split/TableSplitter.h" using android::StringPiece; @@ -78,7 +79,21 @@ class StripCommand { context_->GetDiagnostics()->Note(DiagMessage() << "Stripping APK..."); } - // TODO(lecesne): Implement stripping here. + // TODO(lecesne): Add support for more than one density. + if (options_.target_configs.size() > 1) { + context_->GetDiagnostics()->Error(DiagMessage() + << "Multiple densities not supported at the moment"); + return 1; + } + + // Stripping the APK using the TableSplitter with no splits and the target + // density as the preferred density. The resource table is modified in + // place in the LoadedApk. + TableSplitterOptions splitter_options; + splitter_options.preferred_density = options_.target_configs[0].density; + std::vector splits; + TableSplitter splitter(splits, splitter_options); + splitter.SplitTable(apk->GetResourceTable()); std::unique_ptr writer = CreateZipFileArchiveWriter(context_->GetDiagnostics(), options_.output_path);