summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIzabela Orlowska <imorlowska@google.com>2018-07-24 11:54:32 +0100
committerIzabela Orlowska <imorlowska@google.com>2018-07-25 09:50:15 +0000
commitf67d486e58f93a1d45795cee04633fce5e5e2bc7 (patch)
treee2d40be90b2a0f3890ae07b06ea51b356ee55636
parenta6f3ba1dc578c14e3ccbf61676ab7d3b54c69f1c (diff)
AAPT2: partial files contain only local resources
When writing a partial R file for the compiled file, only include resources defined locally - meaning those without a package. Do not write resources from other packages (e.g. "android"). Test: manual Bug: 73927419 Change-Id: I84241352e643ca1f22a581e6847372e2a4278824
-rw-r--r--tools/aapt2/cmd/Compile.cpp74
1 files changed, 39 insertions, 35 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 8c1fa9ac0226..89b3e0d52748 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -288,44 +288,48 @@ static bool CompileTable(IAaptContext* context, const CompileOptions& options,
Printer r_txt_printer(&fout_text);
for (const auto& package : table.packages) {
- for (const auto& type : package->types) {
- for (const auto& entry : type->entries) {
- // Check access modifiers.
- switch(entry->visibility.level) {
- case Visibility::Level::kUndefined :
- r_txt_printer.Print("default ");
- break;
- case Visibility::Level::kPublic :
- r_txt_printer.Print("public ");
- break;
- case Visibility::Level::kPrivate :
- r_txt_printer.Print("private ");
- }
+ // Only print resources defined locally, e.g. don't write android attributes.
+ if (package->name.empty()) {
+ for (const auto& type : package->types) {
+ for (const auto& entry : type->entries) {
+ // Check access modifiers.
+ switch (entry->visibility.level) {
+ case Visibility::Level::kUndefined :
+ r_txt_printer.Print("default ");
+ break;
+ case Visibility::Level::kPublic :
+ r_txt_printer.Print("public ");
+ break;
+ case Visibility::Level::kPrivate :
+ r_txt_printer.Print("private ");
+ }
- if (type->type != ResourceType::kStyleable) {
- r_txt_printer.Print("int ");
- r_txt_printer.Print(to_string(type->type));
- r_txt_printer.Print(" ");
- r_txt_printer.Println(entry->name);
- } else {
- r_txt_printer.Print("int[] styleable ");
- r_txt_printer.Println(entry->name);
-
- if (!entry->values.empty()) {
- auto styleable = static_cast<const Styleable*>(entry->values.front()->value.get());
- for (const auto& attr : styleable->entries) {
- // The visibility of the children under the styleable does not matter as they are
- // nested under their parent and use its visibility.
- r_txt_printer.Print("default int styleable ");
- r_txt_printer.Print(entry->name);
- // If the package name is present, also include it in the mangled name (e.g.
- // "android")
- if (!attr.name.value().package.empty()) {
+ if (type->type != ResourceType::kStyleable) {
+ r_txt_printer.Print("int ");
+ r_txt_printer.Print(to_string(type->type));
+ r_txt_printer.Print(" ");
+ r_txt_printer.Println(entry->name);
+ } else {
+ r_txt_printer.Print("int[] styleable ");
+ r_txt_printer.Println(entry->name);
+
+ if (!entry->values.empty()) {
+ auto styleable =
+ static_cast<const Styleable*>(entry->values.front()->value.get());
+ for (const auto& attr : styleable->entries) {
+ // The visibility of the children under the styleable does not matter as they are
+ // nested under their parent and use its visibility.
+ r_txt_printer.Print("default int styleable ");
+ r_txt_printer.Print(entry->name);
+ // If the package name is present, also include it in the mangled name (e.g.
+ // "android")
+ if (!attr.name.value().package.empty()) {
+ r_txt_printer.Print("_");
+ r_txt_printer.Print(MakePackageSafeName(attr.name.value().package));
+ }
r_txt_printer.Print("_");
- r_txt_printer.Print(MakePackageSafeName(attr.name.value().package));
+ r_txt_printer.Println(attr.name.value().entry);
}
- r_txt_printer.Print("_");
- r_txt_printer.Println(attr.name.value().entry);
}
}
}