AAPT2: Remove resources that define locales but no default values.

According to our docs:
https://developer.android.com/guide/topics/resources/localization.html#defaults-r-important

Some resources *require* that there is a default definition. So far,
the pain is felt when doing translations for strings that have been
renamed, etc.

This CL strips out resources that don't have a default value and define
a resource for a locale. This is conservative, but should be expanded
to other configuration properties moving forward.

Bug: 36572857
Test: make aapt2_tests
Change-Id: Ife94a1f8a2ee221f8532ffa856541a9c8c4e7143
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index 12ab883..0839f6f 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -55,6 +55,7 @@
 #include "java/ProguardRules.h"
 #include "link/Linkers.h"
 #include "link/ManifestFixer.h"
+#include "link/NoDefaultResourceRemover.h"
 #include "link/ReferenceLinker.h"
 #include "link/TableMerger.h"
 #include "link/XmlCompatVersioner.h"
@@ -1785,6 +1786,14 @@
           util::make_unique<FeatureSplitSymbolTableDelegate>(context_));
     }
 
+    // Before we process anything, remove the resources whose default values don't exist.
+    // We want to force any references to these to fail the build.
+    if (!NoDefaultResourceRemover{}.Consume(context_, &final_table_)) {
+      context_->GetDiagnostics()->Error(DiagMessage()
+                                        << "failed removing resources with no defaults");
+      return 1;
+    }
+
     ReferenceLinker linker;
     if (!linker.Consume(context_, &final_table_)) {
       context_->GetDiagnostics()->Error(DiagMessage() << "failed linking references");