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_embedded_jars_extractor.py b/tools/android/aar_embedded_jars_extractor.py
index 2fa85b6..d8f42d9 100644
--- a/tools/android/aar_embedded_jars_extractor.py
+++ b/tools/android/aar_embedded_jars_extractor.py
@@ -1,3 +1,4 @@
+# Lint as: python2, python3
 # pylint: disable=g-direct-third-party-import
 # Copyright 2016 The Bazel Authors. All rights reserved.
 #
@@ -19,23 +20,31 @@
 of the jars and creates a param file for singlejar to merge them into one jar.
 """
 
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
 import os
 import re
 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(
-    "output_singlejar_param_file", None, "Output parameter file for singlejar")
-gflags.MarkFlagAsRequired("output_singlejar_param_file")
-gflags.DEFINE_string("output_dir", None, "Output directory to extract jars in")
-gflags.MarkFlagAsRequired("output_dir")
+flags.DEFINE_string("input_aar", None, "Input AAR")
+flags.mark_flag_as_required("input_aar")
+flags.DEFINE_string("output_singlejar_param_file", None,
+                    "Output parameter file for singlejar")
+flags.mark_flag_as_required("output_singlejar_param_file")
+flags.DEFINE_string("output_dir", None, "Output directory to extract jars in")
+flags.mark_flag_as_required("output_dir")
 
 
 def ExtractEmbeddedJars(aar,
@@ -52,7 +61,7 @@
       # output_dir may be a temporary junction, so write the original
       # (unshortened) path to the params file
       singlejar_param_file.write(
-          (output_dir_orig + "/" + name + "\n").encode("utf-8"))
+          six.ensure_binary((output_dir_orig + "/" + name + "\n"), "utf-8"))
       aar.extract(name, output_dir)
 
 
@@ -68,7 +77,7 @@
                           output_dir_orig)
 
 
-def main():
+def main(unused_argv):
   if os.name == "nt":
     # Shorten paths unconditionally, because the extracted paths in
     # ExtractEmbeddedJars (which we cannot yet predict, because they depend on
@@ -90,4 +99,4 @@
 
 if __name__ == "__main__":
   FLAGS(sys.argv)
-  main()
+  app.run(main)