AAPT2: Implement density stripping and initial Split support
When a preferred density is supplied, the closest matching densities
will be selected, the rest stripped from the APK.
Split support will be enabled in a later CL. Command line support is still
needed, but the foundation is ready.
Bug:25958912
Change-Id: I56d599806b4ec4ffa24e17aad48d47130ca05c08
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index 4bea129..19bd521 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -30,7 +30,8 @@
namespace aapt {
-struct PrintVisitor : public ValueVisitor {
+class PrintVisitor : public ValueVisitor {
+public:
using ValueVisitor::visit;
void visit(Attribute* attr) override {
@@ -69,7 +70,11 @@
for (const auto& entry : style->entries) {
std::cout << "\n ";
if (entry.key.name) {
- std::cout << entry.key.name.value().package << ":" << entry.key.name.value().entry;
+ const ResourceName& name = entry.key.name.value();
+ if (!name.package.empty()) {
+ std::cout << name.package << ":";
+ }
+ std::cout << name.entry;
}
if (entry.key.id) {
@@ -89,7 +94,21 @@
}
void visit(Styleable* styleable) override {
- styleable->print(&std::cout);
+ std::cout << "(styleable)";
+ for (const auto& attr : styleable->entries) {
+ std::cout << "\n ";
+ if (attr.name) {
+ const ResourceName& name = attr.name.value();
+ if (!name.package.empty()) {
+ std::cout << name.package << ":";
+ }
+ std::cout << name.entry;
+ }
+
+ if (attr.id) {
+ std::cout << "(" << attr.id.value() << ")";
+ }
+ }
}
void visitItem(Item* item) override {
@@ -97,7 +116,9 @@
}
};
-void Debug::printTable(ResourceTable* table) {
+void Debug::printTable(ResourceTable* table, const DebugPrintTableOptions& options) {
+ PrintVisitor visitor;
+
for (auto& package : table->packages) {
std::cout << "Package name=" << package->name;
if (package->id) {
@@ -106,7 +127,7 @@
std::cout << std::endl;
for (const auto& type : package->types) {
- std::cout << " type " << type->type;
+ std::cout << "\n type " << type->type;
if (type->id) {
std::cout << " id=" << std::hex << (int) type->id.value() << std::dec;
}
@@ -142,10 +163,12 @@
std::cout << std::endl;
- PrintVisitor visitor;
for (const auto& value : entry->values) {
std::cout << " (" << value->config << ") ";
value->value->accept(&visitor);
+ if (options.showSources && !value->value->getSource().path.empty()) {
+ std::cout << " src=" << value->value->getSource();
+ }
std::cout << std::endl;
}
}