AAPT2: Include package name of attributes in styleable from another package
Change-Id: I44f902e297238e7ee4ae27c02aaaf9e148652d2a
diff --git a/tools/aapt2/JavaClassGenerator.cpp b/tools/aapt2/JavaClassGenerator.cpp
index 3f92f18..2bb0e65 100644
--- a/tools/aapt2/JavaClassGenerator.cpp
+++ b/tools/aapt2/JavaClassGenerator.cpp
@@ -94,12 +94,12 @@
std::u16string* entryName = static_cast<GenArgs&>(a).entryName;
// This must be sorted by resource ID.
- std::vector<std::pair<ResourceId, StringPiece16>> sortedAttributes;
+ std::vector<std::pair<ResourceId, ResourceNameRef>> sortedAttributes;
sortedAttributes.reserve(styleable.entries.size());
for (const auto& attr : styleable.entries) {
assert(attr.id.isValid() && "no ID set for Styleable entry");
assert(attr.name.isValid() && "no name set for Styleable entry");
- sortedAttributes.emplace_back(attr.id, attr.name.entry);
+ sortedAttributes.emplace_back(attr.id, attr.name);
}
std::sort(sortedAttributes.begin(), sortedAttributes.end());
@@ -124,8 +124,15 @@
for (size_t i = 0; i < attrCount; i++) {
*out << " "
<< "public static" << finalModifier
- << " int " << transform(*entryName) << "_" << transform(sortedAttributes[i].second)
- << " = " << i << ";" << std::endl;
+ << " int " << transform(*entryName);
+
+ // We may reference IDs from other packages, so prefix the entry name with
+ // the package.
+ const ResourceNameRef& itemName = sortedAttributes[i].second;
+ if (itemName.package != mTable->getPackage()) {
+ *out << "_" << transform(itemName.package);
+ }
+ *out << "_" << transform(itemName.entry) << " = " << i << ";" << std::endl;
}
}