py2to3: update tools/android/*.py to PY3

This is a rollback of commit 91b26dc4f3b327f115787c3ec35278c299480d0c and a
roll-forward of commit ad628ecfb8ed43870fb354e5d8f7da68594f95bd. Original commit
message is below.

Details:
- use six.ensure_str / six.ensure_bytes
- use absl.flags instead of gflags
- put third_party/py/abseil:srcs into @bazel_tools
  so the embedded Android tools can also use it
- remove python_version = "PY2" from py_binary and
  py_test rules (the default is "PY3"), except in
  BUILD.tools, to preserve PY2 compatibility for
  running Bazel (its embedded Python tools)
- added srcs_version = "PY2AND3" to BUILD.tools to
  make it explicit that these libraries are meant
  to be py2 and py3 compatible

See https://github.com/bazelbuild/bazel/issues/10127

PiperOrigin-RevId: 278394040
diff --git a/tools/android/aar_native_libs_zip_creator.py b/tools/android/aar_native_libs_zip_creator.py
index 0348418..59c3d7b 100644
--- a/tools/android/aar_native_libs_zip_creator.py
+++ b/tools/android/aar_native_libs_zip_creator.py
@@ -1,3 +1,4 @@
+# Lint as: python2, python3
 # pylint: disable=g-direct-third-party-import
 # Copyright 2016 The Bazel Authors. All rights reserved.
 #
@@ -20,6 +21,8 @@
 directory structure of /lib/<cpu>/foo.so.
 """
 
+from __future__ import absolute_import
+from __future__ import division
 from __future__ import print_function
 
 import os
@@ -27,17 +30,21 @@
 import sys
 import zipfile
 
+# Do not edit this line. Copybara replaces it with PY2 migration helper.
+from absl import app
+from absl import flags
+import six
+
 from tools.android import junction
-from third_party.py import gflags
 
-FLAGS = gflags.FLAGS
+FLAGS = flags.FLAGS
 
-gflags.DEFINE_string("input_aar", None, "Input AAR")
-gflags.MarkFlagAsRequired("input_aar")
-gflags.DEFINE_string("cpu", None, "CPU architecture to include")
-gflags.MarkFlagAsRequired("cpu")
-gflags.DEFINE_string("output_zip", None, "Output ZIP of native libs")
-gflags.MarkFlagAsRequired("output_zip")
+flags.DEFINE_string("input_aar", None, "Input AAR")
+flags.mark_flag_as_required("input_aar")
+flags.DEFINE_string("cpu", None, "CPU architecture to include")
+flags.mark_flag_as_required("cpu")
+flags.DEFINE_string("output_zip", None, "Output ZIP of native libs")
+flags.mark_flag_as_required("output_zip")
 
 
 class UnsupportedArchitectureException(Exception):
@@ -48,7 +55,7 @@
 def CreateNativeLibsZip(aar, cpu, native_libs_zip):
   native_lib_pattern = re.compile("^jni/.+/.+\\.so$")
   if any(native_lib_pattern.match(filename) for filename in aar.namelist()):
-    cpu_pattern = re.compile("^jni/" + cpu + "/.+\\.so$")
+    cpu_pattern = re.compile("^jni/" + six.ensure_str(cpu) + "/.+\\.so$")
     libs = [name for name in aar.namelist() if cpu_pattern.match(name)]
     if not libs:
       raise UnsupportedArchitectureException()
@@ -65,12 +72,13 @@
       try:
         CreateNativeLibsZip(input_aar, cpu, native_libs_zip)
       except UnsupportedArchitectureException:
-        print("AAR " + input_aar_path_for_error_msg +
-              " missing native libs for requested architecture: " + cpu)
+        print("AAR " + six.ensure_str(input_aar_path_for_error_msg) +
+              " missing native libs for requested architecture: " +
+              six.ensure_str(cpu))
         sys.exit(1)
 
 
-def main():
+def main(unused_argv):
   if os.name == "nt":
     with junction.TempJunction(os.path.dirname(FLAGS.input_aar)) as j_in:
       with junction.TempJunction(os.path.dirname(FLAGS.output_zip)) as j_out:
@@ -84,4 +92,4 @@
 
 if __name__ == "__main__":
   FLAGS(sys.argv)
-  main()
+  app.run(main)