AAPT2: Allow specifying non-final IDS when building 'legacy' style libraries

Real libraries will be built correctly, but since we are not doing that
yet, support the old way and allow a flag --non-final-ids to remove
the final modifier from R.java.

Change-Id: Iad55fb9140e55dbb0f41d0d55f2e2bd958294c8e
diff --git a/tools/aapt2/link/Link.cpp b/tools/aapt2/link/Link.cpp
index 364a55b..f3a9ea3 100644
--- a/tools/aapt2/link/Link.cpp
+++ b/tools/aapt2/link/Link.cpp
@@ -56,6 +56,7 @@
     Maybe<std::string> generateProguardRulesPath;
     bool noAutoVersion = false;
     bool staticLib = false;
+    bool generateNonFinalIds = false;
     bool verbose = false;
     bool outputToDirectory = false;
     bool autoAddOverlay = false;
@@ -835,7 +836,7 @@
             JavaClassGeneratorOptions options;
             options.types = JavaClassGeneratorOptions::SymbolTypes::kAll;
 
-            if (mOptions.staticLib) {
+            if (mOptions.staticLib || mOptions.generateNonFinalIds) {
                 options.useFinal = false;
             }
 
@@ -933,6 +934,9 @@
             .optionalFlag("--version-name", "Version name to inject into the AndroidManifest.xml "
                           "if none is present", &versionName)
             .optionalSwitch("--static-lib", "Generate a static Android library", &options.staticLib)
+            .optionalSwitch("--non-final-ids", "Generates R.java without the final modifier.\n"
+                            "This is implied when --static-lib is specified.",
+                            &options.generateNonFinalIds)
             .optionalFlag("--private-symbols", "Package name to use when generating R.java for "
                           "private symbols.\n"
                           "If not specified, public and private symbols will use the application's "