Replace Maybe with std::optional

With c++17, std::optional provides the functionality that Maybe
provided.

Bug: 183215655
Test: aapt2_tests
Change-Id: I62bb9c2fa4985dc5217a6ed153df92b85ad9a034
diff --git a/tools/aapt2/AppInfo.h b/tools/aapt2/AppInfo.h
index d3ca357..cabbe7e 100644
--- a/tools/aapt2/AppInfo.h
+++ b/tools/aapt2/AppInfo.h
@@ -17,11 +17,10 @@
 #ifndef AAPT_APP_INFO_H
 #define AAPT_APP_INFO_H
 
+#include <optional>
 #include <set>
 #include <string>
 
-#include "util/Maybe.h"
-
 namespace aapt {
 
 // Information relevant to building an app, parsed from the app's AndroidManifest.xml.
@@ -30,19 +29,19 @@
   std::string package;
 
   // The app's minimum SDK version, if it is defined.
-  Maybe<int> min_sdk_version;
+  std::optional<int> min_sdk_version;
 
   // The app's version code (the lower 32 bits of the long version code), if it is defined.
-  Maybe<uint32_t> version_code;
+  std::optional<uint32_t> version_code;
 
   // The app's version code major (the upper 32 bits of the long version code), if it is defined.
-  Maybe<uint32_t> version_code_major;
+  std::optional<uint32_t> version_code_major;
 
   // The app's revision code, if it is defined.
-  Maybe<uint32_t> revision_code;
+  std::optional<uint32_t> revision_code;
 
   // The app's split name, if it is a split.
-  Maybe<std::string> split_name;
+  std::optional<std::string> split_name;
 
   // The split names that this split depends on.
   std::set<std::string> split_name_dependencies;
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index ef3a62f..df444ba 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -280,8 +280,7 @@
       printer->Indent();
       for (const ResourceTableEntryView& entry : type.entries) {
         printer->Print("resource ");
-        printer->Print(ResourceId(package.id.value_or_default(0), type.id.value_or_default(0),
-                                  entry.id.value_or_default(0))
+        printer->Print(ResourceId(package.id.value_or(0), type.id.value_or(0), entry.id.value_or(0))
                            .to_string());
         printer->Print(" ");
 
@@ -362,7 +361,7 @@
       continue;
     }
 
-    Maybe<ResourceTable::SearchResult> result = table->FindResource(style_name);
+    std::optional<ResourceTable::SearchResult> result = table->FindResource(style_name);
     if (result) {
       ResourceEntry* entry = result.value().entry;
       for (const auto& value : entry->values) {
@@ -482,8 +481,7 @@
 
       if (attr.compiled_attribute) {
         printer_->Print("(");
-        printer_->Print(
-            attr.compiled_attribute.value().id.value_or_default(ResourceId(0)).to_string());
+        printer_->Print(attr.compiled_attribute.value().id.value_or(ResourceId(0)).to_string());
         printer_->Print(")");
       }
       printer_->Print("=");
diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp
index 8a43bb4..b249c6c 100644
--- a/tools/aapt2/Main.cpp
+++ b/tools/aapt2/Main.cpp
@@ -147,7 +147,7 @@
  private:
   io::FileOutputStream* out_;
   IDiagnostics* diagnostics_;
-  Maybe<std::string> trace_folder_;
+  std::optional<std::string> trace_folder_;
 };
 
 }  // namespace aapt
diff --git a/tools/aapt2/NameMangler.h b/tools/aapt2/NameMangler.h
index f1aad29..0b49052 100644
--- a/tools/aapt2/NameMangler.h
+++ b/tools/aapt2/NameMangler.h
@@ -21,7 +21,6 @@
 #include <string>
 
 #include "Resource.h"
-#include "util/Maybe.h"
 
 namespace aapt {
 
@@ -44,7 +43,7 @@
  public:
   explicit NameMangler(NameManglerPolicy policy) : policy_(policy) {}
 
-  Maybe<ResourceName> MangleName(const ResourceName& name) {
+  std::optional<ResourceName> MangleName(const ResourceName& name) {
     if (policy_.target_package_name == name.package ||
         policy_.packages_to_mangle.count(name.package) == 0) {
       return {};
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index f1e2da9..f49c254 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -20,7 +20,8 @@
 #include <limits>
 #include <sstream>
 
-#include "android-base/logging.h"
+#include <android-base/logging.h>
+#include <idmap2/Policies.h>
 
 #include "ResourceTable.h"
 #include "ResourceUtils.h"
@@ -28,12 +29,10 @@
 #include "ValueVisitor.h"
 #include "text/Utf8Iterator.h"
 #include "util/ImmutableMap.h"
-#include "util/Maybe.h"
+
 #include "util/Util.h"
 #include "xml/XmlPullParser.h"
 
-#include "idmap2/Policies.h"
-
 using ::aapt::ResourceUtils::StringBuilder;
 using ::aapt::text::Utf8Iterator;
 using ::android::ConfigDescription;
@@ -109,8 +108,8 @@
   Visibility::Level visibility_level = Visibility::Level::kUndefined;
   bool staged_api = false;
   bool allow_new = false;
-  Maybe<OverlayableItem> overlayable_item;
-  Maybe<StagedId> staged_alias;
+  std::optional<OverlayableItem> overlayable_item;
+  std::optional<StagedId> staged_alias;
 
   std::string comment;
   std::unique_ptr<Value> value;
@@ -252,7 +251,7 @@
   std::string current_text;
 
   // The first occurrence of a <xliff:g> tag. Nested <xliff:g> tags are illegal.
-  Maybe<size_t> untranslatable_start_depth;
+  std::optional<size_t> untranslatable_start_depth;
 
   Node root;
   std::vector<Node*> node_stack;
@@ -342,7 +341,7 @@
         }
 
         node_stack.pop_back();
-        if (untranslatable_start_depth == make_value(depth)) {
+        if (untranslatable_start_depth == depth) {
           // This is the end of an untranslatable section.
           untranslatable_start_depth = {};
         }
@@ -468,7 +467,7 @@
     }
 
     // Extract the product name if it exists.
-    if (Maybe<StringPiece> maybe_product = xml::FindNonEmptyAttribute(parser, "product")) {
+    if (std::optional<StringPiece> maybe_product = xml::FindNonEmptyAttribute(parser, "product")) {
       parsed_resource.product = maybe_product.value().to_string();
     }
 
@@ -560,7 +559,7 @@
     resource_format = android::ResTable_map::TYPE_ANY;
 
     // Items have their type encoded in the type attribute.
-    if (Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
+    if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
       resource_type = maybe_type.value().to_string();
     } else {
       diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
@@ -568,7 +567,7 @@
       return false;
     }
 
-    if (Maybe<StringPiece> maybe_format = xml::FindNonEmptyAttribute(parser, "format")) {
+    if (std::optional<StringPiece> maybe_format = xml::FindNonEmptyAttribute(parser, "format")) {
       // An explicit format for this resource was specified. The resource will
       // retain its type in its name, but the accepted value for this type is
       // overridden.
@@ -584,7 +583,7 @@
     can_be_item = false;
 
     // Bags have their type encoded in the type attribute.
-    if (Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
+    if (std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
       resource_type = maybe_type.value().to_string();
     } else {
       diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
@@ -595,7 +594,7 @@
 
   // Get the name of the resource. This will be checked later, because not all
   // XML elements require a name.
-  Maybe<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
+  std::optional<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
 
   if (resource_type == "id") {
     if (!maybe_name) {
@@ -835,10 +834,8 @@
 bool ResourceParser::ParseString(xml::XmlPullParser* parser,
                                  ParsedResource* out_resource) {
   bool formatted = true;
-  if (Maybe<StringPiece> formatted_attr =
-          xml::FindAttribute(parser, "formatted")) {
-    Maybe<bool> maybe_formatted =
-        ResourceUtils::ParseBool(formatted_attr.value());
+  if (std::optional<StringPiece> formatted_attr = xml::FindAttribute(parser, "formatted")) {
+    std::optional<bool> maybe_formatted = ResourceUtils::ParseBool(formatted_attr.value());
     if (!maybe_formatted) {
       diag_->Error(DiagMessage(out_resource->source)
                    << "invalid value for 'formatted'. Must be a boolean");
@@ -848,8 +845,8 @@
   }
 
   bool translatable = options_.translatable;
-  if (Maybe<StringPiece> translatable_attr = xml::FindAttribute(parser, "translatable")) {
-    Maybe<bool> maybe_translatable = ResourceUtils::ParseBool(translatable_attr.value());
+  if (std::optional<StringPiece> translatable_attr = xml::FindAttribute(parser, "translatable")) {
+    std::optional<bool> maybe_translatable = ResourceUtils::ParseBool(translatable_attr.value());
     if (!maybe_translatable) {
       diag_->Error(DiagMessage(out_resource->source)
                    << "invalid value for 'translatable'. Must be a boolean");
@@ -929,7 +926,7 @@
                 << "ignoring configuration '" << out_resource->config << "' for <public> tag");
   }
 
-  Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
+  std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
   if (!maybe_type) {
     diag_->Error(DiagMessage(out_resource->source)
                  << "<public> must have a 'type' attribute");
@@ -946,8 +943,8 @@
 
   out_resource->name.type = *parsed_type;
 
-  if (Maybe<StringPiece> maybe_id_str = xml::FindNonEmptyAttribute(parser, "id")) {
-    Maybe<ResourceId> maybe_id = ResourceUtils::ParseResourceId(maybe_id_str.value());
+  if (std::optional<StringPiece> maybe_id_str = xml::FindNonEmptyAttribute(parser, "id")) {
+    std::optional<ResourceId> maybe_id = ResourceUtils::ParseResourceId(maybe_id_str.value());
     if (!maybe_id) {
       diag_->Error(DiagMessage(out_resource->source)
                    << "invalid resource ID '" << maybe_id_str.value() << "' in <public>");
@@ -974,7 +971,7 @@
                << "> tag");
   }
 
-  Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
+  std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
   if (!maybe_type) {
     diag->Error(DiagMessage(out_resource->source)
                 << "<" << tag_name << "> must have a 'type' attribute");
@@ -988,14 +985,14 @@
     return false;
   }
 
-  Maybe<StringPiece> maybe_id_str = xml::FindNonEmptyAttribute(parser, "first-id");
+  std::optional<StringPiece> maybe_id_str = xml::FindNonEmptyAttribute(parser, "first-id");
   if (!maybe_id_str) {
     diag->Error(DiagMessage(out_resource->source)
                 << "<" << tag_name << "> must have a 'first-id' attribute");
     return false;
   }
 
-  Maybe<ResourceId> maybe_id = ResourceUtils::ParseResourceId(maybe_id_str.value());
+  std::optional<ResourceId> maybe_id = ResourceUtils::ParseResourceId(maybe_id_str.value());
   if (!maybe_id) {
     diag->Error(DiagMessage(out_resource->source)
                 << "invalid resource ID '" << maybe_id_str.value() << "' in <" << tag_name << ">");
@@ -1090,7 +1087,7 @@
 
 bool ResourceParser::ParseSymbolImpl(xml::XmlPullParser* parser,
                                      ParsedResource* out_resource) {
-  Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
+  std::optional<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type");
   if (!maybe_type) {
     diag_->Error(DiagMessage(out_resource->source)
                  << "<" << parser->element_name()
@@ -1137,7 +1134,7 @@
                 << "' for <overlayable> tag");
   }
 
-  Maybe<StringPiece> overlayable_name = xml::FindNonEmptyAttribute(parser, "name");
+  std::optional<StringPiece> overlayable_name = xml::FindNonEmptyAttribute(parser, "name");
   if (!overlayable_name) {
     diag_->Error(DiagMessage(out_resource->source)
                   << "<overlayable> tag must have a 'name' attribute");
@@ -1146,7 +1143,7 @@
 
   const std::string kActorUriScheme =
       android::base::StringPrintf("%s://", Overlayable::kActorScheme);
-  Maybe<StringPiece> overlayable_actor = xml::FindNonEmptyAttribute(parser, "actor");
+  std::optional<StringPiece> overlayable_actor = xml::FindNonEmptyAttribute(parser, "actor");
   if (overlayable_actor && !util::StartsWith(overlayable_actor.value(), kActorUriScheme)) {
     diag_->Error(DiagMessage(out_resource->source)
                  << "specified <overlayable> tag 'actor' attribute must use the scheme '"
@@ -1194,7 +1191,7 @@
       }
 
       // Items specify the name and type of resource that should be overlayable
-      Maybe<StringPiece> item_name = xml::FindNonEmptyAttribute(parser, "name");
+      std::optional<StringPiece> item_name = xml::FindNonEmptyAttribute(parser, "name");
       if (!item_name) {
         diag_->Error(DiagMessage(element_source)
                      << "<item> within an <overlayable> must have a 'name' attribute");
@@ -1202,7 +1199,7 @@
         continue;
       }
 
-      Maybe<StringPiece> item_type = xml::FindNonEmptyAttribute(parser, "type");
+      std::optional<StringPiece> item_type = xml::FindNonEmptyAttribute(parser, "type");
       if (!item_type) {
         diag_->Error(DiagMessage(element_source)
                      << "<item> within an <overlayable> must have a 'type' attribute");
@@ -1236,7 +1233,8 @@
         diag_->Error(DiagMessage(element_source) << "<policy> blocks cannot be recursively nested");
         error = true;
         break;
-      } else if (Maybe<StringPiece> maybe_type = xml::FindNonEmptyAttribute(parser, "type")) {
+      } else if (std::optional<StringPiece> maybe_type =
+                     xml::FindNonEmptyAttribute(parser, "type")) {
         // Parse the polices separated by vertical bar characters to allow for specifying multiple
         // policies. Items within the policy tag will have the specified policy.
         for (const StringPiece& part : util::Tokenize(maybe_type.value(), '|')) {
@@ -1302,7 +1300,7 @@
 
   uint32_t type_mask = 0;
 
-  Maybe<StringPiece> maybe_format = xml::FindAttribute(parser, "format");
+  std::optional<StringPiece> maybe_format = xml::FindAttribute(parser, "format");
   if (maybe_format) {
     type_mask = ParseFormatAttribute(maybe_format.value());
     if (type_mask == 0) {
@@ -1312,9 +1310,9 @@
     }
   }
 
-  Maybe<int32_t> maybe_min, maybe_max;
+  std::optional<int32_t> maybe_min, maybe_max;
 
-  if (Maybe<StringPiece> maybe_min_str = xml::FindAttribute(parser, "min")) {
+  if (std::optional<StringPiece> maybe_min_str = xml::FindAttribute(parser, "min")) {
     StringPiece min_str = util::TrimWhitespace(maybe_min_str.value());
     if (!min_str.empty()) {
       std::u16string min_str16 = util::Utf8ToUtf16(min_str);
@@ -1331,7 +1329,7 @@
     }
   }
 
-  if (Maybe<StringPiece> maybe_max_str = xml::FindAttribute(parser, "max")) {
+  if (std::optional<StringPiece> maybe_max_str = xml::FindAttribute(parser, "max")) {
     StringPiece max_str = util::TrimWhitespace(maybe_max_str.value());
     if (!max_str.empty()) {
       std::u16string max_str16 = util::Utf8ToUtf16(max_str);
@@ -1398,8 +1396,7 @@
         type_mask |= android::ResTable_map::TYPE_FLAGS;
       }
 
-      if (Maybe<Attribute::Symbol> s =
-              ParseEnumOrFlagItem(parser, element_name)) {
+      if (std::optional<Attribute::Symbol> s = ParseEnumOrFlagItem(parser, element_name)) {
         Attribute::Symbol& symbol = s.value();
         ParsedResource child_resource;
         child_resource.name = symbol.symbol.name.value();
@@ -1443,24 +1440,24 @@
       type_mask ? type_mask : uint32_t{android::ResTable_map::TYPE_ANY});
   attr->SetWeak(weak);
   attr->symbols = std::vector<Attribute::Symbol>(items.begin(), items.end());
-  attr->min_int = maybe_min.value_or_default(std::numeric_limits<int32_t>::min());
-  attr->max_int = maybe_max.value_or_default(std::numeric_limits<int32_t>::max());
+  attr->min_int = maybe_min.value_or(std::numeric_limits<int32_t>::min());
+  attr->max_int = maybe_max.value_or(std::numeric_limits<int32_t>::max());
   out_resource->value = std::move(attr);
   return true;
 }
 
-Maybe<Attribute::Symbol> ResourceParser::ParseEnumOrFlagItem(
-    xml::XmlPullParser* parser, const StringPiece& tag) {
+std::optional<Attribute::Symbol> ResourceParser::ParseEnumOrFlagItem(xml::XmlPullParser* parser,
+                                                                     const StringPiece& tag) {
   const Source source = source_.WithLine(parser->line_number());
 
-  Maybe<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
+  std::optional<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
   if (!maybe_name) {
     diag_->Error(DiagMessage(source) << "no attribute 'name' found for tag <"
                                      << tag << ">");
     return {};
   }
 
-  Maybe<StringPiece> maybe_value = xml::FindNonEmptyAttribute(parser, "value");
+  std::optional<StringPiece> maybe_value = xml::FindNonEmptyAttribute(parser, "value");
   if (!maybe_value) {
     diag_->Error(DiagMessage(source) << "no attribute 'value' found for tag <"
                                      << tag << ">");
@@ -1484,13 +1481,13 @@
 bool ResourceParser::ParseStyleItem(xml::XmlPullParser* parser, Style* style) {
   const Source source = source_.WithLine(parser->line_number());
 
-  Maybe<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
+  std::optional<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
   if (!maybe_name) {
     diag_->Error(DiagMessage(source) << "<item> must have a 'name' attribute");
     return false;
   }
 
-  Maybe<Reference> maybe_key = ResourceUtils::ParseXmlAttributeName(maybe_name.value());
+  std::optional<Reference> maybe_key = ResourceUtils::ParseXmlAttributeName(maybe_name.value());
   if (!maybe_key) {
     diag_->Error(DiagMessage(source) << "invalid attribute name '" << maybe_name.value() << "'");
     return false;
@@ -1515,7 +1512,7 @@
 
   std::unique_ptr<Style> style = util::make_unique<Style>();
 
-  Maybe<StringPiece> maybe_parent = xml::FindAttribute(parser, "parent");
+  std::optional<StringPiece> maybe_parent = xml::FindAttribute(parser, "parent");
   if (maybe_parent) {
     // If the parent is empty, we don't have a parent, but we also don't infer either.
     if (!maybe_parent.value().empty()) {
@@ -1571,7 +1568,7 @@
 
 bool ResourceParser::ParseArray(xml::XmlPullParser* parser, ParsedResource* out_resource) {
   uint32_t resource_format = android::ResTable_map::TYPE_ANY;
-  if (Maybe<StringPiece> format_attr = xml::FindNonEmptyAttribute(parser, "format")) {
+  if (std::optional<StringPiece> format_attr = xml::FindNonEmptyAttribute(parser, "format")) {
     resource_format = ParseFormatTypeNoEnumsOrFlags(format_attr.value());
     if (resource_format == 0u) {
       diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
@@ -1598,8 +1595,8 @@
   std::unique_ptr<Array> array = util::make_unique<Array>();
 
   bool translatable = options_.translatable;
-  if (Maybe<StringPiece> translatable_attr = xml::FindAttribute(parser, "translatable")) {
-    Maybe<bool> maybe_translatable = ResourceUtils::ParseBool(translatable_attr.value());
+  if (std::optional<StringPiece> translatable_attr = xml::FindAttribute(parser, "translatable")) {
+    std::optional<bool> maybe_translatable = ResourceUtils::ParseBool(translatable_attr.value());
     if (!maybe_translatable) {
       diag_->Error(DiagMessage(out_resource->source)
                    << "invalid value for 'translatable'. Must be a boolean");
@@ -1664,8 +1661,7 @@
     const std::string& element_namespace = parser->element_namespace();
     const std::string& element_name = parser->element_name();
     if (element_namespace.empty() && element_name == "item") {
-      Maybe<StringPiece> maybe_quantity =
-          xml::FindNonEmptyAttribute(parser, "quantity");
+      std::optional<StringPiece> maybe_quantity = xml::FindNonEmptyAttribute(parser, "quantity");
       if (!maybe_quantity) {
         diag_->Error(DiagMessage(item_source)
                      << "<item> in <plurals> requires attribute "
@@ -1767,7 +1763,7 @@
     const std::string& element_namespace = parser->element_namespace();
     const std::string& element_name = parser->element_name();
     if (element_namespace.empty() && element_name == "attr") {
-      Maybe<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
+      std::optional<StringPiece> maybe_name = xml::FindNonEmptyAttribute(parser, "name");
       if (!maybe_name) {
         diag_->Error(DiagMessage(item_source) << "<attr> tag must have a 'name' attribute");
         error = true;
@@ -1777,7 +1773,7 @@
       // If this is a declaration, the package name may be in the name. Separate
       // these out.
       // Eg. <attr name="android:text" />
-      Maybe<Reference> maybe_ref = ResourceUtils::ParseXmlAttributeName(maybe_name.value());
+      std::optional<Reference> maybe_ref = ResourceUtils::ParseXmlAttributeName(maybe_name.value());
       if (!maybe_ref) {
         diag_->Error(DiagMessage(item_source) << "<attr> tag has invalid name '"
                                               << maybe_name.value() << "'");
diff --git a/tools/aapt2/ResourceParser.h b/tools/aapt2/ResourceParser.h
index 2614997..548f5f9 100644
--- a/tools/aapt2/ResourceParser.h
+++ b/tools/aapt2/ResourceParser.h
@@ -18,6 +18,7 @@
 #define AAPT_RESOURCE_PARSER_H
 
 #include <memory>
+#include <optional>
 
 #include "android-base/macros.h"
 #include "androidfw/ConfigDescription.h"
@@ -27,7 +28,6 @@
 #include "ResourceTable.h"
 #include "ResourceValues.h"
 #include "StringPool.h"
-#include "util/Maybe.h"
 #include "xml/XmlPullParser.h"
 
 namespace aapt {
@@ -54,7 +54,7 @@
 
   // If visibility was forced, we need to use it when creating a new resource and also error if we
   // try to parse the <public>, <public-group>, <java-symbol> or <symbol> tags.
-  Maybe<Visibility::Level> visibility;
+  std::optional<Visibility::Level> visibility;
 };
 
 struct FlattenedXmlSubTree {
@@ -122,8 +122,8 @@
   bool ParseAddResource(xml::XmlPullParser* parser, ParsedResource* out_resource);
   bool ParseAttr(xml::XmlPullParser* parser, ParsedResource* out_resource);
   bool ParseAttrImpl(xml::XmlPullParser* parser, ParsedResource* out_resource, bool weak);
-  Maybe<Attribute::Symbol> ParseEnumOrFlagItem(xml::XmlPullParser* parser,
-                                               const android::StringPiece& tag);
+  std::optional<Attribute::Symbol> ParseEnumOrFlagItem(xml::XmlPullParser* parser,
+                                                       const android::StringPiece& tag);
   bool ParseStyle(ResourceType type, xml::XmlPullParser* parser, ParsedResource* out_resource);
   bool ParseStyleItem(xml::XmlPullParser* parser, Style* style);
   bool ParseDeclareStyleable(xml::XmlPullParser* parser, ParsedResource* out_resource);
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index 279ebcba..556ffa22 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -567,12 +567,12 @@
   Style* style = test::GetValue<Style>(&table_, "style/foo");
   ASSERT_THAT(style, NotNull());
   ASSERT_TRUE(style->parent);
-  EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("style/fu"))));
+  EXPECT_THAT(style->parent.value().name, Eq(test::ParseNameOrDie("style/fu")));
   ASSERT_THAT(style->entries, SizeIs(3));
 
-  EXPECT_THAT(style->entries[0].key.name, Eq(make_value(test::ParseNameOrDie("attr/bar"))));
-  EXPECT_THAT(style->entries[1].key.name, Eq(make_value(test::ParseNameOrDie("attr/bat"))));
-  EXPECT_THAT(style->entries[2].key.name, Eq(make_value(test::ParseNameOrDie("attr/baz"))));
+  EXPECT_THAT(style->entries[0].key.name, Eq(test::ParseNameOrDie("attr/bar")));
+  EXPECT_THAT(style->entries[1].key.name, Eq(test::ParseNameOrDie("attr/bat")));
+  EXPECT_THAT(style->entries[2].key.name, Eq(test::ParseNameOrDie("attr/baz")));
 }
 
 TEST_F(ResourceParserTest, ParseStyleWithShorthandParent) {
@@ -581,7 +581,7 @@
   Style* style = test::GetValue<Style>(&table_, "style/foo");
   ASSERT_THAT(style, NotNull());
   ASSERT_TRUE(style->parent);
-  EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("com.app:style/Theme"))));
+  EXPECT_THAT(style->parent.value().name, Eq(test::ParseNameOrDie("com.app:style/Theme")));
 }
 
 TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedParent) {
@@ -594,7 +594,7 @@
   ASSERT_THAT(style, NotNull());
   ASSERT_TRUE(style->parent);
   ASSERT_TRUE(style->parent.value().name);
-  EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("android:style/Theme"))));
+  EXPECT_THAT(style->parent.value().name, Eq(test::ParseNameOrDie("android:style/Theme")));
 }
 
 TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) {
@@ -607,7 +607,7 @@
   Style* style = test::GetValue<Style>(&table_, "style/foo");
   ASSERT_THAT(style, NotNull());
   ASSERT_THAT(style->entries, SizeIs(1));
-  EXPECT_THAT(style->entries[0].key.name, Eq(make_value(test::ParseNameOrDie("android:attr/bar"))));
+  EXPECT_THAT(style->entries[0].key.name, Eq(test::ParseNameOrDie("android:attr/bar")));
 }
 
 TEST_F(ResourceParserTest, ParseStyleWithRawStringItem) {
@@ -634,7 +634,7 @@
   Style* style = test::GetValue<Style>(&table_, "style/foo.bar");
   ASSERT_THAT(style, NotNull());
   ASSERT_TRUE(style->parent);
-  EXPECT_THAT(style->parent.value().name, Eq(make_value(test::ParseNameOrDie("style/foo"))));
+  EXPECT_THAT(style->parent.value().name, Eq(test::ParseNameOrDie("style/foo")));
   EXPECT_TRUE(style->parent_inferred);
 }
 
@@ -672,7 +672,7 @@
       </declare-styleable>)";
   ASSERT_TRUE(TestParse(input));
 
-  Maybe<ResourceTable::SearchResult> result =
+  std::optional<ResourceTable::SearchResult> result =
       table_.FindResource(test::ParseNameOrDie("styleable/foo"));
   ASSERT_TRUE(result);
   EXPECT_THAT(result.value().entry->visibility.level, Eq(Visibility::Level::kPublic));
@@ -695,9 +695,9 @@
   ASSERT_THAT(styleable, NotNull());
   ASSERT_THAT(styleable->entries, SizeIs(3));
 
-  EXPECT_THAT(styleable->entries[0].name, Eq(make_value(test::ParseNameOrDie("attr/bar"))));
-  EXPECT_THAT(styleable->entries[1].name, Eq(make_value(test::ParseNameOrDie("attr/bat"))));
-  EXPECT_THAT(styleable->entries[2].name, Eq(make_value(test::ParseNameOrDie("attr/baz"))));
+  EXPECT_THAT(styleable->entries[0].name, Eq(test::ParseNameOrDie("attr/bar")));
+  EXPECT_THAT(styleable->entries[1].name, Eq(test::ParseNameOrDie("attr/bat")));
+  EXPECT_THAT(styleable->entries[2].name, Eq(test::ParseNameOrDie("attr/baz")));
 }
 
 TEST_F(ResourceParserTest, ParseDeclareStyleablePreservingVisibility) {
@@ -913,7 +913,8 @@
       </public-group>)";
   ASSERT_TRUE(TestParse(input));
 
-  Maybe<ResourceTable::SearchResult> result = table_.FindResource(test::ParseNameOrDie("attr/foo"));
+  std::optional<ResourceTable::SearchResult> result =
+      table_.FindResource(test::ParseNameOrDie("attr/foo"));
   ASSERT_TRUE(result);
   ASSERT_TRUE(result.value().entry->id);
   EXPECT_THAT(result.value().entry->id.value(), Eq(ResourceId(0x01010040)));
@@ -932,7 +933,8 @@
       </staging-public-group>)";
   ASSERT_TRUE(TestParse(input));
 
-  Maybe<ResourceTable::SearchResult> result = table_.FindResource(test::ParseNameOrDie("attr/foo"));
+  std::optional<ResourceTable::SearchResult> result =
+      table_.FindResource(test::ParseNameOrDie("attr/foo"));
   ASSERT_TRUE(result);
 
   ASSERT_TRUE(result.value().entry->id);
@@ -959,7 +961,7 @@
       <java-symbol type="string" name="foo" />)";
   ASSERT_TRUE(TestParse(input));
 
-  Maybe<ResourceTable::SearchResult> result =
+  std::optional<ResourceTable::SearchResult> result =
       table_.FindResource(test::ParseNameOrDie("string/foo"));
   ASSERT_TRUE(result);
 
@@ -977,7 +979,7 @@
 TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) {
   ASSERT_TRUE(TestParse(R"(<add-resource name="bar" type="string" />)"));
 
-  Maybe<ResourceTable::SearchResult> result =
+  std::optional<ResourceTable::SearchResult> result =
       table_.FindResource(test::ParseNameOrDie("string/bar"));
   ASSERT_TRUE(result);
   const ResourceEntry* entry = result.value().entry;
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp
index 8ab1493..ad014a2 100644
--- a/tools/aapt2/ResourceTable.cpp
+++ b/tools/aapt2/ResourceTable.cpp
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <memory>
+#include <optional>
 #include <tuple>
 
 #include "android-base/logging.h"
@@ -68,7 +69,7 @@
 
 template <typename T, typename U>
 bool less_than_struct_with_name_and_id(const T& lhs,
-                                       const std::pair<std::string_view, Maybe<U>>& rhs) {
+                                       const std::pair<std::string_view, std::optional<U>>& rhs) {
   if (lhs.id != rhs.second) {
     return lhs.id < rhs.second;
   }
@@ -341,20 +342,20 @@
 
 void InsertEntryIntoTableView(ResourceTableView& table, const ResourceTablePackage* package,
                               const ResourceTableType* type, const std::string& entry_name,
-                              const Maybe<ResourceId>& id, const Visibility& visibility,
-                              const Maybe<AllowNew>& allow_new,
-                              const Maybe<OverlayableItem>& overlayable_item,
-                              const Maybe<StagedId>& staged_id,
+                              const std::optional<ResourceId>& id, const Visibility& visibility,
+                              const std::optional<AllowNew>& allow_new,
+                              const std::optional<OverlayableItem>& overlayable_item,
+                              const std::optional<StagedId>& staged_id,
                               const std::vector<std::unique_ptr<ResourceConfigValue>>& values) {
   SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
   SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
   SortedVectorInserter<ResourceTableEntryView, EntryViewComparer> entry_inserter;
 
   ResourceTablePackageView new_package{package->name,
-                                       id ? id.value().package_id() : Maybe<uint8_t>{}};
+                                       id ? id.value().package_id() : std::optional<uint8_t>{}};
   auto view_package = package_inserter.Insert(table.packages, std::move(new_package));
 
-  ResourceTableTypeView new_type{type->type, id ? id.value().type_id() : Maybe<uint8_t>{}};
+  ResourceTableTypeView new_type{type->type, id ? id.value().type_id() : std::optional<uint8_t>{}};
   auto view_type = type_inserter.Insert(view_package->types, std::move(new_type));
 
   if (visibility.level == Visibility::Level::kPublic) {
@@ -363,7 +364,7 @@
   }
 
   ResourceTableEntryView new_entry{.name = entry_name,
-                                   .id = id ? id.value().entry_id() : Maybe<uint16_t>{},
+                                   .id = id ? id.value().entry_id() : std::optional<uint16_t>{},
                                    .visibility = visibility,
                                    .allow_new = allow_new,
                                    .overlayable_item = overlayable_item,
@@ -585,7 +586,8 @@
   return true;
 }
 
-Maybe<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name) const {
+std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(
+    const ResourceNameRef& name) const {
   ResourceTablePackage* package = FindPackage(name.package);
   if (package == nullptr) {
     return {};
@@ -603,8 +605,8 @@
   return SearchResult{package, type, entry};
 }
 
-Maybe<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name,
-                                                               ResourceId id) const {
+std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name,
+                                                                       ResourceId id) const {
   ResourceTablePackage* package = FindPackage(name.package);
   if (package == nullptr) {
     return {};
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h
index bae1d82..2e17659 100644
--- a/tools/aapt2/ResourceTable.h
+++ b/tools/aapt2/ResourceTable.h
@@ -120,18 +120,18 @@
   const std::string name;
 
   // The entry ID for this resource (the EEEE in 0xPPTTEEEE).
-  Maybe<ResourceId> id;
+  std::optional<ResourceId> id;
 
   // Whether this resource is public (and must maintain the same entry ID across builds).
   Visibility visibility;
 
-  Maybe<AllowNew> allow_new;
+  std::optional<AllowNew> allow_new;
 
   // The declarations of this resource as overlayable for RROs
-  Maybe<OverlayableItem> overlayable_item;
+  std::optional<OverlayableItem> overlayable_item;
 
   // The staged resource id for a finalized resource.
-  Maybe<StagedId> staged_id;
+  std::optional<StagedId> staged_id;
 
   // The resource's values for each configuration.
   std::vector<std::unique_ptr<ResourceConfigValue>> values;
@@ -205,11 +205,11 @@
 
 struct ResourceTableEntryView {
   std::string name;
-  Maybe<uint16_t> id;
+  std::optional<uint16_t> id;
   Visibility visibility;
-  Maybe<AllowNew> allow_new;
-  Maybe<OverlayableItem> overlayable_item;
-  Maybe<StagedId> staged_id;
+  std::optional<AllowNew> allow_new;
+  std::optional<OverlayableItem> overlayable_item;
+  std::optional<StagedId> staged_id;
   std::vector<const ResourceConfigValue*> values;
 
   const ResourceConfigValue* FindValue(const android::ConfigDescription& config,
@@ -218,7 +218,7 @@
 
 struct ResourceTableTypeView {
   ResourceType type;
-  Maybe<uint8_t> id;
+  std::optional<uint8_t> id;
   Visibility::Level visibility_level = Visibility::Level::kUndefined;
 
   // Entries sorted in ascending entry id order. If ids have not been assigned, the entries are
@@ -228,7 +228,7 @@
 
 struct ResourceTablePackageView {
   std::string name;
-  Maybe<uint8_t> id;
+  std::optional<uint8_t> id;
   // Types sorted in ascending type id order. If ids have not been assigned, the types are sorted by
   // their declaration order in the ResourceType enum.
   std::vector<ResourceTableTypeView> types;
@@ -309,8 +309,8 @@
     ResourceEntry* entry;
   };
 
-  Maybe<SearchResult> FindResource(const ResourceNameRef& name) const;
-  Maybe<SearchResult> FindResource(const ResourceNameRef& name, ResourceId id) const;
+  std::optional<SearchResult> FindResource(const ResourceNameRef& name) const;
+  std::optional<SearchResult> FindResource(const ResourceNameRef& name, ResourceId id) const;
   bool RemoveResource(const ResourceNameRef& name, ResourceId id) const;
 
   // Returns the package struct with the given name, or nullptr if such a package does not
diff --git a/tools/aapt2/ResourceTable_test.cpp b/tools/aapt2/ResourceTable_test.cpp
index 38391c9..de73d2c 100644
--- a/tools/aapt2/ResourceTable_test.cpp
+++ b/tools/aapt2/ResourceTable_test.cpp
@@ -162,7 +162,7 @@
   EXPECT_THAT(test::GetValueForConfigAndProduct<Id>(&table, "android:string/foo",test::ParseConfigOrDie("land"), "tablet"), NotNull());
   EXPECT_THAT(test::GetValueForConfigAndProduct<Id>(&table, "android:string/foo",test::ParseConfigOrDie("land"), "phone"), NotNull());
 
-  Maybe<ResourceTable::SearchResult> sr =
+  std::optional<ResourceTable::SearchResult> sr =
       table.FindResource(test::ParseNameOrDie("android:string/foo"));
   ASSERT_TRUE(sr);
   std::vector<ResourceConfigValue*> values =
@@ -187,7 +187,7 @@
                                                        const ResourceNameRef& name,
                                                        Visibility::Level level,
                                                        const StringPiece& comment) {
-  Maybe<ResourceTable::SearchResult> result = table.FindResource(name);
+  std::optional<ResourceTable::SearchResult> result = table.FindResource(name);
   if (!result) {
     return ::testing::AssertionFailure() << "no resource '" << name << "' found in table";
   }
@@ -242,7 +242,7 @@
   const ResourceName name = test::ParseNameOrDie("android:string/foo");
 
   AllowNew allow_new;
-  Maybe<ResourceTable::SearchResult> result;
+  std::optional<ResourceTable::SearchResult> result;
 
   allow_new.comment = "first";
   ASSERT_TRUE(table.AddResource(NewResourceBuilder(name).SetAllowNew(allow_new).Build(),
@@ -274,7 +274,7 @@
   const ResourceName name = test::ParseNameOrDie("android:string/foo");
   ASSERT_TRUE(table.AddResource(NewResourceBuilder(name).SetOverlayable(overlayable_item).Build(),
                                 test::GetDiagnostics()));
-  Maybe<ResourceTable::SearchResult> search_result = table.FindResource(name);
+  std::optional<ResourceTable::SearchResult> search_result = table.FindResource(name);
 
   ASSERT_TRUE(search_result);
   ASSERT_TRUE(search_result.value().entry->overlayable_item);
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index e0e80ac..ead06bf 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -40,8 +40,7 @@
 namespace aapt {
 namespace ResourceUtils {
 
-Maybe<ResourceName> ToResourceName(
-    const android::ResTable::resource_name& name_in) {
+std::optional<ResourceName> ToResourceName(const android::ResTable::resource_name& name_in) {
   // TODO: Remove this when ResTable and AssetManager(1) are removed from AAPT2
   ResourceName name_out;
   if (!name_in.package) {
@@ -78,7 +77,7 @@
   return name_out;
 }
 
-Maybe<ResourceName> ToResourceName(const android::AssetManager2::ResourceName& name_in) {
+std::optional<ResourceName> ToResourceName(const android::AssetManager2::ResourceName& name_in) {
   ResourceName name_out;
   if (!name_in.package) {
     return {};
@@ -251,8 +250,7 @@
  * <[*]package>:[style/]<entry>
  * [[*]package:style/]<entry>
  */
-Maybe<Reference> ParseStyleParentReference(const StringPiece& str,
-                                           std::string* out_error) {
+std::optional<Reference> ParseStyleParentReference(const StringPiece& str, std::string* out_error) {
   if (str.empty()) {
     return {};
   }
@@ -301,7 +299,7 @@
   return result;
 }
 
-Maybe<Reference> ParseXmlAttributeName(const StringPiece& str) {
+std::optional<Reference> ParseXmlAttributeName(const StringPiece& str) {
   StringPiece trimmed_str = util::TrimWhitespace(str);
   const char* start = trimmed_str.data();
   const char* const end = start + trimmed_str.size();
@@ -326,7 +324,7 @@
   }
 
   ref.name = ResourceName(package, ResourceType::kAttr, name.empty() ? trimmed_str : name);
-  return Maybe<Reference>(std::move(ref));
+  return std::optional<Reference>(std::move(ref));
 }
 
 std::unique_ptr<Reference> TryParseReference(const StringPiece& str,
@@ -488,18 +486,18 @@
                : util::make_unique<BinaryPrimitive>(value);
 }
 
-Maybe<bool> ParseBool(const StringPiece& str) {
+std::optional<bool> ParseBool(const StringPiece& str) {
   StringPiece trimmed_str(util::TrimWhitespace(str));
   if (trimmed_str == "true" || trimmed_str == "TRUE" || trimmed_str == "True") {
-    return Maybe<bool>(true);
+    return std::optional<bool>(true);
   } else if (trimmed_str == "false" || trimmed_str == "FALSE" ||
              trimmed_str == "False") {
-    return Maybe<bool>(false);
+    return std::optional<bool>(false);
   }
   return {};
 }
 
-Maybe<uint32_t> ParseInt(const StringPiece& str) {
+std::optional<uint32_t> ParseInt(const StringPiece& str) {
   std::u16string str16 = util::Utf8ToUtf16(str);
   android::Res_value value;
   if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) {
@@ -508,7 +506,7 @@
   return {};
 }
 
-Maybe<ResourceId> ParseResourceId(const StringPiece& str) {
+std::optional<ResourceId> ParseResourceId(const StringPiece& str) {
   StringPiece trimmed_str(util::TrimWhitespace(str));
 
   std::u16string str16 = util::Utf8ToUtf16(trimmed_str);
@@ -524,7 +522,7 @@
   return {};
 }
 
-Maybe<int> ParseSdkVersion(const StringPiece& str) {
+std::optional<int> ParseSdkVersion(const StringPiece& str) {
   StringPiece trimmed_str(util::TrimWhitespace(str));
 
   std::u16string str16 = util::Utf8ToUtf16(trimmed_str);
@@ -534,7 +532,7 @@
   }
 
   // Try parsing the code name.
-  Maybe<int> entry = GetDevelopmentSdkCodeNameVersion(trimmed_str);
+  std::optional<int> entry = GetDevelopmentSdkCodeNameVersion(trimmed_str);
   if (entry) {
     return entry.value();
   }
@@ -551,7 +549,7 @@
 }
 
 std::unique_ptr<BinaryPrimitive> TryParseBool(const StringPiece& str) {
-  if (Maybe<bool> maybe_result = ParseBool(str)) {
+  if (std::optional<bool> maybe_result = ParseBool(str)) {
     const uint32_t data = maybe_result.value() ? 0xffffffffu : 0u;
     return util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_BOOLEAN, data);
   }
diff --git a/tools/aapt2/ResourceUtils.h b/tools/aapt2/ResourceUtils.h
index be493db..fe450a8 100644
--- a/tools/aapt2/ResourceUtils.h
+++ b/tools/aapt2/ResourceUtils.h
@@ -75,35 +75,33 @@
 /**
  * Convert an android::ResTable::resource_name to an aapt::ResourceName struct.
  */
-Maybe<ResourceName> ToResourceName(
-    const android::ResTable::resource_name& name);
+std::optional<ResourceName> ToResourceName(const android::ResTable::resource_name& name);
 
 /**
  * Convert an android::AssetManager2::ResourceName to an aapt::ResourceName struct.
  */
-Maybe<ResourceName> ToResourceName(
-    const android::AssetManager2::ResourceName& name_in);
+std::optional<ResourceName> ToResourceName(const android::AssetManager2::ResourceName& name_in);
 
 /**
  * Returns a boolean value if the string is equal to TRUE, true, True, FALSE,
  * false, or False.
  */
-Maybe<bool> ParseBool(const android::StringPiece& str);
+std::optional<bool> ParseBool(const android::StringPiece& str);
 
 /**
  * Returns a uint32_t if the string is an integer.
  */
-Maybe<uint32_t> ParseInt(const android::StringPiece& str);
+std::optional<uint32_t> ParseInt(const android::StringPiece& str);
 
 /**
  * Returns an ID if it the string represented a valid ID.
  */
-Maybe<ResourceId> ParseResourceId(const android::StringPiece& str);
+std::optional<ResourceId> ParseResourceId(const android::StringPiece& str);
 
 /**
  * Parses an SDK version, which can be an integer, or a letter from A-Z.
  */
-Maybe<int> ParseSdkVersion(const android::StringPiece& str);
+std::optional<int> ParseSdkVersion(const android::StringPiece& str);
 
 /*
  * Returns a Reference, or None Maybe instance if the string `str` was parsed as
@@ -116,7 +114,8 @@
  * ?[package:]style/<entry> or
  * <package>:[style/]<entry>
  */
-Maybe<Reference> ParseStyleParentReference(const android::StringPiece& str, std::string* out_error);
+std::optional<Reference> ParseStyleParentReference(const android::StringPiece& str,
+                                                   std::string* out_error);
 
 /*
  * Returns a Reference if the string `str` was parsed as a valid XML attribute
@@ -125,7 +124,7 @@
  *
  * package:entry
  */
-Maybe<Reference> ParseXmlAttributeName(const android::StringPiece& str);
+std::optional<Reference> ParseXmlAttributeName(const android::StringPiece& str);
 
 /*
  * Returns a Reference object if the string was parsed as a resource or
diff --git a/tools/aapt2/ResourceUtils_test.cpp b/tools/aapt2/ResourceUtils_test.cpp
index b08bf9a..1aaa34d 100644
--- a/tools/aapt2/ResourceUtils_test.cpp
+++ b/tools/aapt2/ResourceUtils_test.cpp
@@ -30,15 +30,15 @@
 namespace aapt {
 
 TEST(ResourceUtilsTest, ParseBool) {
-  EXPECT_THAT(ResourceUtils::ParseBool("true"), Eq(Maybe<bool>(true)));
-  EXPECT_THAT(ResourceUtils::ParseBool("TRUE"), Eq(Maybe<bool>(true)));
-  EXPECT_THAT(ResourceUtils::ParseBool("True"), Eq(Maybe<bool>(true)));
+  EXPECT_THAT(ResourceUtils::ParseBool("true"), Eq(std::optional<bool>(true)));
+  EXPECT_THAT(ResourceUtils::ParseBool("TRUE"), Eq(std::optional<bool>(true)));
+  EXPECT_THAT(ResourceUtils::ParseBool("True"), Eq(std::optional<bool>(true)));
 
-  EXPECT_THAT(ResourceUtils::ParseBool("false"), Eq(Maybe<bool>(false)));
-  EXPECT_THAT(ResourceUtils::ParseBool("FALSE"), Eq(Maybe<bool>(false)));
-  EXPECT_THAT(ResourceUtils::ParseBool("False"), Eq(Maybe<bool>(false)));
+  EXPECT_THAT(ResourceUtils::ParseBool("false"), Eq(std::optional<bool>(false)));
+  EXPECT_THAT(ResourceUtils::ParseBool("FALSE"), Eq(std::optional<bool>(false)));
+  EXPECT_THAT(ResourceUtils::ParseBool("False"), Eq(std::optional<bool>(false)));
 
-  EXPECT_THAT(ResourceUtils::ParseBool(" False\n "), Eq(Maybe<bool>(false)));
+  EXPECT_THAT(ResourceUtils::ParseBool(" False\n "), Eq(std::optional<bool>(false)));
 }
 
 TEST(ResourceUtilsTest, ParseResourceName) {
@@ -155,41 +155,42 @@
   const ResourceName kStyleFooName({}, ResourceType::kStyle, "foo");
 
   std::string err_str;
-  Maybe<Reference> ref = ResourceUtils::ParseStyleParentReference("@android:style/foo", &err_str);
+  std::optional<Reference> ref =
+      ResourceUtils::ParseStyleParentReference("@android:style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("@style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("?android:style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("?style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("android:style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("android:foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("@android:foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kStyleFooName));
 
   ref = ResourceUtils::ParseStyleParentReference("*android:style/foo", &err_str);
   ASSERT_TRUE(ref);
-  EXPECT_THAT(ref.value().name, Eq(make_value(kAndroidStyleFooName)));
+  EXPECT_THAT(ref.value().name, Eq(kAndroidStyleFooName));
   EXPECT_TRUE(ref.value().private_reference);
 }
 
@@ -228,15 +229,11 @@
 }
 
 TEST(ResourceUtilsTest, ParseSdkVersionWithCodename) {
-  EXPECT_THAT(ResourceUtils::ParseSdkVersion("Q"), Eq(Maybe<int>(10000)));
-  EXPECT_THAT(
-      ResourceUtils::ParseSdkVersion("Q.fingerprint"),
-      Eq(Maybe<int>(10000)));
+  EXPECT_THAT(ResourceUtils::ParseSdkVersion("Q"), Eq(std::optional<int>(10000)));
+  EXPECT_THAT(ResourceUtils::ParseSdkVersion("Q.fingerprint"), Eq(std::optional<int>(10000)));
 
-  EXPECT_THAT(ResourceUtils::ParseSdkVersion("R"), Eq(Maybe<int>(10000)));
-  EXPECT_THAT(
-      ResourceUtils::ParseSdkVersion("R.fingerprint"),
-      Eq(Maybe<int>(10000)));
+  EXPECT_THAT(ResourceUtils::ParseSdkVersion("R"), Eq(std::optional<int>(10000)));
+  EXPECT_THAT(ResourceUtils::ParseSdkVersion("R.fingerprint"), Eq(std::optional<int>(10000)));
 }
 
 TEST(ResourceUtilsTest, StringBuilderWhitespaceRemoval) {
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index 2a90f26..b3ab4ff 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -120,7 +120,7 @@
     return false;
   }
 
-  const ResourceId resid = id.value_or_default(ResourceId(0));
+  const ResourceId resid = id.value_or(ResourceId(0));
   const bool dynamic = resid.is_valid() && is_dynamic;
 
   if (reference_type == Reference::Type::kResource) {
@@ -1040,7 +1040,7 @@
 }
 
 bool operator<(const Reference& a, const Reference& b) {
-  int cmp = a.name.value_or_default({}).compare(b.name.value_or_default({}));
+  int cmp = a.name.value_or(ResourceName{}).compare(b.name.value_or(ResourceName{}));
   if (cmp != 0) return cmp < 0;
   return a.id < b.id;
 }
diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h
index d903b7e..1694d6b 100644
--- a/tools/aapt2/ResourceValues.h
+++ b/tools/aapt2/ResourceValues.h
@@ -31,7 +31,6 @@
 #include "ValueTransformer.h"
 #include "io/File.h"
 #include "text/Printer.h"
-#include "util/Maybe.h"
 
 namespace aapt {
 
@@ -159,8 +158,8 @@
     kAttribute,
   };
 
-  Maybe<ResourceName> name;
-  Maybe<ResourceId> id;
+  std::optional<ResourceName> name;
+  std::optional<ResourceId> id;
   std::optional<uint32_t> type_flags;
   Reference::Type reference_type;
   bool private_reference = false;
@@ -327,7 +326,7 @@
     friend std::ostream& operator<<(std::ostream& out, const Entry& entry);
   };
 
-  Maybe<Reference> parent;
+  std::optional<Reference> parent;
 
   // If set to true, the parent was auto inferred from the style's name.
   bool parent_inferred = false;
diff --git a/tools/aapt2/SdkConstants.cpp b/tools/aapt2/SdkConstants.cpp
index ebe41da..f7a5ba1 100644
--- a/tools/aapt2/SdkConstants.cpp
+++ b/tools/aapt2/SdkConstants.cpp
@@ -77,9 +77,10 @@
   return iter->second;
 }
 
-Maybe<ApiVersion> GetDevelopmentSdkCodeNameVersion(const StringPiece& code_name) {
+std::optional<ApiVersion> GetDevelopmentSdkCodeNameVersion(const StringPiece& code_name) {
   return (sDevelopmentSdkCodeNames.find(code_name) == sDevelopmentSdkCodeNames.end())
-      ? Maybe<ApiVersion>() : sDevelopmentSdkLevel;
+             ? std::optional<ApiVersion>()
+             : sDevelopmentSdkLevel;
 }
 
 }  // namespace aapt
diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h
index 6bb6ddb..7518e70 100644
--- a/tools/aapt2/SdkConstants.h
+++ b/tools/aapt2/SdkConstants.h
@@ -60,7 +60,7 @@
 };
 
 ApiVersion FindAttributeSdkLevel(const ResourceId& id);
-Maybe<ApiVersion> GetDevelopmentSdkCodeNameVersion(const android::StringPiece& code_name);
+std::optional<ApiVersion> GetDevelopmentSdkCodeNameVersion(const android::StringPiece& code_name);
 
 }  // namespace aapt
 
diff --git a/tools/aapt2/Source.h b/tools/aapt2/Source.h
index 92934c3..4f9369a 100644
--- a/tools/aapt2/Source.h
+++ b/tools/aapt2/Source.h
@@ -17,21 +17,20 @@
 #ifndef AAPT_SOURCE_H
 #define AAPT_SOURCE_H
 
+#include <optional>
 #include <ostream>
 #include <string>
 
 #include "android-base/stringprintf.h"
 #include "androidfw/StringPiece.h"
 
-#include "util/Maybe.h"
-
 namespace aapt {
 
 // Represents a file on disk. Used for logging and showing errors.
 struct Source {
   std::string path;
-  Maybe<size_t> line;
-  Maybe<std::string> archive;
+  std::optional<size_t> line;
+  std::optional<std::string> archive;
 
   Source() = default;
 
diff --git a/tools/aapt2/cmd/Command.cpp b/tools/aapt2/cmd/Command.cpp
index 919b4c9..b1452fa 100644
--- a/tools/aapt2/cmd/Command.cpp
+++ b/tools/aapt2/cmd/Command.cpp
@@ -72,7 +72,7 @@
 }
 
 void Command::AddOptionalFlag(const StringPiece& name, const StringPiece& description,
-                              Maybe<std::string>* value, uint32_t flags) {
+                              std::optional<std::string>* value, uint32_t flags) {
   auto func = [value, flags](const StringPiece& arg) -> bool {
     *value = (flags & Command::kPath) ? GetSafePath(arg) : arg.to_string();
     return true;
diff --git a/tools/aapt2/cmd/Command.h b/tools/aapt2/cmd/Command.h
index d21571d..8678cda 100644
--- a/tools/aapt2/cmd/Command.h
+++ b/tools/aapt2/cmd/Command.h
@@ -18,6 +18,7 @@
 #define AAPT_COMMAND_H
 
 #include <functional>
+#include <optional>
 #include <ostream>
 #include <string>
 #include <unordered_set>
@@ -25,19 +26,20 @@
 
 #include "androidfw/StringPiece.h"
 
-#include "util/Maybe.h"
-
 namespace aapt {
 
 class Command {
  public:
-  explicit Command(const android::StringPiece& name) : name_(name.to_string()),
-                                                       short_name_(""),
-                                                       full_subcommand_name_(name.to_string()) {}
+  explicit Command(const android::StringPiece& name)
+      : name_(name.to_string()), full_subcommand_name_(name.to_string()){};
 
   explicit Command(const android::StringPiece& name, const android::StringPiece& short_name)
-      : name_(name.to_string()), short_name_(short_name.to_string()),
-        full_subcommand_name_(name.to_string()) {}
+      : name_(name.to_string()),
+        short_name_(short_name.to_string()),
+        full_subcommand_name_(name.to_string()){};
+
+  Command(Command&&) = default;
+  Command& operator=(Command&&) = default;
 
   virtual ~Command() = default;
 
@@ -58,7 +60,7 @@
                            uint32_t flags = 0);
 
   void AddOptionalFlag(const android::StringPiece& name, const android::StringPiece& description,
-                       Maybe<std::string>* value, uint32_t flags = 0);
+                       std::optional<std::string>* value, uint32_t flags = 0);
 
   void AddOptionalFlagList(const android::StringPiece& name,
                            const android::StringPiece& description, std::vector<std::string>* value,
@@ -87,8 +89,6 @@
   virtual int Action(const std::vector<std::string>& args) = 0;
 
  private:
-  DISALLOW_COPY_AND_ASSIGN(Command);
-
   struct Flag {
     explicit Flag(const android::StringPiece& name, const android::StringPiece& description,
                   const bool is_required, const size_t num_args,
@@ -104,8 +104,8 @@
     bool found = false;
   };
 
-  const std::string name_;
-  const std::string short_name_;
+  std::string name_;
+  std::string short_name_;
   std::string description_ = "";
   std::string full_subcommand_name_;
 
diff --git a/tools/aapt2/cmd/Command_test.cpp b/tools/aapt2/cmd/Command_test.cpp
index 65608fd..7aa1aa01 100644
--- a/tools/aapt2/cmd/Command_test.cpp
+++ b/tools/aapt2/cmd/Command_test.cpp
@@ -38,7 +38,7 @@
   TestCommand command;
   std::string required_flag;
   command.AddRequiredFlag("--rflag", "", &required_flag, Command::kPath);
-  Maybe<std::string> optional_flag;
+  std::optional<std::string> optional_flag;
   command.AddOptionalFlag("--oflag", "", &optional_flag, Command::kPath);
   std::vector<std::string> required_flag_list;
   command.AddRequiredFlagList("--rlflag", "", &required_flag_list, Command::kPath);
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index cd5015e..fe56018 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -47,7 +47,6 @@
 #include "io/ZipArchive.h"
 #include "trace/TraceBuffer.h"
 #include "util/Files.h"
-#include "util/Maybe.h"
 #include "util/Util.h"
 #include "xml/XmlDom.h"
 #include "xml/XmlPullParser.h"
@@ -75,10 +74,10 @@
 };
 
 // Resource file paths are expected to look like: [--/res/]type[-config]/name
-static Maybe<ResourcePathData> ExtractResourcePathData(const std::string& path,
-                                                       const char dir_sep,
-                                                       std::string* out_error,
-                                                       const CompileOptions& options) {
+static std::optional<ResourcePathData> ExtractResourcePathData(const std::string& path,
+                                                               const char dir_sep,
+                                                               std::string* out_error,
+                                                               const CompileOptions& options) {
   std::vector<std::string> parts = util::Split(path, dir_sep);
   if (parts.size() < 2) {
     if (out_error) *out_error = "bad resource path";
@@ -337,7 +336,7 @@
     if (file_type == file::FileType::kDirectory) {
       context->GetDiagnostics()->Error(DiagMessage(input_path)
                                        << "resource file cannot be a directory");
-    } else if (file_type == file::FileType::kNonexistant) {
+    } else if (file_type == file::FileType::kNonExistant) {
       context->GetDiagnostics()->Error(DiagMessage(input_path) << "file not found");
     } else {
       context->GetDiagnostics()->Error(DiagMessage(input_path)
diff --git a/tools/aapt2/cmd/Compile.h b/tools/aapt2/cmd/Compile.h
index 1bc1f66..bd2e3d7 100644
--- a/tools/aapt2/cmd/Compile.h
+++ b/tools/aapt2/cmd/Compile.h
@@ -17,7 +17,10 @@
 #ifndef AAPT2_COMPILE_H
 #define AAPT2_COMPILE_H
 
-#include "androidfw/StringPiece.h"
+#include <optional>
+
+#include <androidfw/StringPiece.h>
+
 #include "format/Archive.h"
 #include "process/IResourceTableConsumer.h"
 #include "Command.h"
@@ -28,11 +31,11 @@
 
 struct CompileOptions {
   std::string output_path;
-  Maybe<std::string> source_path;
-  Maybe<std::string> res_dir;
-  Maybe<std::string> res_zip;
-  Maybe<std::string> generate_text_symbols_path;
-  Maybe<Visibility::Level> visibility;
+  std::optional<std::string> source_path;
+  std::optional<std::string> res_dir;
+  std::optional<std::string> res_zip;
+  std::optional<std::string> generate_text_symbols_path;
+  std::optional<Visibility::Level> visibility;
   bool pseudolocalize = false;
   bool no_png_crunch = false;
   bool legacy_mode = false;
@@ -80,8 +83,8 @@
  private:
   IDiagnostics* diagnostic_;
   CompileOptions options_;
-  Maybe<std::string> visibility_;
-  Maybe<std::string> trace_folder_;
+  std::optional<std::string> visibility_;
+  std::optional<std::string> trace_folder_;
 };
 
 int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer,
diff --git a/tools/aapt2/cmd/Convert.cpp b/tools/aapt2/cmd/Convert.cpp
index 22bcd85..3b097e0 100644
--- a/tools/aapt2/cmd/Convert.cpp
+++ b/tools/aapt2/cmd/Convert.cpp
@@ -367,8 +367,7 @@
     return 1;
   }
 
-  Maybe<AppInfo> app_info = ExtractAppInfoFromBinaryManifest(*apk->GetManifest(),
-                                                             context.GetDiagnostics());
+  auto app_info = ExtractAppInfoFromBinaryManifest(*apk->GetManifest(), context.GetDiagnostics());
   if (!app_info) {
     return 1;
   }
diff --git a/tools/aapt2/cmd/Convert.h b/tools/aapt2/cmd/Convert.h
index 7e2029d..2cdb0c8 100644
--- a/tools/aapt2/cmd/Convert.h
+++ b/tools/aapt2/cmd/Convert.h
@@ -17,6 +17,8 @@
 #ifndef AAPT2_CONVERT_H
 #define AAPT2_CONVERT_H
 
+#include <optional>
+
 #include "Command.h"
 #include "LoadedApk.h"
 #include "format/binary/TableFlattener.h"
@@ -52,7 +54,7 @@
   TableFlattenerOptions table_flattener_options_;
   XmlFlattenerOptions xml_flattener_options_;
   std::string output_path_;
-  Maybe<std::string> output_format_;
+  std::optional<std::string> output_format_;
   bool verbose_ = false;
 };
 
diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp
index 3950f33..d9e8c92 100644
--- a/tools/aapt2/cmd/Diff.cpp
+++ b/tools/aapt2/cmd/Diff.cpp
@@ -87,8 +87,8 @@
 }
 
 template <typename Id>
-static bool IsIdDiff(const Visibility::Level& level_a, const Maybe<Id>& id_a,
-                     const Visibility::Level& level_b, const Maybe<Id>& id_b) {
+static bool IsIdDiff(const Visibility::Level& level_a, const std::optional<Id>& id_a,
+                     const Visibility::Level& level_b, const std::optional<Id>& id_b) {
   if (level_a == Visibility::Level::kPublic || level_b == Visibility::Level::kPublic) {
     return id_a != id_b;
   }
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index 3982d12..0a1e021 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -257,12 +257,11 @@
 }
 
 int DumpPackageNameCommand::Dump(LoadedApk* apk) {
-  Maybe<std::string> package_name = GetPackageName(apk);
-  if (!package_name) {
+  auto package_name = GetPackageName(apk);
+  if (!package_name.has_value()) {
     return 1;
   }
-
-  GetPrinter()->Println(package_name.value());
+  GetPrinter()->Println(*package_name);
   return 0;
 }
 
@@ -283,12 +282,12 @@
 }
 
 int DumpStyleParentCommand::Dump(LoadedApk* apk) {
-  Maybe<std::string> package_name = GetPackageName(apk);
-  if (!package_name) {
+  auto package_name = GetPackageName(apk);
+  if (!package_name.has_value()) {
     return 1;
   }
 
-  const auto target_style = ResourceName(package_name.value(), ResourceType::kStyle, style_);
+  const auto target_style = ResourceName(*package_name, ResourceType::kStyle, style_);
   const auto table = apk->GetResourceTable();
 
   if (!table) {
@@ -296,7 +295,7 @@
     return 1;
   }
 
-  Maybe<ResourceTable::SearchResult> target = table->FindResource(target_style);
+  std::optional<ResourceTable::SearchResult> target = table->FindResource(target_style);
   if (!target) {
     GetDiagnostics()->Error(
         DiagMessage() << "Target style \"" << target_style.entry << "\" does not exist");
diff --git a/tools/aapt2/cmd/Dump.h b/tools/aapt2/cmd/Dump.h
index cd51f7a..52616fa 100644
--- a/tools/aapt2/cmd/Dump.h
+++ b/tools/aapt2/cmd/Dump.h
@@ -43,17 +43,17 @@
     return diag_;
   }
 
-  Maybe<std::string> GetPackageName(LoadedApk* apk) {
+  std::optional<std::string> GetPackageName(LoadedApk* apk) {
     xml::Element* manifest_el = apk->GetManifest()->root.get();
     if (!manifest_el) {
       GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest.");
-      return Maybe<std::string>();
+      return {};
     }
 
     xml::Attribute* attr = manifest_el->FindAttribute({}, "package");
     if (!attr) {
       GetDiagnostics()->Error(DiagMessage() << "No package name.");
-      return Maybe<std::string>();
+      return {};
     }
     return attr->value;
   }
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index e4d0f3b..e614a75 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -299,7 +299,7 @@
   bool do_not_fail_on_missing_resources = false;
   OutputFormat output_format = OutputFormat::kApk;
   std::unordered_set<std::string> extensions_to_not_compress;
-  Maybe<std::regex> regex_to_not_compress;
+  std::optional<std::regex> regex_to_not_compress;
 };
 
 // A sampling of public framework resource IDs.
@@ -741,7 +741,7 @@
     const size_t res_id_str_len = line.size() - res_id_start_idx;
     StringPiece res_id_str = util::TrimWhitespace(line.substr(res_id_start_idx, res_id_str_len));
 
-    Maybe<ResourceId> maybe_id = ResourceUtils::ParseResourceId(res_id_str);
+    std::optional<ResourceId> maybe_id = ResourceUtils::ParseResourceId(res_id_str);
     if (!maybe_id) {
       diag->Error(DiagMessage(Source(path, line_no)) << "invalid resource ID '" << res_id_str
                                                      << "'");
@@ -793,7 +793,7 @@
     if (!options_.manifest_fixer_options.compile_sdk_version) {
       xml::Attribute* attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionCode");
       if (attr != nullptr) {
-        Maybe<std::string>& compile_sdk_version = options_.manifest_fixer_options.compile_sdk_version;
+        auto& compile_sdk_version = options_.manifest_fixer_options.compile_sdk_version;
         if (BinaryPrimitive* prim = ValueCast<BinaryPrimitive>(attr->compiled_value.get())) {
           switch (prim->value.dataType) {
             case Res_value::TYPE_INT_DEC:
@@ -816,7 +816,7 @@
     if (!options_.manifest_fixer_options.compile_sdk_version_codename) {
       xml::Attribute* attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionName");
       if (attr != nullptr) {
-        Maybe<std::string>& compile_sdk_version_codename =
+        std::optional<std::string>& compile_sdk_version_codename =
             options_.manifest_fixer_options.compile_sdk_version_codename;
         if (String* str = ValueCast<String>(attr->compiled_value.get())) {
           compile_sdk_version_codename = *str->value;
@@ -912,7 +912,7 @@
     return true;
   }
 
-  Maybe<AppInfo> ExtractAppInfoFromManifest(xml::XmlResource* xml_res, IDiagnostics* diag) {
+  std::optional<AppInfo> ExtractAppInfoFromManifest(xml::XmlResource* xml_res, IDiagnostics* diag) {
     TRACE_CALL();
     // Make sure the first element is <manifest> with package attribute.
     xml::Element* manifest_el = xml::FindRootElement(xml_res->root.get());
@@ -937,7 +937,7 @@
 
     if (xml::Attribute* version_code_attr =
             manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCode")) {
-      Maybe<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_attr->value);
+      std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_attr->value);
       if (!maybe_code) {
         diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
                     << "invalid android:versionCode '" << version_code_attr->value << "'");
@@ -948,7 +948,7 @@
 
     if (xml::Attribute* version_code_major_attr =
         manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
-      Maybe<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_major_attr->value);
+      std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_major_attr->value);
       if (!maybe_code) {
         diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
                         << "invalid android:versionCodeMajor '"
@@ -960,7 +960,7 @@
 
     if (xml::Attribute* revision_code_attr =
             manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
-      Maybe<uint32_t> maybe_code = ResourceUtils::ParseInt(revision_code_attr->value);
+      std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(revision_code_attr->value);
       if (!maybe_code) {
         diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
                     << "invalid android:revisionCode '" << revision_code_attr->value << "'");
@@ -1094,7 +1094,7 @@
 
   bool WriteJavaFile(ResourceTable* table, const StringPiece& package_name_to_generate,
                      const StringPiece& out_package, const JavaClassGeneratorOptions& java_options,
-                     const Maybe<std::string>& out_text_symbols_path = {}) {
+                     const std::optional<std::string>& out_text_symbols_path = {}) {
     if (!options_.generate_java_class_path && !out_text_symbols_path) {
       return true;
     }
@@ -1251,7 +1251,7 @@
     }
 
     const std::string package_utf8 =
-        options_.custom_java_package.value_or_default(context_->GetCompilationPackage());
+        options_.custom_java_package.value_or(context_->GetCompilationPackage());
 
     std::string out_path = options_.generate_java_class_path.value();
     file::AppendPath(&out_path, file::PackageToPath(package_utf8));
@@ -1283,7 +1283,7 @@
     return true;
   }
 
-  bool WriteProguardFile(const Maybe<std::string>& out, const proguard::KeepSet& keep_set) {
+  bool WriteProguardFile(const std::optional<std::string>& out, const proguard::KeepSet& keep_set) {
     TRACE_CALL();
     if (!out) {
       return true;
@@ -1374,7 +1374,7 @@
         res_name.package = context_->GetCompilationPackage();
       }
 
-      Maybe<ResourceName> mangled_name = context_->GetNameMangler()->MangleName(res_name);
+      std::optional<ResourceName> mangled_name = context_->GetNameMangler()->MangleName(res_name);
       if (mangled_name) {
         res_name = mangled_name.value();
       }
@@ -1550,7 +1550,7 @@
   bool CopyAssetsDirsToApk(IArchiveWriter* writer) {
     std::map<std::string, std::unique_ptr<io::RegularFile>> merged_assets;
     for (const std::string& assets_dir : options_.assets_dirs) {
-      Maybe<std::vector<std::string>> files =
+      std::optional<std::vector<std::string>> files =
           file::FindFiles(assets_dir, context_->GetDiagnostics(), nullptr);
       if (!files) {
         return false;
@@ -1783,7 +1783,7 @@
         package_to_rewrite = table->packages.back().get();
         std::string new_package_name =
             StringPrintf("%s.%s", package_to_rewrite->name.c_str(),
-                         app_info_.split_name.value_or_default("feature").c_str());
+                         app_info_.split_name.value_or("feature").c_str());
 
         if (context_->IsVerbose()) {
           context_->GetDiagnostics()->Note(
@@ -1823,7 +1823,7 @@
     }
 
     // First extract the Package name without modifying it (via --rename-manifest-package).
-    if (Maybe<AppInfo> maybe_app_info =
+    if (std::optional<AppInfo> maybe_app_info =
             ExtractAppInfoFromManifest(manifest_xml.get(), context_->GetDiagnostics())) {
       const AppInfo& app_info = maybe_app_info.value();
       context_->SetCompilationPackage(app_info.package);
@@ -1850,14 +1850,14 @@
       return 1;
     }
 
-    Maybe<AppInfo> maybe_app_info =
+    std::optional<AppInfo> maybe_app_info =
         ExtractAppInfoFromManifest(manifest_xml.get(), context_->GetDiagnostics());
     if (!maybe_app_info) {
       return 1;
     }
 
     app_info_ = maybe_app_info.value();
-    context_->SetMinSdkVersion(app_info_.min_sdk_version.value_or_default(0));
+    context_->SetMinSdkVersion(app_info_.min_sdk_version.value_or(0));
 
     context_->SetNameManglerPolicy(NameManglerPolicy{context_->GetCompilationPackage()});
     context_->SetSplitNameDependencies(app_info_.split_name_dependencies);
@@ -2231,7 +2231,7 @@
   std::map<size_t, std::string> shared_libs_;
 
   // The package name of the base application, if it is included.
-  Maybe<std::string> included_feature_base_;
+  std::optional<std::string> included_feature_base_;
 };
 
 int LinkCommand::Action(const std::vector<std::string>& args) {
@@ -2315,7 +2315,8 @@
       return 1;
     }
 
-    const Maybe<uint32_t> maybe_package_id_int = ResourceUtils::ParseInt(package_id_.value());
+    const std::optional<uint32_t> maybe_package_id_int =
+        ResourceUtils::ParseInt(package_id_.value());
     if (!maybe_package_id_int) {
       context.GetDiagnostics()->Error(DiagMessage() << "package ID '" << package_id_.value()
                                                     << "' is not a valid integer");
@@ -2360,7 +2361,7 @@
   }
 
   if (preferred_density_) {
-    Maybe<uint16_t> density =
+    std::optional<uint16_t> density =
         ParseTargetDensityParameter(preferred_density_.value(), context.GetDiagnostics());
     if (!density) {
       return 1;
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h
index 768b4b2..d8c76e2 100644
--- a/tools/aapt2/cmd/Link.h
+++ b/tools/aapt2/cmd/Link.h
@@ -45,21 +45,21 @@
   bool auto_add_overlay = false;
   bool override_styles_instead_of_overlaying = false;
   OutputFormat output_format = OutputFormat::kApk;
-  Maybe<std::string> rename_resources_package;
+  std::optional<std::string> rename_resources_package;
 
   // Java/Proguard options.
-  Maybe<std::string> generate_java_class_path;
-  Maybe<std::string> custom_java_package;
+  std::optional<std::string> generate_java_class_path;
+  std::optional<std::string> custom_java_package;
   std::set<std::string> extra_java_packages;
-  Maybe<std::string> generate_text_symbols_path;
-  Maybe<std::string> generate_proguard_rules_path;
-  Maybe<std::string> generate_main_dex_proguard_rules_path;
+  std::optional<std::string> generate_text_symbols_path;
+  std::optional<std::string> generate_proguard_rules_path;
+  std::optional<std::string> generate_main_dex_proguard_rules_path;
   bool generate_conditional_proguard_rules = false;
   bool generate_minimal_proguard_rules = false;
   bool generate_non_final_ids = false;
   bool no_proguard_location_reference = false;
   std::vector<std::string> javadoc_annotations;
-  Maybe<std::string> private_symbols;
+  std::optional<std::string> private_symbols;
 
   // Optimizations/features.
   bool no_auto_version = false;
@@ -70,7 +70,7 @@
   bool no_xml_namespaces = false;
   bool do_not_compress_anything = false;
   std::unordered_set<std::string> extensions_to_not_compress;
-  Maybe<std::regex> regex_to_not_compress;
+  std::optional<std::regex> regex_to_not_compress;
 
   // Static lib options.
   bool no_static_lib_packages = false;
@@ -97,7 +97,7 @@
 
   // Stable ID options.
   std::unordered_map<ResourceName, ResourceId> stable_id_map;
-  Maybe<std::string> resource_id_map_path;
+  std::optional<std::string> resource_id_map_path;
 
   // When 'true', allow reserved package IDs to be used for applications. Pre-O, the platform
   // treats negative resource IDs [those with a package ID of 0x80 or higher] as invalid.
@@ -321,20 +321,20 @@
 
   std::vector<std::string> overlay_arg_list_;
   std::vector<std::string> extra_java_packages_;
-  Maybe<std::string> package_id_;
+  std::optional<std::string> package_id_;
   std::vector<std::string> configs_;
-  Maybe<std::string> preferred_density_;
-  Maybe<std::string> product_list_;
-  Maybe<std::string> no_compress_regex;
+  std::optional<std::string> preferred_density_;
+  std::optional<std::string> product_list_;
+  std::optional<std::string> no_compress_regex;
   bool legacy_x_flag_ = false;
   bool require_localization_ = false;
   bool verbose_ = false;
   bool shared_lib_ = false;
   bool static_lib_ = false;
   bool proto_format_ = false;
-  Maybe<std::string> stable_id_file_path_;
+  std::optional<std::string> stable_id_file_path_;
   std::vector<std::string> split_args_;
-  Maybe<std::string> trace_folder_;
+  std::optional<std::string> trace_folder_;
 };
 
 }// namespace aapt
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index 5b18a37..caa3e60 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -354,7 +354,7 @@
     return false;
   }
 
-  Maybe<AppInfo> app_info = ExtractAppInfoFromBinaryManifest(*manifest, context->GetDiagnostics());
+  auto app_info = ExtractAppInfoFromBinaryManifest(*manifest, context->GetDiagnostics());
   if (!app_info) {
     context->GetDiagnostics()->Error(DiagMessage()
                                      << "failed to extract data from AndroidManifest.xml");
@@ -362,7 +362,7 @@
   }
 
   out_options->app_info = std::move(app_info.value());
-  context->SetMinSdkVersion(out_options->app_info.min_sdk_version.value_or_default(0));
+  context->SetMinSdkVersion(out_options->app_info.min_sdk_version.value_or(0));
   return true;
 }
 
@@ -380,7 +380,7 @@
 
   if (config_path_) {
     std::string& path = config_path_.value();
-    Maybe<ConfigurationParser> for_path = ConfigurationParser::ForPath(path);
+    std::optional<ConfigurationParser> for_path = ConfigurationParser::ForPath(path);
     if (for_path) {
       options_.apk_artifacts = for_path.value().WithDiagnostics(diag).Parse(apk_path);
       if (!options_.apk_artifacts) {
@@ -427,7 +427,7 @@
   if (target_densities_) {
     // Parse the target screen densities.
     for (const StringPiece& config_str : util::Tokenize(target_densities_.value(), ',')) {
-      Maybe<uint16_t> target_density = ParseTargetDensityParameter(config_str, diag);
+      std::optional<uint16_t> target_density = ParseTargetDensityParameter(config_str, diag);
       if (!target_density) {
         return 1;
       }
diff --git a/tools/aapt2/cmd/Optimize.h b/tools/aapt2/cmd/Optimize.h
index 3afc46b..ff63e8d 100644
--- a/tools/aapt2/cmd/Optimize.h
+++ b/tools/aapt2/cmd/Optimize.h
@@ -29,9 +29,9 @@
   friend class OptimizeCommand;
 
   // Path to the output APK.
-  Maybe<std::string> output_path;
+  std::optional<std::string> output_path;
   // Path to the output APK directory for splits.
-  Maybe<std::string> output_dir;
+  std::optional<std::string> output_dir;
 
   // Details of the app extracted from the AndroidManifest.xml
   AppInfo app_info;
@@ -50,7 +50,7 @@
 
   TableFlattenerOptions table_flattener_options;
 
-  Maybe<std::vector<aapt::configuration::OutputArtifact>> apk_artifacts;
+  std::optional<std::vector<aapt::configuration::OutputArtifact>> apk_artifacts;
 
   // Set of artifacts to keep when generating multi-APK splits. If the list is empty, all artifacts
   // are kept and will be written as output.
@@ -60,7 +60,7 @@
   bool shorten_resource_paths = false;
 
   // Path to the output map of original resource paths to shortened paths.
-  Maybe<std::string> shortened_paths_map_path;
+  std::optional<std::string> shortened_paths_map_path;
 };
 
 class OptimizeCommand : public Command {
@@ -122,9 +122,9 @@
   bool WriteObfuscatedPathsMap(const std::map<std::string, std::string> &path_map,
                                const std::string &file_path);
 
-  Maybe<std::string> config_path_;
-  Maybe<std::string> resources_config_path_;
-  Maybe<std::string> target_densities_;
+  std::optional<std::string> config_path_;
+  std::optional<std::string> resources_config_path_;
+  std::optional<std::string> target_densities_;
   std::vector<std::string> configs_;
   std::vector<std::string> split_args_;
   std::unordered_set<std::string> kept_artifacts_;
diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp
index 7214f1a..3244fb8 100644
--- a/tools/aapt2/cmd/Util.cpp
+++ b/tools/aapt2/cmd/Util.cpp
@@ -21,11 +21,10 @@
 #include "android-base/logging.h"
 #include "androidfw/ConfigDescription.h"
 #include "androidfw/Locale.h"
-
 #include "ResourceUtils.h"
 #include "ValueVisitor.h"
 #include "split/TableSplitter.h"
-#include "util/Maybe.h"
+
 #include "util/Util.h"
 
 using ::android::ConfigDescription;
@@ -35,7 +34,7 @@
 
 namespace aapt {
 
-Maybe<uint16_t> ParseTargetDensityParameter(const StringPiece& arg, IDiagnostics* diag) {
+std::optional<uint16_t> ParseTargetDensityParameter(const StringPiece& arg, IDiagnostics* diag) {
   ConfigDescription preferred_density_config;
   if (!ConfigDescription::Parse(arg, &preferred_density_config)) {
     diag->Error(DiagMessage() << "invalid density '" << arg << "' for --preferred-density option");
@@ -245,8 +244,8 @@
   return doc;
 }
 
-static Maybe<std::string> ExtractCompiledString(const xml::Attribute& attr,
-                                                std::string* out_error) {
+static std::optional<std::string> ExtractCompiledString(const xml::Attribute& attr,
+                                                        std::string* out_error) {
   if (attr.compiled_value != nullptr) {
     const String* compiled_str = ValueCast<String>(attr.compiled_value.get());
     if (compiled_str != nullptr) {
@@ -269,7 +268,8 @@
   return {};
 }
 
-static Maybe<uint32_t> ExtractCompiledInt(const xml::Attribute& attr, std::string* out_error) {
+static std::optional<uint32_t> ExtractCompiledInt(const xml::Attribute& attr,
+                                                  std::string* out_error) {
   if (attr.compiled_value != nullptr) {
     const BinaryPrimitive* compiled_prim = ValueCast<BinaryPrimitive>(attr.compiled_value.get());
     if (compiled_prim != nullptr) {
@@ -283,7 +283,7 @@
   }
 
   // Fallback to the plain text value if there is one.
-  Maybe<uint32_t> integer = ResourceUtils::ParseInt(attr.value);
+  std::optional<uint32_t> integer = ResourceUtils::ParseInt(attr.value);
   if (integer) {
     return integer;
   }
@@ -293,7 +293,7 @@
   return {};
 }
 
-static Maybe<int> ExtractSdkVersion(const xml::Attribute& attr, std::string* out_error) {
+static std::optional<int> ExtractSdkVersion(const xml::Attribute& attr, std::string* out_error) {
   if (attr.compiled_value != nullptr) {
     const BinaryPrimitive* compiled_prim = ValueCast<BinaryPrimitive>(attr.compiled_value.get());
     if (compiled_prim != nullptr) {
@@ -307,7 +307,7 @@
 
     const String* compiled_str = ValueCast<String>(attr.compiled_value.get());
     if (compiled_str != nullptr) {
-      Maybe<int> sdk_version = ResourceUtils::ParseSdkVersion(*compiled_str->value);
+      std::optional<int> sdk_version = ResourceUtils::ParseSdkVersion(*compiled_str->value);
       if (sdk_version) {
         return sdk_version;
       }
@@ -320,7 +320,7 @@
   }
 
   // Fallback to the plain text value if there is one.
-  Maybe<int> sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
+  std::optional<int> sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
   if (sdk_version) {
     return sdk_version;
   }
@@ -330,8 +330,8 @@
   return {};
 }
 
-Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
-                                                IDiagnostics* diag) {
+std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
+                                                        IDiagnostics* diag) {
   // Make sure the first element is <manifest> with package attribute.
   const xml::Element* manifest_el = xml_res.root.get();
   if (manifest_el == nullptr) {
@@ -352,7 +352,7 @@
   }
 
   std::string error_msg;
-  Maybe<std::string> maybe_package = ExtractCompiledString(*package_attr, &error_msg);
+  std::optional<std::string> maybe_package = ExtractCompiledString(*package_attr, &error_msg);
   if (!maybe_package) {
     diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
                 << "invalid package name: " << error_msg);
@@ -362,7 +362,7 @@
 
   if (const xml::Attribute* version_code_attr =
           manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCode")) {
-    Maybe<uint32_t> maybe_code = ExtractCompiledInt(*version_code_attr, &error_msg);
+    std::optional<uint32_t> maybe_code = ExtractCompiledInt(*version_code_attr, &error_msg);
     if (!maybe_code) {
       diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
                   << "invalid android:versionCode: " << error_msg);
@@ -373,7 +373,7 @@
 
   if (const xml::Attribute* version_code_major_attr =
       manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
-    Maybe<uint32_t> maybe_code = ExtractCompiledInt(*version_code_major_attr, &error_msg);
+    std::optional<uint32_t> maybe_code = ExtractCompiledInt(*version_code_major_attr, &error_msg);
     if (!maybe_code) {
       diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
                       << "invalid android:versionCodeMajor: " << error_msg);
@@ -384,7 +384,7 @@
 
   if (const xml::Attribute* revision_code_attr =
           manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
-    Maybe<uint32_t> maybe_code = ExtractCompiledInt(*revision_code_attr, &error_msg);
+    std::optional<uint32_t> maybe_code = ExtractCompiledInt(*revision_code_attr, &error_msg);
     if (!maybe_code) {
       diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
                   << "invalid android:revisionCode: " << error_msg);
@@ -394,7 +394,8 @@
   }
 
   if (const xml::Attribute* split_name_attr = manifest_el->FindAttribute({}, "split")) {
-    Maybe<std::string> maybe_split_name = ExtractCompiledString(*split_name_attr, &error_msg);
+    std::optional<std::string> maybe_split_name =
+        ExtractCompiledString(*split_name_attr, &error_msg);
     if (!maybe_split_name) {
       diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
                   << "invalid split name: " << error_msg);
@@ -406,7 +407,7 @@
   if (const xml::Element* uses_sdk_el = manifest_el->FindChild({}, "uses-sdk")) {
     if (const xml::Attribute* min_sdk =
             uses_sdk_el->FindAttribute(xml::kSchemaAndroid, "minSdkVersion")) {
-      Maybe<int> maybe_sdk = ExtractSdkVersion(*min_sdk, &error_msg);
+      std::optional<int> maybe_sdk = ExtractSdkVersion(*min_sdk, &error_msg);
       if (!maybe_sdk) {
         diag->Error(DiagMessage(xml_res.file.source.WithLine(uses_sdk_el->line_number))
                     << "invalid android:minSdkVersion: " << error_msg);
diff --git a/tools/aapt2/cmd/Util.h b/tools/aapt2/cmd/Util.h
index 2a7c62e..1b98eb4 100644
--- a/tools/aapt2/cmd/Util.h
+++ b/tools/aapt2/cmd/Util.h
@@ -26,14 +26,14 @@
 #include "SdkConstants.h"
 #include "filter/ConfigFilter.h"
 #include "split/TableSplitter.h"
-#include "util/Maybe.h"
 #include "xml/XmlDom.h"
 
 namespace aapt {
 
 // Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
 // Returns Nothing and logs a human friendly error message if the string was not legal.
-Maybe<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg, IDiagnostics* diag);
+std::optional<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg,
+                                                    IDiagnostics* diag);
 
 // Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in
 // `out_path` with the path and `out_split` with the set of ConfigDescriptions.
@@ -59,8 +59,8 @@
                                                         const SplitConstraints& constraints);
 
 // Extracts relevant info from the AndroidManifest.xml.
-Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
-                                                IDiagnostics* diag);
+std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
+                                                        IDiagnostics* diag);
 
 // Returns a copy of 'name' which conforms to the regex '[a-zA-Z]+[a-zA-Z0-9_]*' by
 // replacing nonconforming characters with underscores.
diff --git a/tools/aapt2/compile/IdAssigner_test.cpp b/tools/aapt2/compile/IdAssigner_test.cpp
index 6637766..d357571 100644
--- a/tools/aapt2/compile/IdAssigner_test.cpp
+++ b/tools/aapt2/compile/IdAssigner_test.cpp
@@ -57,18 +57,18 @@
   ASSERT_TRUE(assigner.Consume(context.get(), table.get()));
   ASSERT_TRUE(VerifyIds(table.get()));
 
-  Maybe<ResourceTable::SearchResult> maybe_result;
+  std::optional<ResourceTable::SearchResult> maybe_result;
 
   // Expect to fill in the gaps between 0x0101XXXX and 0x0104XXXX.
 
   maybe_result = table->FindResource(test::ParseNameOrDie("android:dimen/two"));
   ASSERT_TRUE(maybe_result);
-  EXPECT_EQ(make_value<ResourceId>(0x01020000), maybe_result.value().entry->id);
+  EXPECT_EQ(0x01020000, maybe_result.value().entry->id);
 
   maybe_result =
       table->FindResource(test::ParseNameOrDie("android:integer/three"));
   ASSERT_TRUE(maybe_result);
-  EXPECT_EQ(make_value<ResourceId>(0x01030000), maybe_result.value().entry->id);
+  EXPECT_EQ(0x01030000, maybe_result.value().entry->id);
 
   // Expect to bypass the reserved 0x0104XXXX IDs and use the next 0x0105XXXX
   // IDs.
@@ -76,17 +76,17 @@
   maybe_result =
       table->FindResource(test::ParseNameOrDie("android:string/five"));
   ASSERT_TRUE(maybe_result);
-  EXPECT_EQ(make_value<ResourceId>(0x01050000), maybe_result.value().entry->id);
+  EXPECT_EQ(0x01050000, maybe_result.value().entry->id);
 
   // Expect to fill in the gaps between 0x01040000 and 0x01040006.
 
   maybe_result = table->FindResource(test::ParseNameOrDie("android:attr/bar"));
   ASSERT_TRUE(maybe_result);
-  EXPECT_EQ(make_value<ResourceId>(0x01040001), maybe_result.value().entry->id);
+  EXPECT_EQ(0x01040001, maybe_result.value().entry->id);
 
   maybe_result = table->FindResource(test::ParseNameOrDie("android:attr/baz"));
   ASSERT_TRUE(maybe_result);
-  EXPECT_EQ(make_value<ResourceId>(0x01040002), maybe_result.value().entry->id);
+  EXPECT_EQ(0x01040002, maybe_result.value().entry->id);
 }
 
 TEST_F(IdAssignerTests, FailWhenNonUniqueIdsAssigned) {
@@ -143,7 +143,7 @@
   ASSERT_TRUE(result);
 
   const ResourceTable::SearchResult& search_result = result.value();
-  EXPECT_EQ(make_value<ResourceId>(0x01010002), search_result.entry->id);
+  EXPECT_EQ(0x01010002, search_result.entry->id);
 }
 
 TEST_F(IdAssignerTests, UseAllEntryIds) {
diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp
index 79b0933..de1c3bb 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp
@@ -56,7 +56,7 @@
       return;
     }
 
-    Maybe<Reference> ref = ResourceUtils::ParseXmlAttributeName(attr->value);
+    std::optional<Reference> ref = ResourceUtils::ParseXmlAttributeName(attr->value);
     if (!ref) {
       context_->GetDiagnostics()->Error(DiagMessage(src) << "invalid XML attribute '" << attr->value
                                                          << "'");
@@ -65,7 +65,7 @@
     }
 
     const ResourceName& name = ref.value().name.value();
-    Maybe<xml::ExtractedPackage> maybe_pkg = TransformPackageAlias(name.package);
+    std::optional<xml::ExtractedPackage> maybe_pkg = TransformPackageAlias(name.package);
     if (!maybe_pkg) {
       context_->GetDiagnostics()->Error(DiagMessage(src)
                                         << "invalid namespace prefix '" << name.package << "'");
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.cpp b/tools/aapt2/compile/PseudolocaleGenerator.cpp
index 3f574ee..2461438 100644
--- a/tools/aapt2/compile/PseudolocaleGenerator.cpp
+++ b/tools/aapt2/compile/PseudolocaleGenerator.cpp
@@ -33,7 +33,7 @@
 // The struct that represents both Span objects and UntranslatableSections.
 struct UnifiedSpan {
   // Only present for Span objects. If not present, this was an UntranslatableSection.
-  Maybe<std::string> tag;
+  std::optional<std::string> tag;
 
   // The UTF-16 index into the string where this span starts.
   uint32_t first_char;
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index dd06b38..e7a4585 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -34,7 +34,6 @@
 #include "io/FileSystem.h"
 #include "io/StringStream.h"
 #include "util/Files.h"
-#include "util/Maybe.h"
 #include "util/Util.h"
 #include "xml/XmlActionExecutor.h"
 #include "xml/XmlDom.h"
@@ -113,7 +112,7 @@
 }
 
 /** Returns the value of the version-code-order attribute for a given element. */
-Maybe<int32_t> GetVersionCodeOrder(const Element* element, IDiagnostics* diag) {
+std::optional<int32_t> GetVersionCodeOrder(const Element* element, IDiagnostics* diag) {
   const xml::Attribute* version = element->FindAttribute("", "version-code-order");
   if (version == nullptr) {
     std::string label = GetLabel(element, diag);
@@ -135,7 +134,7 @@
 
 /** Copies the values referenced in a configuration group to the target list. */
 template <typename T>
-bool CopyXmlReferences(const Maybe<std::string>& name, const Group<T>& groups,
+bool CopyXmlReferences(const std::optional<std::string>& name, const Group<T>& groups,
                        std::vector<T>* target) {
   // If there was no item configured, there is nothing to do and no error.
   if (!name) {
@@ -159,7 +158,7 @@
  * success, or false if the either the placeholder is not found in the name, or the value is not
  * present and the placeholder was.
  */
-bool ReplacePlaceholder(const StringPiece& placeholder, const Maybe<StringPiece>& value,
+bool ReplacePlaceholder(const StringPiece& placeholder, const std::optional<StringPiece>& value,
                         std::string* name, IDiagnostics* diag) {
   size_t offset = name->find(placeholder.data());
   bool found = (offset != std::string::npos);
@@ -207,17 +206,17 @@
 }
 
 /** Converts a ConfiguredArtifact into an OutputArtifact. */
-Maybe<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact,
-                                       const std::string& apk_name,
-                                       const PostProcessingConfiguration& config,
-                                       IDiagnostics* diag) {
+std::optional<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact,
+                                               const std::string& apk_name,
+                                               const PostProcessingConfiguration& config,
+                                               IDiagnostics* diag) {
   if (!artifact.name && !config.artifact_format) {
     diag->Error(
         DiagMessage() << "Artifact does not have a name and no global name template defined");
     return {};
   }
 
-  Maybe<std::string> artifact_name =
+  std::optional<std::string> artifact_name =
       (artifact.name) ? artifact.Name(apk_name, diag)
                       : artifact.ToArtifactName(config.artifact_format.value(), apk_name, diag);
 
@@ -287,9 +286,9 @@
 namespace configuration {
 
 /** Returns the binary reprasentation of the XML configuration. */
-Maybe<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
-                                                        const std::string& config_path,
-                                                        IDiagnostics* diag) {
+std::optional<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
+                                                                const std::string& config_path,
+                                                                IDiagnostics* diag) {
   StringInputStream in(contents);
   std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, diag, Source(config_path));
   if (!doc) {
@@ -351,7 +350,8 @@
 /**
  * Returns the common artifact base name from a template string.
  */
-Maybe<std::string> ToBaseName(std::string result, const StringPiece& apk_name, IDiagnostics* diag) {
+std::optional<std::string> ToBaseName(std::string result, const StringPiece& apk_name,
+                                      IDiagnostics* diag) {
   const StringPiece ext = file::GetExtension(apk_name);
   size_t end_index = apk_name.to_string().rfind(ext.to_string());
   const std::string base_name =
@@ -359,8 +359,8 @@
 
   // Base name is optional.
   if (result.find("${basename}") != std::string::npos) {
-    Maybe<StringPiece> maybe_base_name =
-        base_name.empty() ? Maybe<StringPiece>{} : Maybe<StringPiece>{base_name};
+    auto maybe_base_name = base_name.empty() ? std::nullopt
+                                             : std::optional<StringPiece>{base_name};
     if (!ReplacePlaceholder("${basename}", maybe_base_name, &result, diag)) {
       return {};
     }
@@ -383,10 +383,10 @@
   return result;
 }
 
-Maybe<std::string> ConfiguredArtifact::ToArtifactName(const StringPiece& format,
-                                                      const StringPiece& apk_name,
-                                                      IDiagnostics* diag) const {
-  Maybe<std::string> base = ToBaseName(format.to_string(), apk_name, diag);
+std::optional<std::string> ConfiguredArtifact::ToArtifactName(const StringPiece& format,
+                                                              const StringPiece& apk_name,
+                                                              IDiagnostics* diag) const {
+  std::optional<std::string> base = ToBaseName(format.to_string(), apk_name, diag);
   if (!base) {
     return {};
   }
@@ -419,7 +419,8 @@
   return result;
 }
 
-Maybe<std::string> ConfiguredArtifact::Name(const StringPiece& apk_name, IDiagnostics* diag) const {
+std::optional<std::string> ConfiguredArtifact::Name(const StringPiece& apk_name,
+                                                    IDiagnostics* diag) const {
   if (!name) {
     return {};
   }
@@ -430,7 +431,7 @@
 }  // namespace configuration
 
 /** Returns a ConfigurationParser for the file located at the provided path. */
-Maybe<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path) {
+std::optional<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path) {
   std::string contents;
   if (!ReadFileToString(path, &contents, true)) {
     return {};
@@ -442,9 +443,9 @@
     : contents_(std::move(contents)), config_path_(config_path), diag_(&noop_) {
 }
 
-Maybe<std::vector<OutputArtifact>> ConfigurationParser::Parse(
+std::optional<std::vector<OutputArtifact>> ConfigurationParser::Parse(
     const android::StringPiece& apk_path) {
-  Maybe<PostProcessingConfiguration> maybe_config =
+  std::optional<PostProcessingConfiguration> maybe_config =
       ExtractConfiguration(contents_, config_path_, diag_);
   if (!maybe_config) {
     return {};
@@ -460,7 +461,8 @@
   int version = 1;
 
   for (const ConfiguredArtifact& artifact : config.artifacts) {
-    Maybe<OutputArtifact> output_artifact = ToOutputArtifact(artifact, apk_name, config, diag_);
+    std::optional<OutputArtifact> output_artifact =
+        ToOutputArtifact(artifact, apk_name, config, diag_);
     if (!output_artifact) {
       // Defer return an error condition so that all errors are reported.
       valid = false;
@@ -538,7 +540,7 @@
 
   bool valid = true;
   OrderedEntry<Abi>& entry = config->abi_groups[label];
-  Maybe<int32_t> order = GetVersionCodeOrder(root_element, diag);
+  std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag);
   if (!order) {
     valid = false;
   } else {
@@ -589,7 +591,7 @@
 
   bool valid = true;
   OrderedEntry<ConfigDescription>& entry = config->screen_density_groups[label];
-  Maybe<int32_t> order = GetVersionCodeOrder(root_element, diag);
+  std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag);
   if (!order) {
     valid = false;
   } else {
@@ -656,7 +658,7 @@
 
   bool valid = true;
   OrderedEntry<ConfigDescription>& entry = config->locale_groups[label];
-  Maybe<int32_t> order = GetVersionCodeOrder(root_element, diag);
+  std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag);
   if (!order) {
     valid = false;
   } else {
@@ -724,19 +726,19 @@
       entry.label = attr.value;
       valid_attr = true;
     } else if (attr.name == "minSdkVersion") {
-      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
+      std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value);
       if (version) {
         valid_attr = true;
         entry.min_sdk_version = version.value();
       }
     } else if (attr.name == "targetSdkVersion") {
-      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
+      std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value);
       if (version) {
         valid_attr = true;
         entry.target_sdk_version = version;
       }
     } else if (attr.name == "maxSdkVersion") {
-      Maybe<int> version = ResourceUtils::ParseSdkVersion(attr.value);
+      std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value);
       if (version) {
         valid_attr = true;
         entry.max_sdk_version = version;
@@ -778,7 +780,7 @@
 
   bool valid = true;
   OrderedEntry<GlTexture>& entry = config->gl_texture_groups[label];
-  Maybe<int32_t> order = GetVersionCodeOrder(root_element, diag);
+  std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag);
   if (!order) {
     valid = false;
   } else {
@@ -828,7 +830,7 @@
 
   bool valid = true;
   OrderedEntry<DeviceFeature>& entry = config->device_feature_groups[label];
-  Maybe<int32_t> order = GetVersionCodeOrder(root_element, diag);
+  std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag);
   if (!order) {
     valid = false;
   } else {
diff --git a/tools/aapt2/configuration/ConfigurationParser.h b/tools/aapt2/configuration/ConfigurationParser.h
index b9e3be9..195b4ba 100644
--- a/tools/aapt2/configuration/ConfigurationParser.h
+++ b/tools/aapt2/configuration/ConfigurationParser.h
@@ -17,6 +17,7 @@
 #ifndef AAPT2_CONFIGURATION_H
 #define AAPT2_CONFIGURATION_H
 
+#include <optional>
 #include <set>
 #include <string>
 #include <unordered_map>
@@ -25,7 +26,6 @@
 #include "androidfw/ConfigDescription.h"
 
 #include "Diagnostics.h"
-#include "util/Maybe.h"
 
 namespace aapt {
 
@@ -55,9 +55,9 @@
  */
 struct Locale {
   /** The ISO<?> standard locale language code. */
-  Maybe<std::string> lang;
+  std::optional<std::string> lang;
   /** The ISO<?> standard locale region code. */
-  Maybe<std::string> region;
+  std::optional<std::string> region;
 
   inline friend bool operator==(const Locale& lhs, const Locale& rhs) {
     return lhs.lang == rhs.lang && lhs.region == rhs.region;
@@ -74,9 +74,9 @@
 struct AndroidSdk {
   std::string label;
   int min_sdk_version;  // min_sdk_version is mandatory if splitting by SDK.
-  Maybe<int> target_sdk_version;
-  Maybe<int> max_sdk_version;
-  Maybe<AndroidManifest> manifest;
+  std::optional<int> target_sdk_version;
+  std::optional<int> max_sdk_version;
+  std::optional<AndroidManifest> manifest;
 
   static AndroidSdk ForMinSdk(int min_sdk) {
     AndroidSdk sdk;
@@ -112,7 +112,7 @@
   std::vector<Abi> abis;
   std::vector<android::ConfigDescription> screen_densities;
   std::vector<android::ConfigDescription> locales;
-  Maybe<AndroidSdk> android_sdk;
+  std::optional<AndroidSdk> android_sdk;
   std::vector<DeviceFeature> features;
   std::vector<GlTexture> textures;
 
@@ -136,7 +136,7 @@
  public:
 
   /** Returns a ConfigurationParser for the file located at the provided path. */
-  static Maybe<ConfigurationParser> ForPath(const std::string& path);
+  static std::optional<ConfigurationParser> ForPath(const std::string& path);
 
   /** Returns a ConfigurationParser for the configuration in the provided file contents. */
   static ConfigurationParser ForContents(const std::string& contents, const std::string& path) {
@@ -154,7 +154,8 @@
    * Parses the configuration file and returns the results. If the configuration could not be parsed
    * the result is empty and any errors will be displayed with the provided diagnostics context.
    */
-  Maybe<std::vector<configuration::OutputArtifact>> Parse(const android::StringPiece& apk_path);
+  std::optional<std::vector<configuration::OutputArtifact>> Parse(
+      const android::StringPiece& apk_path);
 
  protected:
   /**
diff --git a/tools/aapt2/configuration/ConfigurationParser.internal.h b/tools/aapt2/configuration/ConfigurationParser.internal.h
index c541688..42ef5159 100644
--- a/tools/aapt2/configuration/ConfigurationParser.internal.h
+++ b/tools/aapt2/configuration/ConfigurationParser.internal.h
@@ -84,8 +84,8 @@
    * have not been able to determine the sort order with the previous comparisons.
    */
   template <typename T>
-  ComparisonChain& Add(const Group<T>& groups, const Maybe<std::string>& lhs,
-                       const Maybe<std::string>& rhs) {
+  ComparisonChain& Add(const Group<T>& groups, const std::optional<std::string>& lhs,
+                       const std::optional<std::string>& rhs) {
     return Add(GetGroupOrder(groups, lhs), GetGroupOrder(groups, rhs));
   }
 
@@ -108,7 +108,7 @@
 
  private:
   template <typename T>
-  inline size_t GetGroupOrder(const Entry<T>& groups, const Maybe<std::string>& label) {
+  inline size_t GetGroupOrder(const Entry<T>& groups, const std::optional<std::string>& label) {
     if (!label) {
       return std::numeric_limits<size_t>::max();
     }
@@ -122,32 +122,33 @@
 /** Output artifact configuration options. */
 struct ConfiguredArtifact {
   /** Name to use for output of processing foo.apk -> foo.<name>.apk. */
-  Maybe<std::string> name;
+  std::optional<std::string> name;
   /** If present, uses the ABI group with this name. */
-  Maybe<std::string> abi_group;
+  std::optional<std::string> abi_group;
   /** If present, uses the screen density group with this name. */
-  Maybe<std::string> screen_density_group;
+  std::optional<std::string> screen_density_group;
   /** If present, uses the locale group with this name. */
-  Maybe<std::string> locale_group;
+  std::optional<std::string> locale_group;
   /** If present, uses the Android SDK with this name. */
-  Maybe<std::string> android_sdk;
+  std::optional<std::string> android_sdk;
   /** If present, uses the device feature group with this name. */
-  Maybe<std::string> device_feature_group;
+  std::optional<std::string> device_feature_group;
   /** If present, uses the OpenGL texture group with this name. */
-  Maybe<std::string> gl_texture_group;
+  std::optional<std::string> gl_texture_group;
 
   /** Convert an artifact name template into a name string based on configuration contents. */
-  Maybe<std::string> ToArtifactName(const android::StringPiece& format,
-                                    const android::StringPiece& apk_name, IDiagnostics* diag) const;
+  std::optional<std::string> ToArtifactName(const android::StringPiece& format,
+                                            const android::StringPiece& apk_name,
+                                            IDiagnostics* diag) const;
 
   /** Convert an artifact name template into a name string based on configuration contents. */
-  Maybe<std::string> Name(const android::StringPiece& apk_name, IDiagnostics* diag) const;
+  std::optional<std::string> Name(const android::StringPiece& apk_name, IDiagnostics* diag) const;
 };
 
 /** AAPT2 XML configuration file binary representation. */
 struct PostProcessingConfiguration {
   std::vector<ConfiguredArtifact> artifacts;
-  Maybe<std::string> artifact_format;
+  std::optional<std::string> artifact_format;
 
   Group<Abi> abi_groups;
   Group<android::ConfigDescription> screen_density_groups;
@@ -212,9 +213,9 @@
 };
 
 /** Parses the provided XML document returning the post processing configuration. */
-Maybe<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
-                                                        const std::string& config_path,
-                                                        IDiagnostics* diag);
+std::optional<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents,
+                                                                const std::string& config_path,
+                                                                IDiagnostics* diag);
 
 namespace handler {
 
diff --git a/tools/aapt2/configuration/ConfigurationParser_test.cpp b/tools/aapt2/configuration/ConfigurationParser_test.cpp
index e5b3107..e5eaccc 100644
--- a/tools/aapt2/configuration/ConfigurationParser_test.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser_test.cpp
@@ -31,11 +31,6 @@
 namespace aapt {
 
 namespace configuration {
-void PrintTo(const AndroidSdk& sdk, std::ostream* os) {
-  *os << "SDK: min=" << sdk.min_sdk_version
-      << ", target=" << sdk.target_sdk_version.value_or_default(-1)
-      << ", max=" << sdk.max_sdk_version.value_or_default(-1);
-}
 
 bool operator==(const ConfiguredArtifact& lhs, const ConfiguredArtifact& rhs) {
   return lhs.name == rhs.name && lhs.abi_group == rhs.abi_group &&
@@ -45,20 +40,6 @@
          lhs.gl_texture_group == rhs.gl_texture_group;
 }
 
-std::ostream& operator<<(std::ostream& out, const Maybe<std::string>& value) {
-  PrintTo(value, &out);
-  return out;
-}
-
-void PrintTo(const ConfiguredArtifact& artifact, std::ostream* os) {
-  *os << "\n{"
-      << "\n  name: " << artifact.name << "\n  sdk: " << artifact.android_sdk
-      << "\n  abi: " << artifact.abi_group << "\n  density: " << artifact.screen_density_group
-      << "\n  locale: " << artifact.locale_group
-      << "\n  features: " << artifact.device_feature_group
-      << "\n  textures: " << artifact.gl_texture_group << "\n}\n";
-}
-
 namespace handler {
 
 namespace {
@@ -186,7 +167,7 @@
 }
 
 TEST_F(ConfigurationParserTest, ExtractConfiguration) {
-  Maybe<PostProcessingConfiguration> maybe_config =
+  std::optional<PostProcessingConfiguration> maybe_config =
       ExtractConfiguration(kValidConfig, "fake.xml", &diag_);
 
   PostProcessingConfiguration config = maybe_config.value();
@@ -928,7 +909,8 @@
 
   EXPECT_FALSE(x86.ToArtifactName("something.${abi${density}}.apk", "", &diag));
 
-  const Maybe<std::string>& name = x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag);
+  const std::optional<std::string>& name =
+      x86.ToArtifactName("something.${abi${abi}}.apk", "", &diag);
   ASSERT_TRUE(name);
   EXPECT_EQ(name.value(), "something.${abix86}.apk");
 }
diff --git a/tools/aapt2/format/Archive.cpp b/tools/aapt2/format/Archive.cpp
index 41f01a0..c20b053 100644
--- a/tools/aapt2/format/Archive.cpp
+++ b/tools/aapt2/format/Archive.cpp
@@ -43,7 +43,7 @@
   bool Open(const StringPiece& out_dir) {
     dir_ = out_dir.to_string();
     file::FileType type = file::GetFileType(dir_);
-    if (type == file::FileType::kNonexistant) {
+    if (type == file::FileType::kNonExistant) {
       error_ = "directory does not exist";
       return false;
     } else if (type != file::FileType::kDirectory) {
diff --git a/tools/aapt2/format/binary/TableFlattener_test.cpp b/tools/aapt2/format/binary/TableFlattener_test.cpp
index 8139d73..cd1c0af 100644
--- a/tools/aapt2/format/binary/TableFlattener_test.cpp
+++ b/tools/aapt2/format/binary/TableFlattener_test.cpp
@@ -123,7 +123,7 @@
       return ::testing::AssertionFailure() << "failed to find resource name";
     }
 
-    Maybe<ResourceName> resName = ResourceUtils::ToResourceName(actual_name);
+    std::optional<ResourceName> resName = ResourceUtils::ToResourceName(actual_name);
     if (!resName) {
       return ::testing::AssertionFailure()
              << "expected name '" << expected_res_name << "' but got '"
@@ -423,7 +423,7 @@
   ResourceTable result;
   ASSERT_TRUE(Flatten(context.get(), {}, table.get(), &result));
 
-  Maybe<ResourceTable::SearchResult> search_result =
+  std::optional<ResourceTable::SearchResult> search_result =
       result.FindResource(test::ParseNameOrDie("lib:id/foo"));
   ASSERT_TRUE(search_result);
   EXPECT_EQ(0x00u, search_result.value().entry->id.value().package_id());
@@ -454,7 +454,7 @@
   ResourceTable result;
   ASSERT_TRUE(Flatten(context.get(), {}, table.get(), &result));
 
-  Maybe<ResourceTable::SearchResult> search_result =
+  std::optional<ResourceTable::SearchResult> search_result =
       result.FindResource(test::ParseNameOrDie("lib:style/Theme"));
   ASSERT_TRUE(search_result);
   EXPECT_EQ(0x00030001u, search_result.value().entry->id.value());
diff --git a/tools/aapt2/format/binary/XmlFlattener.cpp b/tools/aapt2/format/binary/XmlFlattener.cpp
index afbaae4..cdbe882 100644
--- a/tools/aapt2/format/binary/XmlFlattener.cpp
+++ b/tools/aapt2/format/binary/XmlFlattener.cpp
@@ -264,7 +264,7 @@
       }
 
       std::string processed_str;
-      Maybe<StringPiece> compiled_text;
+      std::optional<StringPiece> compiled_text;
       if (xml_attr->compiled_value != nullptr) {
         // Make sure we're not flattening a String. A String can be referencing a string from
         // a different StringPool than we're using here to build the binary XML.
diff --git a/tools/aapt2/format/proto/ProtoSerialize.cpp b/tools/aapt2/format/proto/ProtoSerialize.cpp
index 6042ba8..f3b7f75 100644
--- a/tools/aapt2/format/proto/ProtoSerialize.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize.cpp
@@ -438,7 +438,7 @@
 }
 
 static void SerializeReferenceToPb(const Reference& ref, pb::Reference* pb_ref) {
-  pb_ref->set_id(ref.id.value_or_default(ResourceId(0x0)).id);
+  pb_ref->set_id(ref.id.value_or(ResourceId(0x0)).id);
 
   if (ref.name) {
     pb_ref->set_name(ref.name.value().to_string());
@@ -759,13 +759,13 @@
     pb_attr->set_namespace_uri(attr.namespace_uri);
     pb_attr->set_value(attr.value);
     if (attr.compiled_attribute) {
-      const ResourceId attr_id = attr.compiled_attribute.value().id.value_or_default({});
+      const ResourceId attr_id = attr.compiled_attribute.value().id.value_or(ResourceId{});
       pb_attr->set_resource_id(attr_id.id);
     }
     if (attr.compiled_value != nullptr) {
       SerializeItemToPb(*attr.compiled_value, pb_attr->mutable_compiled_item());
       pb::SourcePosition* pb_src = pb_attr->mutable_source();
-      pb_src->set_line_number(attr.compiled_value->GetSource().line.value_or_default(0));
+      pb_src->set_line_number(attr.compiled_value->GetSource().line.value_or(0));
     }
   }
 
diff --git a/tools/aapt2/format/proto/ProtoSerialize_test.cpp b/tools/aapt2/format/proto/ProtoSerialize_test.cpp
index 38c811f..d1d72e0 100644
--- a/tools/aapt2/format/proto/ProtoSerialize_test.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize_test.cpp
@@ -189,7 +189,7 @@
   ASSERT_THAT(new_id, NotNull());
   EXPECT_THAT(new_id->IsWeak(), Eq(id->IsWeak()));
 
-  Maybe<ResourceTable::SearchResult> result =
+  std::optional<ResourceTable::SearchResult> result =
       new_table.FindResource(test::ParseNameOrDie("com.app.a:layout/main"));
   ASSERT_TRUE(result);
 
@@ -234,7 +234,7 @@
   EXPECT_THAT(actual_styled_str->value->spans[0].first_char, Eq(0u));
   EXPECT_THAT(actual_styled_str->value->spans[0].last_char, Eq(4u));
 
-  Maybe<ResourceTable::SearchResult> search_result =
+  std::optional<ResourceTable::SearchResult> search_result =
       new_table.FindResource(test::ParseNameOrDie("com.app.a:integer/overlayable"));
   ASSERT_TRUE(search_result);
   ASSERT_THAT(search_result.value().entry, NotNull());
@@ -637,7 +637,7 @@
   ASSERT_TRUE(DeserializeTableFromPb(pb_table, &files, &new_table, &error));
   EXPECT_THAT(error, IsEmpty());
 
-  Maybe<ResourceTable::SearchResult> search_result =
+  std::optional<ResourceTable::SearchResult> search_result =
       new_table.FindResource(test::ParseNameOrDie("com.app.a:bool/foo"));
   ASSERT_TRUE(search_result);
   ASSERT_TRUE(search_result.value().entry->overlayable_item);
diff --git a/tools/aapt2/io/FileSystem.cpp b/tools/aapt2/io/FileSystem.cpp
index e15f935..fc2e45e 100644
--- a/tools/aapt2/io/FileSystem.cpp
+++ b/tools/aapt2/io/FileSystem.cpp
@@ -21,11 +21,10 @@
 #include "android-base/errors.h"
 #include "androidfw/StringPiece.h"
 #include "utils/FileMap.h"
-
 #include "Source.h"
 #include "io/FileStream.h"
 #include "util/Files.h"
-#include "util/Maybe.h"
+
 #include "util/Util.h"
 
 using ::android::StringPiece;
@@ -38,7 +37,7 @@
 
 std::unique_ptr<IData> RegularFile::OpenAsData() {
   android::FileMap map;
-  if (Maybe<android::FileMap> map = file::MmapPath(source_.path, nullptr)) {
+  if (std::optional<android::FileMap> map = file::MmapPath(source_.path, nullptr)) {
     if (map.value().getDataPtr() && map.value().getDataLength() > 0) {
       return util::make_unique<MmappedData>(std::move(map.value()));
     }
diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp
index de6524d..3b3c6e1 100644
--- a/tools/aapt2/java/JavaClassGenerator.cpp
+++ b/tools/aapt2/java/JavaClassGenerator.cpp
@@ -204,7 +204,7 @@
 }
 
 // Whether or not to skip writing this symbol.
-bool JavaClassGenerator::SkipSymbol(const Maybe<SymbolTable::Symbol>& symbol) {
+bool JavaClassGenerator::SkipSymbol(const std::optional<SymbolTable::Symbol>& symbol) {
   return !symbol || (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic &&
                      !symbol.value().is_public);
 }
@@ -212,12 +212,12 @@
 struct StyleableAttr {
   const Reference* attr_ref = nullptr;
   std::string field_name;
-  Maybe<SymbolTable::Symbol> symbol;
+  std::optional<SymbolTable::Symbol> symbol;
 };
 
 static bool operator<(const StyleableAttr& lhs, const StyleableAttr& rhs) {
-  const ResourceId lhs_id = lhs.attr_ref->id.value_or_default(ResourceId(0));
-  const ResourceId rhs_id = rhs.attr_ref->id.value_or_default(ResourceId(0));
+  const ResourceId lhs_id = lhs.attr_ref->id.value_or(ResourceId(0));
+  const ResourceId rhs_id = rhs.attr_ref->id.value_or(ResourceId(0));
   if (lhs_id == rhs_id) {
     return lhs.attr_ref->name.value() < rhs.attr_ref->name.value();
   }
@@ -362,7 +362,7 @@
       array_def->AddElement(field_name);
       r_txt_contents = field_name.ref;
     } else {
-      const ResourceId attr_id = attr.attr_ref->id.value_or_default(ResourceId(0));
+      const ResourceId attr_id = attr.attr_ref->id.value_or(ResourceId(0));
       array_def->AddElement(attr_id);
       r_txt_contents = to_string(attr_id);
     }
@@ -504,9 +504,9 @@
   }
 }
 
-Maybe<std::string> JavaClassGenerator::UnmangleResource(const StringPiece& package_name,
-                                                        const StringPiece& package_name_to_generate,
-                                                        const ResourceEntry& entry) {
+std::optional<std::string> JavaClassGenerator::UnmangleResource(
+    const StringPiece& package_name, const StringPiece& package_name_to_generate,
+    const ResourceEntry& entry) {
   if (SkipSymbol(entry.visibility.level)) {
     return {};
   }
@@ -535,7 +535,7 @@
                                      MethodDefinition* out_rewrite_method_def,
                                      Printer* r_txt_printer) {
   for (const auto& entry : type.entries) {
-    const Maybe<std::string> unmangled_name =
+    const std::optional<std::string> unmangled_name =
         UnmangleResource(package.name, package_name_to_generate, *entry);
     if (!unmangled_name) {
       continue;
diff --git a/tools/aapt2/java/JavaClassGenerator.h b/tools/aapt2/java/JavaClassGenerator.h
index d9d1b39..b45a2f1 100644
--- a/tools/aapt2/java/JavaClassGenerator.h
+++ b/tools/aapt2/java/JavaClassGenerator.h
@@ -46,7 +46,7 @@
 
   // If set, generates code to rewrite the package ID of resources.
   // Implies use_final == true. Default is unset.
-  Maybe<OnResourcesLoadedCallbackOptions> rewrite_callback_options;
+  std::optional<OnResourcesLoadedCallbackOptions> rewrite_callback_options;
 
   enum class SymbolTypes {
     kAll,
@@ -83,13 +83,13 @@
 
  private:
   bool SkipSymbol(Visibility::Level state);
-  bool SkipSymbol(const Maybe<SymbolTable::Symbol>& symbol);
+  bool SkipSymbol(const std::optional<SymbolTable::Symbol>& symbol);
 
   // Returns the unmangled resource entry name if the unmangled package is the same as
   // package_name_to_generate. Returns nothing if the resource should be skipped.
-  Maybe<std::string> UnmangleResource(const android::StringPiece& package_name,
-                                      const android::StringPiece& package_name_to_generate,
-                                      const ResourceEntry& entry);
+  std::optional<std::string> UnmangleResource(const android::StringPiece& package_name,
+                                              const android::StringPiece& package_name_to_generate,
+                                              const ResourceEntry& entry);
 
   bool ProcessType(const android::StringPiece& package_name_to_generate,
                    const ResourceTablePackage& package, const ResourceTableType& type,
diff --git a/tools/aapt2/java/ManifestClassGenerator.cpp b/tools/aapt2/java/ManifestClassGenerator.cpp
index 09ea03b..a0db41b 100644
--- a/tools/aapt2/java/ManifestClassGenerator.cpp
+++ b/tools/aapt2/java/ManifestClassGenerator.cpp
@@ -19,19 +19,17 @@
 #include <algorithm>
 
 #include "Source.h"
-#include "java/AnnotationProcessor.h"
 #include "java/ClassDefinition.h"
 #include "java/JavaClassGenerator.h"
 #include "text/Unicode.h"
-#include "util/Maybe.h"
 #include "xml/XmlDom.h"
 
 using ::aapt::text::IsJavaIdentifier;
 
 namespace aapt {
 
-static Maybe<std::string> ExtractJavaIdentifier(IDiagnostics* diag, const Source& source,
-                                                const std::string& value) {
+static std::optional<std::string> ExtractJavaIdentifier(IDiagnostics* diag, const Source& source,
+                                                        const std::string& value) {
   std::string result = value;
   size_t pos = value.rfind('.');
   if (pos != std::string::npos) {
@@ -63,7 +61,7 @@
     return false;
   }
 
-  Maybe<std::string> result =
+  std::optional<std::string> result =
       ExtractJavaIdentifier(diag, source.WithLine(el->line_number), attr->value);
   if (!result) {
     return false;
diff --git a/tools/aapt2/java/ProguardRules.cpp b/tools/aapt2/java/ProguardRules.cpp
index d9a4caa..b939f35 100644
--- a/tools/aapt2/java/ProguardRules.cpp
+++ b/tools/aapt2/java/ProguardRules.cpp
@@ -48,7 +48,7 @@
 
   void Visit(xml::Element* node) override {
     if (!node->namespace_uri.empty()) {
-      Maybe<xml::ExtractedPackage> maybe_package =
+      std::optional<xml::ExtractedPackage> maybe_package =
           xml::ExtractPackageFromNamespace(node->namespace_uri);
       if (maybe_package) {
         // This is a custom view, let's figure out the class name from this.
@@ -270,14 +270,16 @@
         get_name = true;
         xml::Attribute* attr = node->FindAttribute(xml::kSchemaAndroid, "backupAgent");
         if (attr) {
-          Maybe<std::string> result = util::GetFullyQualifiedClassName(package_, attr->value);
+          std::optional<std::string> result =
+              util::GetFullyQualifiedClassName(package_, attr->value);
           if (result) {
             AddClass(node->line_number, result.value(), "");
           }
         }
         attr = node->FindAttribute(xml::kSchemaAndroid, "appComponentFactory");
         if (attr) {
-          Maybe<std::string> result = util::GetFullyQualifiedClassName(package_, attr->value);
+          std::optional<std::string> result =
+              util::GetFullyQualifiedClassName(package_, attr->value);
           if (result) {
             AddClass(node->line_number, result.value(), "");
           }
@@ -285,7 +287,8 @@
 
         attr = node->FindAttribute(xml::kSchemaAndroid, "zygotePreloadName");
         if (attr) {
-          Maybe<std::string> result = util::GetFullyQualifiedClassName(package_, attr->value);
+          std::optional<std::string> result =
+              util::GetFullyQualifiedClassName(package_, attr->value);
           if (result) {
             AddClass(node->line_number, result.value(), "");
           }
@@ -317,7 +320,8 @@
         get_name = attr != nullptr;
 
         if (get_name) {
-          Maybe<std::string> result = util::GetFullyQualifiedClassName(package_, attr->value);
+          std::optional<std::string> result =
+              util::GetFullyQualifiedClassName(package_, attr->value);
           if (result) {
             AddClass(node->line_number, result.value(), "");
           }
diff --git a/tools/aapt2/link/AutoVersioner.cpp b/tools/aapt2/link/AutoVersioner.cpp
index 876494e..328ac970 100644
--- a/tools/aapt2/link/AutoVersioner.cpp
+++ b/tools/aapt2/link/AutoVersioner.cpp
@@ -90,7 +90,7 @@
           }
 
           if (Style* style = ValueCast<Style>(config_value->value.get())) {
-            Maybe<ApiVersion> min_sdk_stripped;
+            std::optional<ApiVersion> min_sdk_stripped;
             std::vector<Style::Entry> stripped;
 
             auto iter = style->entries.begin();
diff --git a/tools/aapt2/link/AutoVersioner_test.cpp b/tools/aapt2/link/AutoVersioner_test.cpp
index 02fd00b..8179d46 100644
--- a/tools/aapt2/link/AutoVersioner_test.cpp
+++ b/tools/aapt2/link/AutoVersioner_test.cpp
@@ -87,25 +87,27 @@
   Style* style = test::GetValueForConfig<Style>(table.get(), "app:style/Foo", test::ParseConfigOrDie("v4"));
   ASSERT_THAT(style, NotNull());
   ASSERT_EQ(style->entries.size(), 1u);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/onClick")), style->entries.front().key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/onClick"), style->entries.front().key.name);
 
   style = test::GetValueForConfig<Style>(table.get(), "app:style/Foo", test::ParseConfigOrDie("v13"));
   ASSERT_THAT(style, NotNull());
   ASSERT_EQ(style->entries.size(), 2u);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/onClick")),style->entries[0].key.name);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/requiresSmallestWidthDp")), style->entries[1].key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/onClick"), style->entries[0].key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/requiresSmallestWidthDp"),
+            style->entries[1].key.name);
 
   style = test::GetValueForConfig<Style>(table.get(), "app:style/Foo", test::ParseConfigOrDie("v17"));
   ASSERT_THAT(style, NotNull());
   ASSERT_EQ(style->entries.size(), 3u);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/onClick")), style->entries[0].key.name);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/requiresSmallestWidthDp")), style->entries[1].key.name);
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/paddingStart")), style->entries[2].key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/onClick"), style->entries[0].key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/requiresSmallestWidthDp"),
+            style->entries[1].key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/paddingStart"), style->entries[2].key.name);
 
   style = test::GetValueForConfig<Style>(table.get(), "app:style/Foo", test::ParseConfigOrDie("v21"));
   ASSERT_THAT(style, NotNull());
   ASSERT_EQ(1u, style->entries.size());
-  EXPECT_EQ(make_value(test::ParseNameOrDie("android:attr/paddingEnd")), style->entries.front().key.name);
+  EXPECT_EQ(test::ParseNameOrDie("android:attr/paddingEnd"), style->entries.front().key.name);
 }
 
 }  // namespace aapt
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index 8abd9de..1bb0696 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -52,7 +52,7 @@
   // We allow unqualified class names (ie: .HelloActivity)
   // Since we don't know the package name, we can just make a fake one here and
   // the test will be identical as long as the real package name is valid too.
-  Maybe<std::string> fully_qualified_class_name =
+  std::optional<std::string> fully_qualified_class_name =
       util::GetFullyQualifiedClassName("a", attr->value);
 
   StringPiece qualified_class_name = fully_qualified_class_name
@@ -146,7 +146,7 @@
     // Now inject the android:isFeatureSplit="true" attribute.
     xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, kIsFeatureSplit);
     if (attr != nullptr) {
-      if (!ResourceUtils::ParseBool(attr->value).value_or_default(false)) {
+      if (!ResourceUtils::ParseBool(attr->value).value_or(false)) {
         // The isFeatureSplit attribute is false, which conflicts with the use
         // of "featureSplit".
         diag->Error(DiagMessage(el->line_number)
@@ -523,7 +523,8 @@
                                   const StringPiece& attr_name, xml::Element* el) {
   xml::Attribute* attr = el->FindAttribute(attr_ns, attr_name);
   if (attr != nullptr) {
-    if (Maybe<std::string> new_value = util::GetFullyQualifiedClassName(package, attr->value)) {
+    if (std::optional<std::string> new_value =
+            util::GetFullyQualifiedClassName(package, attr->value)) {
       attr->value = std::move(new_value.value());
     }
   }
diff --git a/tools/aapt2/link/ManifestFixer.h b/tools/aapt2/link/ManifestFixer.h
index 34ad8d5..d5d1d17 100644
--- a/tools/aapt2/link/ManifestFixer.h
+++ b/tools/aapt2/link/ManifestFixer.h
@@ -22,7 +22,7 @@
 #include "android-base/macros.h"
 
 #include "process/IResourceTableConsumer.h"
-#include "util/Maybe.h"
+
 #include "xml/XmlActionExecutor.h"
 #include "xml/XmlDom.h"
 
@@ -30,47 +30,47 @@
 
 struct ManifestFixerOptions {
   // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag.
-  Maybe<std::string> min_sdk_version_default;
+  std::optional<std::string> min_sdk_version_default;
 
   // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag.
-  Maybe<std::string> target_sdk_version_default;
+  std::optional<std::string> target_sdk_version_default;
 
   // The Android package to use instead of the one defined in 'package' in <manifest>.
   // This also renames all relative package/class names in the manifest to fully qualified
   // Java names.
-  Maybe<std::string> rename_manifest_package;
+  std::optional<std::string> rename_manifest_package;
 
   // The Android package to use instead of the one defined in 'android:targetPackage' in
   // <instrumentation>.
-  Maybe<std::string> rename_instrumentation_target_package;
+  std::optional<std::string> rename_instrumentation_target_package;
 
   // The Android package to use instead of the one defined in 'android:targetPackage' in
   // <overlay>.
-  Maybe<std::string> rename_overlay_target_package;
+  std::optional<std::string> rename_overlay_target_package;
 
   // The version name to set if 'android:versionName' is not defined in <manifest> or if
   // replace_version is set.
-  Maybe<std::string> version_name_default;
+  std::optional<std::string> version_name_default;
 
   // The version code to set if 'android:versionCode' is not defined in <manifest> or if
   // replace_version is set.
-  Maybe<std::string> version_code_default;
+  std::optional<std::string> version_code_default;
 
   // The version code to set if 'android:versionCodeMajor' is not defined in <manifest> or if
   // replace_version is set.
-  Maybe<std::string> version_code_major_default;
+  std::optional<std::string> version_code_major_default;
 
   // The revision code to set if 'android:revisionCode' is not defined in <manifest> or if
   // replace_version is set.
-  Maybe<std::string> revision_code_default;
+  std::optional<std::string> revision_code_default;
 
   // The version of the framework being compiled against to set for 'android:compileSdkVersion' in
   // the <manifest> tag.
-  Maybe<std::string> compile_sdk_version;
+  std::optional<std::string> compile_sdk_version;
 
   // The version codename of the framework being compiled against to set for
   // 'android:compileSdkVersionCodename' in the <manifest> tag.
-  Maybe<std::string> compile_sdk_version_codename;
+  std::optional<std::string> compile_sdk_version_codename;
 
   // Whether validation errors should be treated only as warnings. If this is 'true', then an
   // incorrect node will not result in an error, but only as a warning, and the parsing will
diff --git a/tools/aapt2/link/ReferenceLinker.cpp b/tools/aapt2/link/ReferenceLinker.cpp
index 4ac25bd..47c804c 100644
--- a/tools/aapt2/link/ReferenceLinker.cpp
+++ b/tools/aapt2/link/ReferenceLinker.cpp
@@ -190,7 +190,8 @@
  public:
   EmptyDeclStack() = default;
 
-  Maybe<xml::ExtractedPackage> TransformPackageAlias(const StringPiece& alias) const override {
+  std::optional<xml::ExtractedPackage> TransformPackageAlias(
+      const StringPiece& alias) const override {
     if (alias.empty()) {
       return xml::ExtractedPackage{{}, true /*private*/};
     }
@@ -206,7 +207,8 @@
       : alias_namespaces_(std::move(namespaces)) {
   }
 
-  Maybe<xml::ExtractedPackage> TransformPackageAlias(const StringPiece& alias) const override {
+  std::optional<xml::ExtractedPackage> TransformPackageAlias(
+      const StringPiece& alias) const override {
     if (alias.empty()) {
       return xml::ExtractedPackage{{}, true /*private*/};
     }
@@ -322,11 +324,11 @@
   return symbol;
 }
 
-Maybe<xml::AaptAttribute> ReferenceLinker::CompileXmlAttribute(const Reference& reference,
-                                                               const CallSite& callsite,
-                                                               IAaptContext* context,
-                                                               SymbolTable* symbols,
-                                                               std::string* out_error) {
+std::optional<xml::AaptAttribute> ReferenceLinker::CompileXmlAttribute(const Reference& reference,
+                                                                       const CallSite& callsite,
+                                                                       IAaptContext* context,
+                                                                       SymbolTable* symbols,
+                                                                       std::string* out_error) {
   const SymbolTable::Symbol* symbol =
       ResolveAttributeCheckVisibility(reference, callsite, context, symbols, out_error);
   if (!symbol) {
diff --git a/tools/aapt2/link/ReferenceLinker.h b/tools/aapt2/link/ReferenceLinker.h
index 770f1e5..b460853 100644
--- a/tools/aapt2/link/ReferenceLinker.h
+++ b/tools/aapt2/link/ReferenceLinker.h
@@ -97,11 +97,11 @@
 
   // Resolves the attribute reference and returns an xml::AaptAttribute if successful.
   // If resolution fails, outError holds the error message.
-  static Maybe<xml::AaptAttribute> CompileXmlAttribute(const Reference& reference,
-                                                       const CallSite& callsite,
-                                                       IAaptContext* context,
-                                                       SymbolTable* symbols,
-                                                       std::string* out_error);
+  static std::optional<xml::AaptAttribute> CompileXmlAttribute(const Reference& reference,
+                                                               const CallSite& callsite,
+                                                               IAaptContext* context,
+                                                               SymbolTable* symbols,
+                                                               std::string* out_error);
 
   // Writes the resource name to the DiagMessage, using the
   // "orig_name (aka <transformed_name>)" syntax.
diff --git a/tools/aapt2/link/ReferenceLinker_test.cpp b/tools/aapt2/link/ReferenceLinker_test.cpp
index 2d8f0d3..97bdd3e 100644
--- a/tools/aapt2/link/ReferenceLinker_test.cpp
+++ b/tools/aapt2/link/ReferenceLinker_test.cpp
@@ -317,12 +317,12 @@
                                                                 CallSite{"com.app.test"},
                                                                 context.get(), &table);
   ASSERT_THAT(s, NotNull());
-  EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010000)));
+  EXPECT_THAT(s->id, Eq(0x7f010000));
 
   s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"), CallSite{"com.app.lib"},
                                      context.get(), &table);
   ASSERT_THAT(s, NotNull());
-  EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010001)));
+  EXPECT_THAT(s->id, Eq(0x7f010001));
 
   EXPECT_THAT(ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"),
                                              CallSite{"com.app.bad"}, context.get(), &table),
@@ -348,7 +348,7 @@
                                                                 CallSite{"com.app.test"},
                                                                 context.get(), &table);
   ASSERT_THAT(s, NotNull());
-  EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x80010000)));
+  EXPECT_THAT(s->id, Eq(0x80010000));
 
   s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"), CallSite{"com.app.lib"},
                                      context.get(), &table);
diff --git a/tools/aapt2/link/TableMerger.cpp b/tools/aapt2/link/TableMerger.cpp
index 22f4d18..d094d36 100644
--- a/tools/aapt2/link/TableMerger.cpp
+++ b/tools/aapt2/link/TableMerger.cpp
@@ -303,8 +303,8 @@
           dst_config_value->value = std::move(new_file_ref);
 
         } else {
-          Maybe<std::string> original_comment = (dst_config_value->value)
-              ? dst_config_value->value->GetComment() : Maybe<std::string>();
+          auto original_comment = (dst_config_value->value)
+              ? dst_config_value->value->GetComment() : std::optional<std::string>();
 
           dst_config_value->value = src_config_value->value->Transform(cloner);
 
diff --git a/tools/aapt2/link/TableMerger_test.cpp b/tools/aapt2/link/TableMerger_test.cpp
index 4358fb5..4cbf2d3 100644
--- a/tools/aapt2/link/TableMerger_test.cpp
+++ b/tools/aapt2/link/TableMerger_test.cpp
@@ -409,8 +409,7 @@
 
   const auto expected = ResourceUtils::MakeBool(true);
   EXPECT_THAT(style->entries, Contains(Field(&Style::Entry::value, Pointee(ValueEq(*expected)))));
-  EXPECT_THAT(style->parent,
-              Eq(make_value(Reference(test::ParseNameOrDie("com.app.a:style/OverlayParent")))));
+  EXPECT_THAT(style->parent, Reference(test::ParseNameOrDie("com.app.a:style/OverlayParent")));
 }
 
 TEST_F(TableMergerTest, OverrideStyleInsteadOfOverlaying) {
@@ -483,7 +482,7 @@
   ASSERT_TRUE(merger.Merge({}, table_b.get(), false /*overlay*/));
 
   const ResourceName name = test::ParseNameOrDie("com.app.a:bool/foo");
-  Maybe<ResourceTable::SearchResult> search_result = final_table.FindResource(name);
+  std::optional<ResourceTable::SearchResult> search_result = final_table.FindResource(name);
   ASSERT_TRUE(search_result);
   ASSERT_TRUE(search_result.value().entry->overlayable_item);
   OverlayableItem& result_overlayable_item = search_result.value().entry->overlayable_item.value();
@@ -517,7 +516,7 @@
   ASSERT_TRUE(merger.Merge({}, table_b.get(), false /*overlay*/));
 
   const ResourceName name = test::ParseNameOrDie("com.app.a:bool/foo");
-  Maybe<ResourceTable::SearchResult> search_result = final_table.FindResource(name);
+  std::optional<ResourceTable::SearchResult> search_result = final_table.FindResource(name);
   ASSERT_TRUE(search_result);
   ASSERT_TRUE(search_result.value().entry->overlayable_item);
   OverlayableItem& result_overlayable_item = search_result.value().entry->overlayable_item.value();
diff --git a/tools/aapt2/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index aaa085e..1f8548b 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -68,7 +68,7 @@
 
       const Attribute* attribute = &default_attribute;
 
-      if (Maybe<xml::ExtractedPackage> maybe_package =
+      if (std::optional<xml::ExtractedPackage> maybe_package =
               xml::ExtractPackageFromNamespace(attr.namespace_uri)) {
         // There is a valid package name for this attribute. We will look this up.
         Reference attr_ref(
diff --git a/tools/aapt2/link/XmlReferenceLinker_test.cpp b/tools/aapt2/link/XmlReferenceLinker_test.cpp
index ddf5b9a..6d96cf1 100644
--- a/tools/aapt2/link/XmlReferenceLinker_test.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker_test.cpp
@@ -100,18 +100,18 @@
   xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "layout_width");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x01010000)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x01010000), xml_attr->compiled_attribute.value().id);
   EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull());
 
   xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "background");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x01010001)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x01010001), xml_attr->compiled_attribute.value().id);
   Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
   ASSERT_THAT(ref, NotNull());
-  EXPECT_EQ(make_value(test::ParseNameOrDie("color/green")), ref->name);  // Make sure the name
-                                                                          // didn't change.
-  EXPECT_EQ(make_value(ResourceId(0x7f020000)), ref->id);
+  EXPECT_EQ(test::ParseNameOrDie("color/green"), ref->name);  // Make sure the name
+                                                              // didn't change.
+  EXPECT_EQ(ResourceId(0x7f020000), ref->id);
 
   xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "text");
   ASSERT_THAT(xml_attr, NotNull());
@@ -172,7 +172,7 @@
       view_el->FindAttribute(xml::BuildPackageNamespace("com.android.support"), "colorAccent");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x7f010001)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x7f010001), xml_attr->compiled_attribute.value().id);
   EXPECT_THAT(ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get()), NotNull());
 }
 
@@ -190,11 +190,11 @@
   xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAuto, "colorAccent");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x7f010000)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x7f010000), xml_attr->compiled_attribute.value().id);
   Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
   ASSERT_THAT(ref, NotNull());
   ASSERT_TRUE(ref->name);
-  EXPECT_EQ(make_value(ResourceId(0x7f020001)), ref->id);
+  EXPECT_EQ(ResourceId(0x7f020001), ref->id);
 }
 
 TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) {
@@ -214,10 +214,10 @@
   xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "attr");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x01010002)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x01010002), xml_attr->compiled_attribute.value().id);
   Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
   ASSERT_THAT(ref, NotNull());
-  EXPECT_EQ(make_value(ResourceId(0x01030000)), ref->id);
+  EXPECT_EQ(ResourceId(0x01030000), ref->id);
 
   ASSERT_FALSE(view_el->GetChildElements().empty());
   view_el = view_el->GetChildElements().front();
@@ -228,10 +228,10 @@
   xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x7f010002), xml_attr->compiled_attribute.value().id);
   ref = ValueCast<Reference>(xml_attr->compiled_value.get());
   ASSERT_THAT(ref, NotNull());
-  EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id);
+  EXPECT_EQ(ResourceId(0x7f030000), ref->id);
 }
 
 TEST_F(XmlReferenceLinkerTest, LinkViewWithLocalPackageAndAliasOfTheSameName) {
@@ -250,10 +250,10 @@
   xml::Attribute* xml_attr = view_el->FindAttribute(xml::BuildPackageNamespace("com.app.test"), "attr");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x7f010002)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x7f010002), xml_attr->compiled_attribute.value().id);
   Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
   ASSERT_THAT(ref, NotNull());
-  EXPECT_EQ(make_value(ResourceId(0x7f030000)), ref->id);
+  EXPECT_EQ(ResourceId(0x7f030000), ref->id);
 }
 
 
@@ -270,7 +270,7 @@
   xml::Attribute* xml_attr = gradient_el->FindAttribute(xml::kSchemaAndroid, "angle");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x01010004)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x01010004), xml_attr->compiled_attribute.value().id);
 
   BinaryPrimitive* value = ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get());
   ASSERT_THAT(value, NotNull());
@@ -292,7 +292,7 @@
   xml::Attribute* xml_attr = gradient_el->FindAttribute(xml::kSchemaAndroid, "angle");
   ASSERT_THAT(xml_attr, NotNull());
   ASSERT_TRUE(xml_attr->compiled_attribute);
-  EXPECT_EQ(make_value(ResourceId(0x01010004)), xml_attr->compiled_attribute.value().id);
+  EXPECT_EQ(ResourceId(0x01010004), xml_attr->compiled_attribute.value().id);
 
   BinaryPrimitive* value = ValueCast<BinaryPrimitive>(xml_attr->compiled_value.get());
   ASSERT_THAT(value, NotNull());
diff --git a/tools/aapt2/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp
index d385267..2d58cbf 100644
--- a/tools/aapt2/process/SymbolTable.cpp
+++ b/tools/aapt2/process/SymbolTable.cpp
@@ -75,8 +75,8 @@
 
   // Fill in the package name if necessary.
   // If there is no package in `name`, we will need to copy the ResourceName
-  // and store it somewhere; we use the Maybe<> class to reserve storage.
-  Maybe<ResourceName> name_with_package_impl;
+  // and store it somewhere; we use the std::optional<> class to reserve storage.
+  std::optional<ResourceName> name_with_package_impl;
   if (name.package.empty()) {
     name_with_package_impl = ResourceName(mangler_->GetTargetPackageName(), name.type, name.entry);
     name_with_package = &name_with_package_impl.value();
@@ -88,9 +88,9 @@
   }
 
   // The name was not found in the cache. Mangle it (if necessary) and find it in our sources.
-  // Again, here we use a Maybe<> object to reserve storage if we need to mangle.
+  // Again, here we use a std::optional<> object to reserve storage if we need to mangle.
   const ResourceName* mangled_name = name_with_package;
-  Maybe<ResourceName> mangled_name_impl;
+  std::optional<ResourceName> mangled_name_impl;
   if (mangler_->ShouldMangle(name_with_package->package)) {
     mangled_name_impl = mangler_->MangleName(*name_with_package);
     mangled_name = &mangled_name_impl.value();
@@ -183,7 +183,7 @@
 
 std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
     const ResourceName& name) {
-  Maybe<ResourceTable::SearchResult> result = table_->FindResource(name);
+  std::optional<ResourceTable::SearchResult> result = table_->FindResource(name);
   if (!result) {
     if (name.type == ResourceType::kAttr) {
       // Recurse and try looking up a private attribute.
@@ -306,7 +306,7 @@
         return nullptr;
       }
 
-      Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
+      std::optional<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
       if (!parsed_name) {
         return nullptr;
       }
@@ -382,8 +382,7 @@
   return {};
 }
 
-static Maybe<ResourceName> GetResourceName(android::AssetManager2& am,
-                                           ResourceId id) {
+static std::optional<ResourceName> GetResourceName(android::AssetManager2& am, ResourceId id) {
   auto name = am.GetResourceName(id.id);
   if (!name.has_value()) {
     return {};
@@ -402,7 +401,7 @@
     return {};
   }
 
-  Maybe<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
+  std::optional<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
   if (!maybe_name) {
     return {};
   }
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index 06eaf63..65ae7be 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -56,7 +56,7 @@
   struct Symbol {
     Symbol() = default;
 
-    explicit Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
+    explicit Symbol(const std::optional<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
                     bool pub = false)
         : id(i), attribute(attr), is_public(pub) {
     }
@@ -66,7 +66,7 @@
     Symbol& operator=(const Symbol&) = default;
     Symbol& operator=(Symbol&&) = default;
 
-    Maybe<ResourceId> id;
+    std::optional<ResourceId> id;
     std::shared_ptr<Attribute> attribute;
     bool is_public = false;
     bool is_dynamic = false;
diff --git a/tools/aapt2/test/Builders.cpp b/tools/aapt2/test/Builders.cpp
index 4816596..23331de 100644
--- a/tools/aapt2/test/Builders.cpp
+++ b/tools/aapt2/test/Builders.cpp
@@ -159,7 +159,8 @@
   return std::move(table_);
 }
 
-std::unique_ptr<Reference> BuildReference(const StringPiece& ref, const Maybe<ResourceId>& id) {
+std::unique_ptr<Reference> BuildReference(const StringPiece& ref,
+                                          const std::optional<ResourceId>& id) {
   std::unique_ptr<Reference> reference = util::make_unique<Reference>(ParseNameOrDie(ref));
   reference->id = id;
   return reference;
@@ -218,7 +219,8 @@
   return std::move(style_);
 }
 
-StyleableBuilder& StyleableBuilder::AddItem(const StringPiece& str, const Maybe<ResourceId>& id) {
+StyleableBuilder& StyleableBuilder::AddItem(const StringPiece& str,
+                                            const std::optional<ResourceId>& id) {
   styleable_->entries.push_back(Reference(ParseNameOrDie(str)));
   styleable_->entries.back().id = id;
   return *this;
diff --git a/tools/aapt2/test/Builders.h b/tools/aapt2/test/Builders.h
index 3ff955d..55778ae 100644
--- a/tools/aapt2/test/Builders.h
+++ b/tools/aapt2/test/Builders.h
@@ -29,7 +29,6 @@
 #include "configuration/ConfigurationParser.internal.h"
 #include "process/IResourceTableConsumer.h"
 #include "test/Common.h"
-#include "util/Maybe.h"
 #include "xml/XmlDom.h"
 
 namespace aapt {
@@ -86,7 +85,7 @@
 };
 
 std::unique_ptr<Reference> BuildReference(const android::StringPiece& ref,
-                                          const Maybe<ResourceId>& id = {});
+                                          const std::optional<ResourceId>& id = {});
 std::unique_ptr<BinaryPrimitive> BuildPrimitive(uint8_t type, uint32_t data);
 
 template <typename T>
@@ -149,7 +148,8 @@
 class StyleableBuilder {
  public:
   StyleableBuilder() = default;
-  StyleableBuilder& AddItem(const android::StringPiece& str, const Maybe<ResourceId>& id = {});
+  StyleableBuilder& AddItem(const android::StringPiece& str,
+                            const std::optional<ResourceId>& id = {});
   std::unique_ptr<Styleable> Build();
 
  private:
diff --git a/tools/aapt2/test/Common.cpp b/tools/aapt2/test/Common.cpp
index 23c2218..e029d02 100644
--- a/tools/aapt2/test/Common.cpp
+++ b/tools/aapt2/test/Common.cpp
@@ -48,7 +48,7 @@
                                           const android::StringPiece& res_name,
                                           const ConfigDescription& config,
                                           const android::StringPiece& product) {
-  Maybe<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
+  std::optional<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
   if (result) {
     ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
     if (config_value) {
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index 777ca5c..7006964 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -55,7 +55,7 @@
 T* GetValueForConfigAndProduct(ResourceTable* table, const android::StringPiece& res_name,
                                const android::ConfigDescription& config,
                                const android::StringPiece& product) {
-  Maybe<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
+  std::optional<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
   if (result) {
     ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
     if (config_value) {
@@ -130,7 +130,7 @@
 
 // Add a print method to Maybe.
 template <typename T>
-void PrintTo(const Maybe<T>& value, std::ostream* out) {
+void PrintTo(const std::optional<T>& value, std::ostream* out) {
   if (value) {
     *out << ::testing::PrintToString(value.value());
   } else {
diff --git a/tools/aapt2/test/Context.h b/tools/aapt2/test/Context.h
index 5d8ded3..e1b8dd5 100644
--- a/tools/aapt2/test/Context.h
+++ b/tools/aapt2/test/Context.h
@@ -95,8 +95,8 @@
   friend class ContextBuilder;
 
   PackageType package_type_ = PackageType::kApp;
-  Maybe<std::string> compilation_package_;
-  Maybe<uint8_t> package_id_;
+  std::optional<std::string> compilation_package_;
+  std::optional<uint8_t> package_id_;
   StdErrDiagnostics diagnostics_;
   NameMangler name_mangler_;
   SymbolTable symbols_;
diff --git a/tools/aapt2/test/Fixture.cpp b/tools/aapt2/test/Fixture.cpp
index 285e5a1..e2f71dc 100644
--- a/tools/aapt2/test/Fixture.cpp
+++ b/tools/aapt2/test/Fixture.cpp
@@ -126,7 +126,7 @@
   link_args.insert(link_args.end(), {"-I", android_sdk});
 
   // Add the files from the compiled resources directory to the link file arguments
-  Maybe<std::vector<std::string>> compiled_files = file::FindFiles(flat_dir, diag);
+  std::optional<std::vector<std::string>> compiled_files = file::FindFiles(flat_dir, diag);
   if (compiled_files) {
     for (std::string& compile_file : compiled_files.value()) {
       compile_file = file::BuildPath({flat_dir, compile_file});
diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp
index 5d57de6..5d2eda3 100644
--- a/tools/aapt2/util/Files.cpp
+++ b/tools/aapt2/util/Files.cpp
@@ -50,12 +50,12 @@
 FileType GetFileType(const std::string& path) {
   std::wstring path_utf16;
   if (!::android::base::UTF8PathToWindowsLongPath(path.c_str(), &path_utf16)) {
-    return FileType::kNonexistant;
+    return FileType::kNonExistant;
   }
 
   DWORD result = GetFileAttributesW(path_utf16.c_str());
   if (result == INVALID_FILE_ATTRIBUTES) {
-    return FileType::kNonexistant;
+    return FileType::kNonExistant;
   }
 
   if (result & FILE_ATTRIBUTE_DIRECTORY) {
@@ -72,7 +72,7 @@
 
   if (result == -1) {
     if (errno == ENOENT || errno == ENOTDIR) {
-      return FileType::kNonexistant;
+      return FileType::kNonExistant;
     }
     return FileType::kUnknown;
   }
@@ -208,7 +208,7 @@
   return out_path;
 }
 
-Maybe<FileMap> MmapPath(const std::string& path, std::string* out_error) {
+std::optional<FileMap> MmapPath(const std::string& path, std::string* out_error) {
   int flags = O_RDONLY | O_CLOEXEC | O_BINARY;
   unique_fd fd(TEMP_FAILURE_RETRY(::android::base::utf8::open(path.c_str(), flags)));
   if (fd == -1) {
@@ -344,8 +344,8 @@
   return true;
 }
 
-Maybe<std::vector<std::string>> FindFiles(const android::StringPiece& path, IDiagnostics* diag,
-                                          const FileFilter* filter) {
+std::optional<std::vector<std::string>> FindFiles(const android::StringPiece& path,
+                                                  IDiagnostics* diag, const FileFilter* filter) {
   const std::string root_dir = path.to_string();
   std::unique_ptr<DIR, decltype(closedir)*> d(opendir(root_dir.data()), closedir);
   if (!d) {
@@ -382,7 +382,7 @@
   for (const std::string& subdir : subdirs) {
     std::string full_subdir = root_dir;
     AppendPath(&full_subdir, subdir);
-    Maybe<std::vector<std::string>> subfiles = FindFiles(full_subdir, diag, filter);
+    std::optional<std::vector<std::string>> subfiles = FindFiles(full_subdir, diag, filter);
     if (!subfiles) {
       return {};
     }
diff --git a/tools/aapt2/util/Files.h b/tools/aapt2/util/Files.h
index 481a4cd..877cd56 100644
--- a/tools/aapt2/util/Files.h
+++ b/tools/aapt2/util/Files.h
@@ -18,6 +18,7 @@
 #define AAPT_FILES_H
 
 #include <memory>
+#include <optional>
 #include <string>
 #include <unordered_set>
 #include <vector>
@@ -27,7 +28,6 @@
 #include "utils/FileMap.h"
 
 #include "Diagnostics.h"
-#include "Maybe.h"
 #include "Source.h"
 
 namespace aapt {
@@ -43,7 +43,7 @@
 
 enum class FileType {
   kUnknown = 0,
-  kNonexistant,
+  kNonExistant,
   kRegular,
   kDirectory,
   kCharDev,
@@ -81,7 +81,7 @@
 std::string PackageToPath(const android::StringPiece& package);
 
 // Creates a FileMap for the file at path.
-Maybe<android::FileMap> MmapPath(const std::string& path, std::string* out_error);
+std::optional<android::FileMap> MmapPath(const std::string& path, std::string* out_error);
 
 // Reads the file at path and appends each line to the outArgList vector.
 bool AppendArgsFromFile(const android::StringPiece& path, std::vector<std::string>* out_arglist,
@@ -124,8 +124,9 @@
 
 // Returns a list of files relative to the directory identified by `path`.
 // An optional FileFilter filters out any files that don't pass.
-Maybe<std::vector<std::string>> FindFiles(const android::StringPiece& path, IDiagnostics* diag,
-                                          const FileFilter* filter = nullptr);
+std::optional<std::vector<std::string>> FindFiles(const android::StringPiece& path,
+                                                  IDiagnostics* diag,
+                                                  const FileFilter* filter = nullptr);
 
 }  // namespace file
 }  // namespace aapt
diff --git a/tools/aapt2/util/Maybe.h b/tools/aapt2/util/Maybe.h
deleted file mode 100644
index 047e1a5..0000000
--- a/tools/aapt2/util/Maybe.h
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef AAPT_MAYBE_H
-#define AAPT_MAYBE_H
-
-#include <type_traits>
-#include <utility>
-
-#include "android-base/logging.h"
-
-#include "util/TypeTraits.h"
-
-namespace aapt {
-
-/**
- * Either holds a valid value of type T, or holds Nothing.
- * The value is stored inline in this structure, so no
- * heap memory is used when creating a Maybe<T> object.
- */
-template <typename T>
-class Maybe {
- public:
-  /**
-   * Construct Nothing.
-   */
-  Maybe();
-
-  ~Maybe();
-
-  Maybe(const Maybe& rhs);
-
-  template <typename U>
-  Maybe(const Maybe<U>& rhs);  // NOLINT(google-explicit-constructor)
-
-  Maybe(Maybe&& rhs) noexcept;
-
-  template <typename U>
-  Maybe(Maybe<U>&& rhs);  // NOLINT(google-explicit-constructor)
-
-  Maybe& operator=(const Maybe& rhs);
-
-  template <typename U>
-  Maybe& operator=(const Maybe<U>& rhs);
-
-  Maybe& operator=(Maybe&& rhs) noexcept;
-
-  template <typename U>
-  Maybe& operator=(Maybe<U>&& rhs);
-
-  /**
-   * Construct a Maybe holding a value.
-   */
-  Maybe(const T& value);  // NOLINT(google-explicit-constructor)
-
-  /**
-   * Construct a Maybe holding a value.
-   */
-  Maybe(T&& value);  // NOLINT(google-explicit-constructor)
-
-  /**
-   * True if this holds a value, false if
-   * it holds Nothing.
-   */
-  explicit operator bool() const;
-
-  /**
-   * Gets the value if one exists, or else
-   * panics.
-   */
-  T& value();
-
-  /**
-   * Gets the value if one exists, or else
-   * panics.
-   */
-  const T& value() const;
-
-  T value_or_default(const T& def) const;
-
- private:
-  template <typename U>
-  friend class Maybe;
-
-  template <typename U>
-  Maybe& copy(const Maybe<U>& rhs);
-
-  template <typename U>
-  Maybe& move(Maybe<U>&& rhs);
-
-  void destroy();
-
-  bool nothing_;
-
-  typename std::aligned_storage<sizeof(T), alignof(T)>::type storage_;
-};
-
-template <typename T>
-Maybe<T>::Maybe() : nothing_(true) {}
-
-template <typename T>
-Maybe<T>::~Maybe() {
-  if (!nothing_) {
-    destroy();
-  }
-}
-
-template <typename T>
-Maybe<T>::Maybe(const Maybe& rhs) : nothing_(rhs.nothing_) {
-  if (!rhs.nothing_) {
-    new (&storage_) T(reinterpret_cast<const T&>(rhs.storage_));
-  }
-}
-
-template <typename T>
-template <typename U>
-Maybe<T>::Maybe(const Maybe<U>& rhs) : nothing_(rhs.nothing_) {
-  if (!rhs.nothing_) {
-    new (&storage_) T(reinterpret_cast<const U&>(rhs.storage_));
-  }
-}
-
-template <typename T>
-Maybe<T>::Maybe(Maybe&& rhs) noexcept : nothing_(rhs.nothing_) {
-  if (!rhs.nothing_) {
-    rhs.nothing_ = true;
-
-    // Move the value from rhs.
-    new (&storage_) T(std::move(reinterpret_cast<T&>(rhs.storage_)));
-    rhs.destroy();
-  }
-}
-
-template <typename T>
-template <typename U>
-Maybe<T>::Maybe(Maybe<U>&& rhs) : nothing_(rhs.nothing_) {
-  if (!rhs.nothing_) {
-    rhs.nothing_ = true;
-
-    // Move the value from rhs.
-    new (&storage_) T(std::move(reinterpret_cast<U&>(rhs.storage_)));
-    rhs.destroy();
-  }
-}
-
-template <typename T>
-inline Maybe<T>& Maybe<T>::operator=(const Maybe& rhs) {
-  // Delegate to the actual assignment.
-  return copy(rhs);
-}
-
-template <typename T>
-template <typename U>
-inline Maybe<T>& Maybe<T>::operator=(const Maybe<U>& rhs) {
-  return copy(rhs);
-}
-
-template <typename T>
-template <typename U>
-Maybe<T>& Maybe<T>::copy(const Maybe<U>& rhs) {
-  if (nothing_ && rhs.nothing_) {
-    // Both are nothing, nothing to do.
-    return *this;
-  } else if (!nothing_ && !rhs.nothing_) {
-    // We both are something, so assign rhs to us.
-    reinterpret_cast<T&>(storage_) = reinterpret_cast<const U&>(rhs.storage_);
-  } else if (nothing_) {
-    // We are nothing but rhs is something.
-    nothing_ = rhs.nothing_;
-
-    // Copy the value from rhs.
-    new (&storage_) T(reinterpret_cast<const U&>(rhs.storage_));
-  } else {
-    // We are something but rhs is nothing, so destroy our value.
-    nothing_ = rhs.nothing_;
-    destroy();
-  }
-  return *this;
-}
-
-template <typename T>
-inline Maybe<T>& Maybe<T>::operator=(Maybe&& rhs) noexcept {
-  // Delegate to the actual assignment.
-  return move(std::forward<Maybe<T>>(rhs));
-}
-
-template <typename T>
-template <typename U>
-inline Maybe<T>& Maybe<T>::operator=(Maybe<U>&& rhs) {
-  return move(std::forward<Maybe<U>>(rhs));
-}
-
-template <typename T>
-template <typename U>
-Maybe<T>& Maybe<T>::move(Maybe<U>&& rhs) {
-  if (nothing_ && rhs.nothing_) {
-    // Both are nothing, nothing to do.
-    return *this;
-  } else if (!nothing_ && !rhs.nothing_) {
-    // We both are something, so move assign rhs to us.
-    rhs.nothing_ = true;
-    reinterpret_cast<T&>(storage_) =
-        std::move(reinterpret_cast<U&>(rhs.storage_));
-    rhs.destroy();
-  } else if (nothing_) {
-    // We are nothing but rhs is something.
-    nothing_ = false;
-    rhs.nothing_ = true;
-
-    // Move the value from rhs.
-    new (&storage_) T(std::move(reinterpret_cast<U&>(rhs.storage_)));
-    rhs.destroy();
-  } else {
-    // We are something but rhs is nothing, so destroy our value.
-    nothing_ = true;
-    destroy();
-  }
-  return *this;
-}
-
-template <typename T>
-Maybe<T>::Maybe(const T& value) : nothing_(false) {
-  new (&storage_) T(value);
-}
-
-template <typename T>
-Maybe<T>::Maybe(T&& value) : nothing_(false) {
-  new (&storage_) T(std::forward<T>(value));
-}
-
-template <typename T>
-Maybe<T>::operator bool() const {
-  return !nothing_;
-}
-
-template <typename T>
-T& Maybe<T>::value() {
-  CHECK(!nothing_) << "Maybe<T>::value() called on Nothing";
-  return reinterpret_cast<T&>(storage_);
-}
-
-template <typename T>
-const T& Maybe<T>::value() const {
-  CHECK(!nothing_) << "Maybe<T>::value() called on Nothing";
-  return reinterpret_cast<const T&>(storage_);
-}
-
-template <typename T>
-T Maybe<T>::value_or_default(const T& def) const {
-  if (nothing_) {
-    return def;
-  }
-  return reinterpret_cast<const T&>(storage_);
-}
-
-template <typename T>
-void Maybe<T>::destroy() {
-  reinterpret_cast<T&>(storage_).~T();
-}
-
-template <typename T>
-inline Maybe<typename std::remove_reference<T>::type> make_value(T&& value) {
-  return Maybe<typename std::remove_reference<T>::type>(std::forward<T>(value));
-}
-
-template <typename T>
-inline Maybe<T> make_nothing() {
-  return Maybe<T>();
-}
-
-// Define the == operator between Maybe<T> and Maybe<U> only if the operator T == U is defined.
-// That way the compiler will show an error at the callsite when comparing two Maybe<> objects
-// whose inner types can't be compared.
-template <typename T, typename U>
-typename std::enable_if<has_eq_op<T, U>::value, bool>::type operator==(const Maybe<T>& a,
-                                                                       const Maybe<U>& b) {
-  if (a && b) {
-    return a.value() == b.value();
-  } else if (!a && !b) {
-    return true;
-  }
-  return false;
-}
-
-template <typename T, typename U>
-typename std::enable_if<has_eq_op<T, U>::value, bool>::type operator==(const Maybe<T>& a,
-                                                                       const U& b) {
-  return a ? a.value() == b : false;
-}
-
-// Same as operator== but negated.
-template <typename T, typename U>
-typename std::enable_if<has_eq_op<T, U>::value, bool>::type operator!=(const Maybe<T>& a,
-                                                                       const Maybe<U>& b) {
-  return !(a == b);
-}
-
-template <typename T, typename U>
-typename std::enable_if<has_lt_op<T, U>::value, bool>::type operator<(const Maybe<T>& a,
-                                                                      const Maybe<U>& b) {
-  if (a && b) {
-    return a.value() < b.value();
-  } else if (!a && !b) {
-    return false;
-  }
-  return !a;
-}
-
-}  // namespace aapt
-
-#endif  // AAPT_MAYBE_H
diff --git a/tools/aapt2/util/Maybe_test.cpp b/tools/aapt2/util/Maybe_test.cpp
deleted file mode 100644
index 4c921f1..0000000
--- a/tools/aapt2/util/Maybe_test.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "util/Maybe.h"
-
-#include <string>
-
-#include "test/Test.h"
-
-namespace aapt {
-
-struct Fake {
-  Fake() {
-    data = new int;
-    *data = 1;
-    std::cerr << "Construct Fake{0x" << (void*)this << "} with data=0x"
-              << (void*)data << std::endl;
-  }
-
-  Fake(const Fake& rhs) {
-    data = nullptr;
-    if (rhs.data) {
-      data = new int;
-      *data = *rhs.data;
-    }
-    std::cerr << "CopyConstruct Fake{0x" << (void*)this << "} from Fake{0x"
-              << (const void*)&rhs << "}" << std::endl;
-  }
-
-  Fake(Fake&& rhs) {
-    data = rhs.data;
-    rhs.data = nullptr;
-    std::cerr << "MoveConstruct Fake{0x" << (void*)this << "} from Fake{0x"
-              << (const void*)&rhs << "}" << std::endl;
-  }
-
-  Fake& operator=(const Fake& rhs) {
-    delete data;
-    data = nullptr;
-
-    if (rhs.data) {
-      data = new int;
-      *data = *rhs.data;
-    }
-    std::cerr << "CopyAssign Fake{0x" << (void*)this << "} from Fake{0x"
-              << (const void*)&rhs << "}" << std::endl;
-    return *this;
-  }
-
-  Fake& operator=(Fake&& rhs) {
-    delete data;
-    data = rhs.data;
-    rhs.data = nullptr;
-    std::cerr << "MoveAssign Fake{0x" << (void*)this << "} from Fake{0x"
-              << (const void*)&rhs << "}" << std::endl;
-    return *this;
-  }
-
-  ~Fake() {
-    std::cerr << "Destruct Fake{0x" << (void*)this << "} with data=0x"
-              << (void*)data << std::endl;
-    delete data;
-  }
-
-  int* data;
-};
-
-TEST(MaybeTest, MakeNothing) {
-  Maybe<int> val = make_nothing<int>();
-  EXPECT_FALSE(val);
-
-  Maybe<std::string> val2 = make_nothing<std::string>();
-  EXPECT_FALSE(val2);
-
-  val2 = make_nothing<std::string>();
-  EXPECT_FALSE(val2);
-}
-
-TEST(MaybeTest, MakeSomething) {
-  Maybe<int> val = make_value(23);
-  ASSERT_TRUE(val);
-  EXPECT_EQ(23, val.value());
-
-  Maybe<std::string> val2 = make_value(std::string("hey"));
-  ASSERT_TRUE(val2);
-  EXPECT_EQ(std::string("hey"), val2.value());
-}
-
-TEST(MaybeTest, Lifecycle) {
-  Maybe<Fake> val = make_nothing<Fake>();
-
-  Maybe<Fake> val2 = make_value(Fake());
-}
-
-TEST(MaybeTest, MoveAssign) {
-  Maybe<Fake> val;
-  {
-    Maybe<Fake> val2 = Fake();
-    val = std::move(val2);
-  }
-}
-
-TEST(MaybeTest, Equality) {
-  Maybe<int> a = 1;
-  Maybe<int> b = 1;
-  Maybe<int> c;
-
-  Maybe<int> emptyA, emptyB;
-
-  EXPECT_EQ(a, b);
-  EXPECT_EQ(b, a);
-  EXPECT_NE(a, c);
-  EXPECT_EQ(emptyA, emptyB);
-}
-
-}  // namespace aapt
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index d7a8e6f..44b4ec1 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -28,7 +28,6 @@
 #include "text/Unicode.h"
 #include "text/Utf8Iterator.h"
 #include "util/BigBuffer.h"
-#include "util/Maybe.h"
 #include "utils/Unicode.h"
 
 using ::aapt::text::Utf8Iterator;
@@ -193,8 +192,8 @@
   return IsAndroidNameImpl(str) > 0;
 }
 
-Maybe<std::string> GetFullyQualifiedClassName(const StringPiece& package,
-                                              const StringPiece& classname) {
+std::optional<std::string> GetFullyQualifiedClassName(const StringPiece& package,
+                                                      const StringPiece& classname) {
   if (classname.empty()) {
     return {};
   }
diff --git a/tools/aapt2/util/Util.h b/tools/aapt2/util/Util.h
index c77aca3..c3efe6a 100644
--- a/tools/aapt2/util/Util.h
+++ b/tools/aapt2/util/Util.h
@@ -28,7 +28,6 @@
 #include "utils/ByteOrder.h"
 
 #include "util/BigBuffer.h"
-#include "util/Maybe.h"
 
 #ifdef _WIN32
 // TODO(adamlesinski): remove once http://b/32447322 is resolved.
@@ -105,8 +104,8 @@
 // .asdf        --> package.asdf
 // .a.b         --> package.a.b
 // asdf.adsf    --> asdf.adsf
-Maybe<std::string> GetFullyQualifiedClassName(const android::StringPiece& package,
-                                              const android::StringPiece& class_name);
+std::optional<std::string> GetFullyQualifiedClassName(const android::StringPiece& package,
+                                                      const android::StringPiece& class_name);
 
 // Retrieves the formatted name of aapt2.
 const char* GetToolName();
diff --git a/tools/aapt2/xml/XmlDom.cpp b/tools/aapt2/xml/XmlDom.cpp
index 2cdcfe4..8b7eadf9 100644
--- a/tools/aapt2/xml/XmlDom.cpp
+++ b/tools/aapt2/xml/XmlDom.cpp
@@ -545,7 +545,7 @@
 void PackageAwareVisitor::BeforeVisitElement(Element* el) {
   std::vector<PackageDecl> decls;
   for (const NamespaceDecl& decl : el->namespace_decls) {
-    if (Maybe<ExtractedPackage> maybe_package = ExtractPackageFromNamespace(decl.uri)) {
+    if (std::optional<ExtractedPackage> maybe_package = ExtractPackageFromNamespace(decl.uri)) {
       decls.push_back(PackageDecl{decl.prefix, std::move(maybe_package.value())});
     }
   }
@@ -556,7 +556,8 @@
   package_decls_.pop_back();
 }
 
-Maybe<ExtractedPackage> PackageAwareVisitor::TransformPackageAlias(const StringPiece& alias) const {
+std::optional<ExtractedPackage> PackageAwareVisitor::TransformPackageAlias(
+    const StringPiece& alias) const {
   if (alias.empty()) {
     return ExtractedPackage{{}, false /*private*/};
   }
diff --git a/tools/aapt2/xml/XmlDom.h b/tools/aapt2/xml/XmlDom.h
index a5b2d10..5d31804 100644
--- a/tools/aapt2/xml/XmlDom.h
+++ b/tools/aapt2/xml/XmlDom.h
@@ -65,12 +65,12 @@
 };
 
 struct AaptAttribute {
-  explicit AaptAttribute(const ::aapt::Attribute& attr, const Maybe<ResourceId>& resid = {})
+  explicit AaptAttribute(const ::aapt::Attribute& attr, const std::optional<ResourceId>& resid = {})
       : attribute(attr), id(resid) {
   }
 
   aapt::Attribute attribute;
-  Maybe<ResourceId> id;
+  std::optional<ResourceId> id;
 };
 
 // An XML attribute.
@@ -79,7 +79,7 @@
   std::string name;
   std::string value;
 
-  Maybe<AaptAttribute> compiled_attribute;
+  std::optional<AaptAttribute> compiled_attribute;
   std::unique_ptr<Item> compiled_value;
 };
 
@@ -235,7 +235,8 @@
  public:
   using Visitor::Visit;
 
-  Maybe<ExtractedPackage> TransformPackageAlias(const android::StringPiece& alias) const override;
+  std::optional<ExtractedPackage> TransformPackageAlias(
+      const android::StringPiece& alias) const override;
 
  protected:
   PackageAwareVisitor() = default;
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp
index ca46d53..6c717dc 100644
--- a/tools/aapt2/xml/XmlDom_test.cpp
+++ b/tools/aapt2/xml/XmlDom_test.cpp
@@ -98,7 +98,7 @@
   // the Attribute accepts (eg: string|reference).
   ASSERT_TRUE(new_doc->root->attributes[0].compiled_attribute);
   EXPECT_THAT(new_doc->root->attributes[0].compiled_attribute.value().id,
-              Eq(make_value(ResourceId(0x01010001u))));
+              Eq(ResourceId(0x01010001u)));
 
   EXPECT_THAT(new_doc->root->attributes[0].value, StrEq("@string/foo"));
   EXPECT_THAT(new_doc->root->attributes[0].compiled_value,
@@ -145,21 +145,19 @@
 
   void Visit(Element* el) override {
     if (el->name == "View1") {
-      EXPECT_THAT(TransformPackageAlias("one"), Eq(make_value(ExtractedPackage{"com.one", false})));
+      EXPECT_THAT(TransformPackageAlias("one"), Eq(ExtractedPackage{"com.one", false}));
     } else if (el->name == "View2") {
-      EXPECT_THAT(TransformPackageAlias("one"), Eq(make_value(ExtractedPackage{"com.one", false})));
-      EXPECT_THAT(TransformPackageAlias("two"), Eq(make_value(ExtractedPackage{"com.two", false})));
+      EXPECT_THAT(TransformPackageAlias("one"), Eq(ExtractedPackage{"com.one", false}));
+      EXPECT_THAT(TransformPackageAlias("two"), Eq(ExtractedPackage{"com.two", false}));
     } else if (el->name == "View3") {
-      EXPECT_THAT(TransformPackageAlias("one"), Eq(make_value(ExtractedPackage{"com.one", false})));
-      EXPECT_THAT(TransformPackageAlias("two"), Eq(make_value(ExtractedPackage{"com.two", false})));
-      EXPECT_THAT(TransformPackageAlias("three"),
-                  Eq(make_value(ExtractedPackage{"com.three", false})));
+      EXPECT_THAT(TransformPackageAlias("one"), Eq(ExtractedPackage{"com.one", false}));
+      EXPECT_THAT(TransformPackageAlias("two"), Eq(ExtractedPackage{"com.two", false}));
+      EXPECT_THAT(TransformPackageAlias("three"), Eq(ExtractedPackage{"com.three", false}));
     } else if (el->name == "View4") {
-      EXPECT_THAT(TransformPackageAlias("one"), Eq(make_value(ExtractedPackage{"com.one", false})));
-      EXPECT_THAT(TransformPackageAlias("two"), Eq(make_value(ExtractedPackage{"com.two", false})));
-      EXPECT_THAT(TransformPackageAlias("three"),
-                  Eq(make_value(ExtractedPackage{"com.three", false})));
-      EXPECT_THAT(TransformPackageAlias("four"), Eq(make_value(ExtractedPackage{"", true})));
+      EXPECT_THAT(TransformPackageAlias("one"), Eq(ExtractedPackage{"com.one", false}));
+      EXPECT_THAT(TransformPackageAlias("two"), Eq(ExtractedPackage{"com.two", false}));
+      EXPECT_THAT(TransformPackageAlias("three"), Eq(ExtractedPackage{"com.three", false}));
+      EXPECT_THAT(TransformPackageAlias("four"), Eq(ExtractedPackage{"", true}));
     }
   }
 };
diff --git a/tools/aapt2/xml/XmlPullParser.cpp b/tools/aapt2/xml/XmlPullParser.cpp
index 182203d..bfa0749 100644
--- a/tools/aapt2/xml/XmlPullParser.cpp
+++ b/tools/aapt2/xml/XmlPullParser.cpp
@@ -17,7 +17,6 @@
 #include <iostream>
 #include <string>
 
-#include "util/Maybe.h"
 #include "util/Util.h"
 #include "xml/XmlPullParser.h"
 #include "xml/XmlUtil.h"
@@ -84,8 +83,7 @@
   // handling of references that use namespace aliases.
   if (next_event == Event::kStartNamespace ||
       next_event == Event::kEndNamespace) {
-    Maybe<ExtractedPackage> result =
-        ExtractPackageFromNamespace(namespace_uri());
+    std::optional<ExtractedPackage> result = ExtractPackageFromNamespace(namespace_uri());
     if (next_event == Event::kStartNamespace) {
       if (result) {
         package_aliases_.emplace_back(
@@ -142,7 +140,8 @@
   return event_queue_.front().data2;
 }
 
-Maybe<ExtractedPackage> XmlPullParser::TransformPackageAlias(const StringPiece& alias) const {
+std::optional<ExtractedPackage> XmlPullParser::TransformPackageAlias(
+    const StringPiece& alias) const {
   if (alias.empty()) {
     return ExtractedPackage{{}, false /*private*/};
   }
@@ -308,8 +307,7 @@
                                       parser->depth_ });
 }
 
-Maybe<StringPiece> FindAttribute(const XmlPullParser* parser,
-                                 const StringPiece& name) {
+std::optional<StringPiece> FindAttribute(const XmlPullParser* parser, const StringPiece& name) {
   auto iter = parser->FindAttribute("", name);
   if (iter != parser->end_attributes()) {
     return StringPiece(util::TrimWhitespace(iter->value));
@@ -317,8 +315,8 @@
   return {};
 }
 
-Maybe<StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
-                                         const StringPiece& name) {
+std::optional<StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
+                                                 const StringPiece& name) {
   auto iter = parser->FindAttribute("", name);
   if (iter != parser->end_attributes()) {
     StringPiece trimmed = util::TrimWhitespace(iter->value);
diff --git a/tools/aapt2/xml/XmlPullParser.h b/tools/aapt2/xml/XmlPullParser.h
index 5da2d4b..ab34772 100644
--- a/tools/aapt2/xml/XmlPullParser.h
+++ b/tools/aapt2/xml/XmlPullParser.h
@@ -33,7 +33,6 @@
 #include "Resource.h"
 #include "io/Io.h"
 #include "process/IResourceTableConsumer.h"
-#include "util/Maybe.h"
 #include "xml/XmlUtil.h"
 
 namespace aapt {
@@ -121,7 +120,8 @@
    * If xmlns:app="http://schemas.android.com/apk/res-auto", then
    * 'package' will be set to 'defaultPackage'.
    */
-  Maybe<ExtractedPackage> TransformPackageAlias(const android::StringPiece& alias) const override;
+  std::optional<ExtractedPackage> TransformPackageAlias(
+      const android::StringPiece& alias) const override;
 
   struct PackageDecl {
     std::string prefix;
@@ -193,16 +193,16 @@
 /**
  * Finds the attribute in the current element within the global namespace.
  */
-Maybe<android::StringPiece> FindAttribute(const XmlPullParser* parser,
-                                          const android::StringPiece& name);
+std::optional<android::StringPiece> FindAttribute(const XmlPullParser* parser,
+                                                  const android::StringPiece& name);
 
 /**
  * Finds the attribute in the current element within the global namespace. The
  * attribute's value
  * must not be the empty string.
  */
-Maybe<android::StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
-                                                  const android::StringPiece& name);
+std::optional<android::StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
+                                                          const android::StringPiece& name);
 
 //
 // Implementation
diff --git a/tools/aapt2/xml/XmlUtil.cpp b/tools/aapt2/xml/XmlUtil.cpp
index 0a622b2..114b5ba 100644
--- a/tools/aapt2/xml/XmlUtil.cpp
+++ b/tools/aapt2/xml/XmlUtil.cpp
@@ -19,7 +19,6 @@
 #include <algorithm>
 #include <string>
 
-#include "util/Maybe.h"
 #include "util/Util.h"
 #include "xml/XmlDom.h"
 
@@ -34,8 +33,7 @@
   return result;
 }
 
-Maybe<ExtractedPackage> ExtractPackageFromNamespace(
-    const std::string& namespace_uri) {
+std::optional<ExtractedPackage> ExtractPackageFromNamespace(const std::string& namespace_uri) {
   if (util::StartsWith(namespace_uri, kSchemaPublicPrefix)) {
     StringPiece schema_prefix = kSchemaPublicPrefix;
     StringPiece package = namespace_uri;
@@ -62,7 +60,7 @@
 
 void ResolvePackage(const IPackageDeclStack* decl_stack, Reference* in_ref) {
   if (in_ref->name) {
-    if (Maybe<ExtractedPackage> transformed_package =
+    if (std::optional<ExtractedPackage> transformed_package =
             decl_stack->TransformPackageAlias(in_ref->name.value().package)) {
       ExtractedPackage& extracted_package = transformed_package.value();
       in_ref->name.value().package = std::move(extracted_package.package);
diff --git a/tools/aapt2/xml/XmlUtil.h b/tools/aapt2/xml/XmlUtil.h
index 592a604f..1ab05a9 100644
--- a/tools/aapt2/xml/XmlUtil.h
+++ b/tools/aapt2/xml/XmlUtil.h
@@ -20,7 +20,6 @@
 #include <string>
 
 #include "ResourceValues.h"
-#include "util/Maybe.h"
 
 namespace aapt {
 namespace xml {
@@ -53,7 +52,7 @@
 //
 // Special case: if namespaceUri is http://schemas.android.com/apk/res-auto, returns an empty
 // package name.
-Maybe<ExtractedPackage> ExtractPackageFromNamespace(const std::string& namespace_uri);
+std::optional<ExtractedPackage> ExtractPackageFromNamespace(const std::string& namespace_uri);
 
 // Returns an XML Android namespace for the given package of the form:
 //   http://schemas.android.com/apk/res/<package>
@@ -69,7 +68,7 @@
   virtual ~IPackageDeclStack() = default;
 
   // Returns an ExtractedPackage struct if the alias given corresponds with a package declaration.
-  virtual Maybe<ExtractedPackage> TransformPackageAlias(
+  virtual std::optional<ExtractedPackage> TransformPackageAlias(
       const android::StringPiece& alias) const = 0;
 };
 
diff --git a/tools/aapt2/xml/XmlUtil_test.cpp b/tools/aapt2/xml/XmlUtil_test.cpp
index cbded8f..7b6ce9e 100644
--- a/tools/aapt2/xml/XmlUtil_test.cpp
+++ b/tools/aapt2/xml/XmlUtil_test.cpp
@@ -27,7 +27,7 @@
   ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/"));
   ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/"));
 
-  Maybe<xml::ExtractedPackage> p =
+  std::optional<xml::ExtractedPackage> p =
       xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/a");
   ASSERT_TRUE(p);
   EXPECT_EQ(std::string("a"), p.value().package);