From c76940363197de1772b761aa38e819b55fb80cb7 Mon Sep 17 00:00:00 2001 From: Mohamed Heikal Date: Wed, 7 Nov 2018 16:49:02 -0500 Subject: Resource Path Obfuscation This CL allows aapt2 to obfuscate resource paths within the output apk and move resources to shorter obfuscated paths. This reduces apk size when there is a large number of resources since the path metadata exists in 4 places in the apk. This CL adds two arguments to aapt2, one to enable resource path obfuscation and one to point to a path to output the path map to (for later debugging). Test: make aapt2_tests Bug: b/75965637 Change-Id: I9cacafe1d17800d673566b2d61b0b88f3fb8d60c --- tools/aapt2/LoadedApk.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/aapt2/LoadedApk.cpp') diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp index b353ff00a23f..45719ef474cd 100644 --- a/tools/aapt2/LoadedApk.cpp +++ b/tools/aapt2/LoadedApk.cpp @@ -223,8 +223,17 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table io::IFile* file = iterator->Next(); std::string path = file->GetSource().path; + std::string output_path = path; + bool is_resource = path.find("res/") == 0; + if (is_resource) { + auto it = options.shortened_path_map.find(path); + if (it != options.shortened_path_map.end()) { + output_path = it->second; + } + } + // Skip resources that are not referenced if requested. - if (path.find("res/") == 0 && referenced_resources.find(path) == referenced_resources.end()) { + if (is_resource && referenced_resources.find(output_path) == referenced_resources.end()) { if (context->IsVerbose()) { context->GetDiagnostics()->Note(DiagMessage() << "Removing resource '" << path << "' from APK."); @@ -283,7 +292,8 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table return false; } } else { - if (!io::CopyFileToArchivePreserveCompression(context, file, path, writer)) { + if (!io::CopyFileToArchivePreserveCompression( + context, file, output_path, writer)) { return false; } } -- cgit v1.2.3-59-g8ed1b