diff options
Diffstat (limited to 'tools/aapt2/JavaClassGenerator.cpp')
-rw-r--r-- | tools/aapt2/JavaClassGenerator.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/aapt2/JavaClassGenerator.cpp b/tools/aapt2/JavaClassGenerator.cpp index 2bb0e65..e2ffe79 100644 --- a/tools/aapt2/JavaClassGenerator.cpp +++ b/tools/aapt2/JavaClassGenerator.cpp @@ -81,23 +81,28 @@ static std::u16string transform(const StringPiece16& symbol) { } struct GenArgs : ValueVisitorArgs { - GenArgs(std::ostream* o, std::u16string* e) : out(o), entryName(e) { + GenArgs(std::ostream* o, const std::u16string* p, std::u16string* e) : + out(o), package(p), entryName(e) { } std::ostream* out; + const std::u16string* package; std::u16string* entryName; }; void JavaClassGenerator::visit(const Styleable& styleable, ValueVisitorArgs& a) { const StringPiece finalModifier = mOptions.useFinal ? " final" : ""; std::ostream* out = static_cast<GenArgs&>(a).out; + const std::u16string* package = static_cast<GenArgs&>(a).package; std::u16string* entryName = static_cast<GenArgs&>(a).entryName; // This must be sorted by resource ID. 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"); + // If we are not encoding final attributes, the styleable entry may have no ID + // if we are building a static library. + assert((!mOptions.useFinal || 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); } @@ -129,7 +134,7 @@ void JavaClassGenerator::visit(const Styleable& styleable, ValueVisitorArgs& a) // 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()) { + if (itemName.package != *package) { *out << "_" << transform(itemName.package); } *out << "_" << transform(itemName.entry) << " = " << i << ";" << std::endl; @@ -172,7 +177,7 @@ bool JavaClassGenerator::generateType(const std::u16string& package, size_t pack if (type.type == ResourceType::kStyleable) { assert(!entry->values.empty()); - entry->values.front().value->accept(*this, GenArgs{ &out, &unmangledName }); + entry->values.front().value->accept(*this, GenArgs{ &out, &package, &unmangledName }); } else { out << " " << "public static" << finalModifier << " int " << transform(unmangledName) << " = " << id << ";" << std::endl; |