Clean up APEX library lists.

Make it more clear why they are listed, and sort lists for maintenance. This
mostly reorders lines, but also removes a few libraries that are pulled in
by dependencies and don't need to be mentioned explicitly. There should be
no functional differences.

Test: art/build/apex/runtests.sh
Bug: 124293228
Change-Id: I5bfb68892a5cbf77654af253c3b1efec034c16e2
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index 15e5c02..bfa4043 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -23,23 +23,27 @@
 // TODO(b/121117762): Remove this note when both the ART Buildbot and Golem use
 // the Runtime APEX.
 art_runtime_base_native_shared_libs = [
-    "libadbconnection",
-    "libart",
-    "libart-compiler",
+    // External API (having APEX stubs).
     "libdexfile_external",
     "libnativebridge",
     "libnativehelper",
     "libnativeloader",
-    "libopenjdkjvm",
-    "libopenjdkjvmti",
-    // TODO(b/124439236): Clean up the following libraries once "required"
+    // libadbconnection is internal and loaded with dlopen(), but it cannot use
+    // "required" because of cyclic dependency (b/124505714).
+    "libadbconnection",
+    // TODO(b/124476339): Clean up the following libraries once "required"
     // dependencies work with APEX libraries.
+    "libart",
+    "libart-compiler",
     "libdt_fd_forward",
     "libdt_socket",
     "libjdwp",
     "libnpt",
+    "libopenjdkjvm",
+    "libopenjdkjvmti",
 ]
 bionic_native_shared_libs = [
+    // External API (having APEX stubs).
     "libc",
     "libm",
     "libdl",
@@ -67,9 +71,6 @@
     "libopenjdkjvmd",
     "libopenjdkjvmtid",
 ]
-libcore_debug_native_shared_libs = [
-    "libopenjdkd",
-]
 
 // Data files associated with bionic / managed core library APIs.
 art_runtime_data_file_prebuilts = [
@@ -105,7 +106,6 @@
     // (same issue as for `libart_fake` above).
     //"ahat",
     "hprof-conv",
-    // ...
 ]
 
 art_tools_device_binaries = art_tools_common_binaries + art_tools_device_only_binaries
@@ -137,18 +137,22 @@
 // TODO(b/121117762): Remove this note when both the ART Buildbot and Golem use
 // the Runtime APEX.
 libcore_native_shared_libs = [
+    // External API (having APEX stubs).
     "libandroidicu",
     "libandroidio",
+    // TODO(b/124476339): Clean up the following libraries once "required"
+    // dependencies work with APEX libraries.
     "libexpat",
     "libicui18n",
     "libicuuc",
     "libjavacore",
     "libopenjdk",
-    "libz",
-    "libziparchive",
+]
+libcore_debug_native_shared_libs = [
+    "libopenjdkd",
 ]
 
-libcore_native_device_only_shared_libs = libcore_native_shared_libs + [
+libcore_native_device_only_shared_libs = [
     // TODO(b/122876336): Remove libpac.so once it's migrated to Webview.
     // libpac is used by frameworks, not by ART host.
     "libpac",
@@ -192,7 +196,8 @@
     java_libs: libcore_java_libs,
     native_shared_libs: art_runtime_base_native_shared_libs
         + bionic_native_shared_libs
-        + libcore_native_device_only_shared_libs,
+        + libcore_native_device_only_shared_libs
+        + libcore_native_shared_libs,
     multilib: {
         both: {
             binaries: art_runtime_base_binaries_both
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index c74f3e8..384eef5 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -372,44 +372,45 @@
     return 'Release Checker'
 
   def run(self):
-    # Check that the mounted image contains an APEX manifest.
+    # Check the APEX manifest.
     self._checker.check_file('apex_manifest.json')
 
-    # Check that the mounted image contains ART base binaries.
-    self._checker.check_symlinked_multilib_executable('dalvikvm')
+    # Check base binaries for ART.
     self._checker.check_executable('dex2oat')
     self._checker.check_executable('dexoptanalyzer')
     self._checker.check_executable('profman')
+    self._checker.check_symlinked_multilib_executable('dalvikvm')
 
-    # oatdump is only in device apex's due to build rules
-    # TODO: Check for it when it is also built for host.
-    # self._checker.check_executable('oatdump')
-
-    # Check that the mounted image contains Android Runtime libraries.
-    self._checker.check_native_library('libart-compiler')
-    self._checker.check_native_library('libart-dexlayout')
-    self._checker.check_native_library('libart')
-    self._checker.check_native_library('libartbase')
-    self._checker.check_native_library('libartpalette')
-    self._checker.check_native_library('libdexfile')
+    # Check exported libraries for ART.
     self._checker.check_native_library('libdexfile_external')
     self._checker.check_native_library('libnativebridge')
     self._checker.check_native_library('libnativehelper')
     self._checker.check_native_library('libnativeloader')
+
+    # Check internal libraries for ART.
+    self._checker.check_native_library('libadbconnection')
+    self._checker.check_native_library('libart')
+    self._checker.check_native_library('libart-compiler')
+    self._checker.check_native_library('libart-dexlayout')
+    self._checker.check_native_library('libartbase')
+    self._checker.check_native_library('libartpalette')
+    self._checker.check_native_library('libdexfile')
+    self._checker.check_native_library('libdexfile_support')
     self._checker.check_native_library('libopenjdkjvm')
     self._checker.check_native_library('libopenjdkjvmti')
     self._checker.check_native_library('libprofile')
-    # Check that the mounted image contains Android Core libraries.
-    # Note: host vs target libs are checked elsewhere.
+    self._checker.check_native_library('libsigchain')
+
+    # Check java libraries for Managed Core Library.
+    self._checker.check_java_library('apache-xml')
+    self._checker.check_java_library('bouncycastle')
+    self._checker.check_java_library('core-libart')
+    self._checker.check_java_library('core-oj')
+    self._checker.check_java_library('okhttp')
+
+    # Check internal native libraries for Managed Core Library.
     self._checker.check_native_library('libjavacore')
     self._checker.check_native_library('libopenjdk')
-    self._checker.check_native_library('libziparchive')
-    # Check that the mounted image contains additional required libraries.
-    self._checker.check_native_library('libadbconnection')
-    self._checker.check_native_library('libdt_fd_forward')
-    self._checker.check_native_library('libdt_socket')
-    self._checker.check_native_library('libjdwp')
-    self._checker.check_native_library('libnpt')
 
     # Check internal native library dependencies.
     #
@@ -425,23 +426,21 @@
     self._checker.check_native_library('libbacktrace')
     self._checker.check_native_library('libbase')
     self._checker.check_native_library('libc++')
-    self._checker.check_native_library('libdexfile_support')
+    self._checker.check_native_library('libdt_fd_forward')
+    self._checker.check_native_library('libdt_socket')
+    self._checker.check_native_library('libjdwp')
     self._checker.check_native_library('liblzma')
-    self._checker.check_native_library('libsigchain')
+    self._checker.check_native_library('libnpt')
     self._checker.check_native_library('libunwindstack')
+    self._checker.check_native_library('libziparchive')
     self._checker.check_optional_native_library('libvixl')  # Only on ARM/ARM64
 
     # TODO(b/124293228): Figure out why we get these.
     self._checker.check_native_library('libcutils')
+    # The following appears with ASAN (SANITIZE_TARGET=address).
     self._checker.check_optional_native_library('libclang_rt.asan-i686-android')
     self._checker.check_optional_native_library('libclang_rt.hwasan-aarch64-android')
 
-    self._checker.check_java_library('core-oj')
-    self._checker.check_java_library('core-libart')
-    self._checker.check_java_library('okhttp')
-    self._checker.check_java_library('bouncycastle')
-    self._checker.check_java_library('apache-xml')
-
 
 class ReleaseTargetChecker:
   def __init__(self, checker):
@@ -451,15 +450,6 @@
     return 'Release (Target) Checker'
 
   def run(self):
-    # Check that the mounted image contains ART tools binaries.
-    self._checker.check_executable('dexdiag')
-    self._checker.check_executable('dexdump')
-    self._checker.check_executable('dexlist')
-
-    # Check for files pulled in for target-only oatdump.
-    self._checker.check_executable('oatdump')
-    self._checker.check_prefer64_library('libart-disassembler')
-
     # Check the APEX package scripts.
     self._checker.check_executable('art_postinstall_hook')
     self._checker.check_executable('art_preinstall_hook')
@@ -467,27 +457,36 @@
     self._checker.check_executable('art_preinstall_hook_system_server')
     self._checker.check_executable('art_prepostinstall_utils')
 
-    # Check Bionic binaries.
+    # Check binaries for ART.
+    self._checker.check_executable('dexdiag')
+    self._checker.check_executable('dexdump')
+    self._checker.check_executable('dexlist')
+    self._checker.check_executable('oatdump')
+
+    # Check internal libraries for ART.
+    self._checker.check_prefer64_library('libart-disassembler')
+
+    # Check binaries for Bionic.
     self._checker.check_multilib_executable('linker')
     self._checker.check_multilib_executable('linker_asan')
 
-    # Check Bionic libraries.
+    # Check libraries for Bionic.
     self._checker.check_native_library('bionic/libc')
     self._checker.check_native_library('bionic/libdl')
     self._checker.check_native_library('bionic/libm')
 
-    # Check that the mounted image contains Android Core libraries.
+    # Check exported native libraries for Managed Core Library.
     self._checker.check_native_library('libandroidicu')
     self._checker.check_native_library('libandroidio')
+
+    # Check internal native library dependencies.
+    self._checker.check_native_library('libcrypto')
     self._checker.check_native_library('libexpat')
     self._checker.check_native_library('libicui18n')
     self._checker.check_native_library('libicuuc')
     self._checker.check_native_library('libpac')
-    self._checker.check_native_library('libz')
-
-    # Check internal native library dependencies.
-    self._checker.check_native_library('libcrypto')
     self._checker.check_native_library('libtombstoned_client')
+    self._checker.check_native_library('libz')
 
     # TODO(b/124293228): Figure out why we get these.
     self._checker.check_prefer64_library('libjsoncpp')
@@ -510,9 +509,11 @@
     return 'Release (Host) Checker'
 
   def run(self):
-    # Check that the mounted image contains Android Core libraries.
+    # Check exported native libraries for Managed Core Library.
     self._checker.check_native_library('libandroidicu-host')
     self._checker.check_native_library('libandroidio')
+
+    # Check internal libraries for Managed Core Library.
     self._checker.check_native_library('libexpat-host')
     self._checker.check_native_library('libicui18n-host')
     self._checker.check_native_library('libicuuc-host')
@@ -527,29 +528,29 @@
     return 'Debug Checker'
 
   def run(self):
-    # Check that the mounted image contains ART tools binaries.
+    # Check binaries for ART.
     self._checker.check_executable('dexdiag')
     self._checker.check_executable('dexdump')
     self._checker.check_executable('dexlist')
 
-    # Check that the mounted image contains ART debug binaries.
-    self._checker.check_symlinked_prefer32_executable('dex2oatd')
+    # Check debug binaries for ART.
     self._checker.check_executable('dexoptanalyzerd')
     self._checker.check_executable('profmand')
+    self._checker.check_symlinked_prefer32_executable('dex2oatd')
 
-    # Check that the mounted image contains Android Runtime debug libraries.
+    # Check internal libraries for ART.
+    self._checker.check_native_library('libadbconnectiond')
     self._checker.check_native_library('libartbased')
+    self._checker.check_native_library('libartd')
     self._checker.check_native_library('libartd-compiler')
     self._checker.check_native_library('libartd-dexlayout')
-    self._checker.check_native_library('libartd')
     self._checker.check_native_library('libdexfiled')
     self._checker.check_native_library('libopenjdkjvmd')
     self._checker.check_native_library('libopenjdkjvmtid')
     self._checker.check_native_library('libprofiled')
-    # Check that the mounted image contains Android Core debug libraries.
+
+    # Check internal libraries for Managed Core Library.
     self._checker.check_native_library('libopenjdkd')
-    # Check that the mounted image contains additional required debug libraries.
-    self._checker.check_native_library('libadbconnectiond')
 
 
 class DebugTargetChecker:
@@ -560,10 +561,10 @@
     return 'Debug (Target) Checker'
 
   def run(self):
-    # Check for files pulled in for debug target-only oatdump.
-    self._checker.check_executable('oatdump')
+    # Check ART debug binaries.
     self._checker.check_executable('oatdumpd')
-    self._checker.check_prefer64_library('libart-disassembler')
+
+    # Check ART internal libraries.
     self._checker.check_prefer64_library('libartd-disassembler')
 
     # Check internal native library dependencies.