Revert "Static link gtests with ART libraries"

This reverts commit 66244e2af2e9ee54b57022eeeabb7230109a98fa.

Reason for revert: broken tests on art-gtest-asan32

Change-Id: I069a6a177a8eb95a383719e3fdadc698dd2fb4b8
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 0c813d1..891fd0f 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -697,6 +697,11 @@
     self._checker.check_art_test_executable('art_runtime_tests')
     self._checker.check_art_test_executable('art_sigchain_tests')
 
+    # Check ART test (internal) libraries.
+    self._checker.check_native_library('libartd-gtest')
+    self._checker.check_native_library('libartd-simulator-container')
+    self._checker.check_native_library('libartbased-testing')
+
     # Check ART test tools.
     self._checker.check_executable('signal_dumper')
 
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 3e279e4..00e1bb9 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -28,89 +28,6 @@
     default_applicable_licenses: ["art_license"],
 }
 
-// Common dependencies for libart-compiler_deps and libartd-compiler_deps.
-cc_defaults {
-    name: "libart-compiler_common_deps",
-    shared_libs: [
-        "libbase",
-        "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib.
-        "libartpalette",
-    ],
-    header_libs: [
-        "libart_generated_headers",
-    ],
-}
-
-// Dependencies of libart-compiler, used to propagate libart-compiler deps when static linking.
-art_cc_defaults {
-    name: "libart-compiler_deps",
-    defaults: ["libart-compiler_common_deps"],
-    shared_libs: [
-        "libartbase",
-        "libprofile",
-        "libdexfile",
-    ],
-    static_libs: ["libelffile"],
-    codegen: {
-        arm: {
-            // VIXL assembly support for ARM targets.
-            static_libs: [
-                "libvixl",
-            ],
-        },
-        arm64: {
-            // VIXL assembly support for ARM64 targets.
-            static_libs: [
-                "libvixl",
-            ],
-        },
-    },
-    runtime_libs: [
-        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
-        // `libart-disassembler.so`.
-        "libart-disassembler",
-    ],
-}
-
-// Dependencies of libartd-compiler, used to propagate libartd-compiler deps when static linking.
-art_cc_defaults {
-    name: "libartd-compiler_deps",
-    defaults: ["libart-compiler_common_deps"],
-    shared_libs: [
-        "libartbased",
-        "libprofiled",
-        "libdexfiled",
-    ],
-    static_libs: ["libelffiled"],
-    codegen: {
-        arm: {
-            // VIXL assembly support for ARM targets.
-            static_libs: [
-                "libvixld",
-            ],
-            // Export vixl headers as they are included in this library's headers used by tests.
-            export_static_lib_headers: [
-                "libvixld",
-            ],
-        },
-        arm64: {
-            // VIXL assembly support for ARM64 targets.
-            static_libs: [
-                "libvixld",
-            ],
-            // Export vixl headers as they are included in this library's headers used by tests.
-            export_static_lib_headers: [
-                "libvixld",
-            ],
-        },
-    },
-    runtime_libs: [
-        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
-        // `libartd-disassembler.so`.
-        "libartd-disassembler",
-    ],
-}
-
 art_cc_defaults {
     name: "libart-compiler-defaults",
     defaults: ["art_defaults"],
@@ -294,13 +211,35 @@
         "libart-compiler-defaults",
         "dex2oat-pgo-defaults",
         "art_hugepage_defaults",
-        "libart-compiler_deps",
     ],
+    codegen: {
+        arm: {
+            // VIXL assembly support for ARM targets.
+            static_libs: [
+                "libvixl",
+            ],
+        },
+        arm64: {
+            // VIXL assembly support for ARM64 targets.
+            static_libs: [
+                "libvixl",
+            ],
+        },
+    },
     shared_libs: [
-        // libart is not included in libart-compiler_deps to allow libart-compiler(-for-test)
-        // select suitable libart library (either with or without LTO).
         "libart",
+        "libartbase",
+        "libartpalette",
+        "libprofile",
+        "libdexfile",
     ],
+    static_libs: ["libelffile"],
+    runtime_libs: [
+        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
+        // `libart-disassembler.so`.
+        "libart-disassembler",
+    ],
+
     target: {
         android: {
             lto: {
@@ -315,22 +254,6 @@
     ],
 }
 
-// For static linking with gtests. Same as `libart-compiler`, but without LTO.
-// When gtests static link a library with LTO enabled, they are also built with LTO.
-// This makes the build process use a lot of memory. b/277207452
-art_cc_library_static {
-    name: "libart-compiler-for-test",
-    defaults: [
-        "libart-compiler-defaults",
-        "dex2oat-pgo-defaults",
-        "art_hugepage_defaults",
-        "libart-compiler_deps",
-    ],
-    header_libs: [
-        "libart_headers",
-    ],
-}
-
 cc_defaults {
     name: "libart-compiler_static_defaults",
     defaults: [
@@ -344,32 +267,48 @@
     whole_static_libs: ["libart-compiler"],
 }
 
-// libart-compiler_static_defaults for standalone gtests.
-// Uses libart-for-test_static_defaults instead of libart_static_defaults.
-// Uses libart-compiler-for-test instead of libart-compiler.
-cc_defaults {
-    name: "libart-compiler-for-test_static_defaults",
-    defaults: [
-        "libart-compiler_static_base_defaults",
-        "libart-disassembler_static_defaults",
-        "libart-for-test_static_defaults",
-        "libartbase_static_defaults",
-        "libdexfile_static_defaults",
-        "libprofile_static_defaults",
-    ],
-    whole_static_libs: ["libart-compiler-for-test"],
-}
-
 art_cc_library {
     name: "libartd-compiler",
     defaults: [
         "art_debug_defaults",
         "libart-compiler-defaults",
-        "libartd-compiler_deps",
     ],
+    codegen: {
+        arm: {
+            // VIXL assembly support for ARM targets.
+            static_libs: [
+                "libvixld",
+            ],
+            // Export vixl headers as they are included in this library's headers used by tests.
+            export_static_lib_headers: [
+                "libvixld",
+            ],
+        },
+        arm64: {
+            // VIXL assembly support for ARM64 targets.
+            static_libs: [
+                "libvixld",
+            ],
+            // Export vixl headers as they are included in this library's headers used by tests.
+            export_static_lib_headers: [
+                "libvixld",
+            ],
+        },
+    },
     shared_libs: [
+        "libartbased",
         "libartd",
+        "libartpalette",
+        "libprofiled",
+        "libdexfiled",
     ],
+    static_libs: ["libelffiled"],
+    runtime_libs: [
+        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
+        // `libartd-disassembler.so`.
+        "libartd-disassembler",
+    ],
+
     apex_available: [
         "com.android.art.debug",
         // TODO(b/183882457): This lib doesn't go into com.android.art, but
@@ -392,45 +331,42 @@
     whole_static_libs: ["libartd-compiler"],
 }
 
-// libartd-compiler_static_defaults for standalone gtests.
-// Uses libartd-for-test_static_defaults instead of libart_static_defaults.
-cc_defaults {
-    name: "libartd-compiler-for-test_static_defaults",
-    defaults: [
-        "libart-compiler_static_base_defaults",
-        "libartbased_static_defaults",
-        "libartd-disassembler_static_defaults",
-        "libartd-for-test_static_defaults",
-        "libdexfiled_static_defaults",
-        "libprofiled_static_defaults",
-    ],
-    whole_static_libs: ["libartd-compiler"],
-}
-
 // Properties common to `libart-compiler-gtest` and `libartd-compiler-gtest`.
 art_cc_defaults {
     name: "libart-compiler-gtest-common",
     srcs: [
         "common_compiler_test.cc",
     ],
+    shared_libs: [
+        "libbase",
+    ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libart-compiler-gtest",
     defaults: [
         "libart-gtest-defaults",
         "libart-compiler-gtest-common",
-        "libart-compiler-for-test_static_defaults",
+    ],
+    shared_libs: [
+        "libart-compiler",
+        "libart-disassembler",
+        "libartbase-art-gtest",
+        "libart-runtime-gtest",
     ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartd-compiler-gtest",
     defaults: [
-        "art_debug_defaults",
-        "libart-gtest-defaults",
+        "libartd-gtest-defaults",
         "libart-compiler-gtest-common",
-        "libartd-compiler-for-test_static_defaults",
+    ],
+    shared_libs: [
+        "libartd-compiler",
+        "libartd-disassembler",
+        "libartbased-art-gtest",
+        "libartd-runtime-gtest",
     ],
 }
 
@@ -539,6 +475,11 @@
         "libnativehelper_header_only",
     ],
 
+    shared_libs: [
+        "libnativeloader",
+        "libunwindstack",
+    ],
+
     target: {
         host: {
             shared_libs: [
@@ -556,8 +497,15 @@
         "art_gtest_defaults",
         "art_compiler_tests_defaults",
     ],
-    static_libs: [
+    shared_libs: [
+        "libprofiled",
         "libartd-simulator-container",
+        "liblzma",
+    ],
+    static_libs: [
+        "libartd-compiler",
+        "libelffiled",
+        "libvixld",
     ],
 }
 
@@ -569,8 +517,21 @@
         "art_compiler_tests_defaults",
     ],
     data: [":generate-boot-image"],
+    shared_libs: [
+        "libprofile",
+        "liblzma",
+        "libartpalette",
+    ],
     static_libs: [
+        // For now, link `libart-simulator-container` statically for simplicity,
+        // to save the added complexity to package it in test suites (along with
+        // other test artifacts) and install it on device during tests.
+        // TODO(b/192070541): Consider linking `libart-simulator-container`
+        // dynamically.
         "libart-simulator-container",
+        "libart-compiler",
+        "libelffile",
+        "libvixl",
     ],
     test_config: "art_standalone_compiler_tests.xml",
 }
@@ -591,7 +552,7 @@
                 "utils/assembler_thumb_test.cc",
             ],
         },
-        riscv64: {
+        riscv64 : {
             srcs: [
                 "utils/riscv64/assembler_riscv64_test.cc",
             ],
@@ -607,7 +568,12 @@
             ],
         },
     },
+    shared_libs: [
+        "liblzma",
+    ],
     static_libs: [
+        "libartd-compiler",
+        "libelffiled",
         "libvixld",
     ],
 }
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 761b073..7341774 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -440,24 +440,37 @@
     srcs: [
         "common_compiler_driver_test.cc",
     ],
+    shared_libs: [
+        "libart-compiler-gtest",
+        "libart-runtime-gtest",
+        "libart-compiler",
+        "libart-disassembler",
+        "libbase",
+        "liblz4", // libart-dex2oat dependency; must be repeated here since it's a static lib.
+        "liblog",
+    ],
     static_libs: [
         "libart-dex2oat",
-        "libart-gtest",
     ],
 }
 
 art_cc_library_static {
     name: "libartd-dex2oat-gtest",
-    defaults: [
-        "art_debug_defaults",
-        "libart-gtest-defaults",
-    ],
+    defaults: ["libartd-gtest-defaults"],
     srcs: [
         "common_compiler_driver_test.cc",
     ],
+    shared_libs: [
+        "libartd-compiler-gtest",
+        "libartd-runtime-gtest",
+        "libartd-compiler",
+        "libartd-disassembler",
+        "libbase",
+        "liblz4", // libartd-dex2oat dependency; must be repeated here since it's a static lib.
+        "liblog",
+    ],
     static_libs: [
         "libartd-dex2oat",
-        "libartd-gtest",
     ],
 }
 
@@ -543,10 +556,17 @@
         },
     },
 
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
+        "libartpalette",
+        "libbase",
         "libcrypto",
         "liblz4", // libart(d)-dex2oat dependency; must be repeated here since it's a static lib.
         "liblog",
+        "libsigchain",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
 }
 
@@ -558,11 +578,18 @@
         "art_gtest_defaults",
         "art_dex2oat_tests_defaults",
     ],
+    shared_libs: [
+        "libartbased",
+        "libartd-dexlayout",
+        "liblzma",
+        "libprofiled",
+    ],
     static_libs: [
+        "libartd-compiler",
         "libartd-dex2oat",
         "libartd-dex2oat-gtest",
+        "libelffiled",
         "libvixld",
-        "libartd-dexlayout",
     ],
 }
 
@@ -574,11 +601,18 @@
         "art_dex2oat_tests_defaults",
     ],
     data: [":generate-boot-image"],
+    shared_libs: [
+        "libart-dexlayout",
+        "libartbase",
+        "liblzma",
+        "libprofile",
+    ],
     static_libs: [
+        "libart-compiler",
         "libart-dex2oat",
         "libart-dex2oat-gtest",
+        "libelffile",
         "libvixl",
-        "libart-dexlayout",
     ],
     test_config: "art_standalone_dex2oat_tests.xml",
 }
@@ -597,6 +631,12 @@
         ":art-gtest-jars-Nested",
         ":generate-boot-image",
     ],
+    shared_libs: [
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
+    ],
+    static_libs: [
+        "libziparchive",
+    ],
     test_config: "art_standalone_dex2oat_cts_tests.xml",
     test_suites: ["cts"],
 }
diff --git a/dexoptanalyzer/Android.bp b/dexoptanalyzer/Android.bp
index 43953da..82f0c1a 100644
--- a/dexoptanalyzer/Android.bp
+++ b/dexoptanalyzer/Android.bp
@@ -83,8 +83,12 @@
 
 art_cc_defaults {
     name: "art_dexoptanalyzer_tests_defaults",
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
         "libunwindstack",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
     data: [
         ":art-gtest-jars-LinkageTest",
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index 7cd1532..951599d 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -254,10 +254,12 @@
     srcs: [
         "base/common_art_test.cc",
     ],
+    shared_libs: [
+        "libbase",
+        "libunwindstack",
+    ],
     header_libs: [
         "libnativehelper_header_only",
-        // Required for "base/mutex.h" in common_art_test.cc
-        "libart_headers",
     ],
     static: {
         whole_static_libs: [
@@ -273,29 +275,34 @@
     },
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartbase-art-gtest",
     defaults: [
         "libart-gtest-defaults",
         "libartbase-art-gtest-defaults",
-        "libartbase_static_defaults",
-        "libdexfile_static_defaults",
+    ],
+    shared_libs: [
+        "libartbase",
+        "libartbase-testing",
+        "libdexfile",
     ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartbased-art-gtest",
     defaults: [
-        "art_debug_defaults",
-        "libart-gtest-defaults",
+        "libartd-gtest-defaults",
         "libartbase-art-gtest-defaults",
-        "libartbased_static_defaults",
-        "libdexfiled_static_defaults",
+    ],
+    shared_libs: [
+        "libartbased",
+        "libartbased-testing",
+        "libdexfiled",
     ],
 }
 
-art_cc_library_static {
-    name: "libartbase-testing",
+art_cc_defaults {
+    name: "libartbase-testing-defaults",
     defaults: [
         "art_defaults",
     ],
@@ -303,9 +310,35 @@
     srcs: [
         "base/testing.cc",
     ],
-    header_libs: [
-        "libbase_headers",
-        "art_libartbase_headers",
+    shared_libs: [
+        "libbase",
+    ],
+    apex_available: [
+        "com.android.art.debug",
+        // TODO(b/183882457): This lib doesn't go into com.android.art, but
+        // apex_available lists need to be the same for internal libs to avoid
+        // stubs, and this depends on libdexfiled and others.
+        "com.android.art",
+    ],
+}
+
+art_cc_library {
+    name: "libartbase-testing",
+    defaults: [
+        "libartbase-testing-defaults",
+    ],
+    shared_libs: [
+        "libartbase",
+    ],
+}
+
+art_cc_library {
+    name: "libartbased-testing",
+    defaults: [
+        "libartbase-testing-defaults",
+    ],
+    shared_libs: [
+        "libartbased",
     ],
 }
 
@@ -351,6 +384,9 @@
         "base/variant_map_test.cc",
         "base/zip_archive_test.cc",
     ],
+    shared_libs: [
+        "libbase",
+    ],
     static_libs: [
         "libgmock",
     ],
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp
index 301ef89..9ac9091 100644
--- a/libartpalette/Android.bp
+++ b/libartpalette/Android.bp
@@ -111,6 +111,10 @@
 art_cc_defaults {
     name: "art_libartpalette_tests_defaults",
     srcs: ["apex/palette_test.cc"],
+    shared_libs: [
+        "libartpalette",
+        "libnativehelper",
+    ],
     target: {
         android: {
             static_libs: ["libmodules-utils-build"],
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index 9d2a219..9c2acac 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -306,8 +306,12 @@
         ":art-gtest-jars-VerifierDeps",
     ],
     header_libs: ["jni_headers"],
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
         "libunwindstack",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
 }
 
diff --git a/libprofile/Android.bp b/libprofile/Android.bp
index c7e3cb8..beae8a9 100644
--- a/libprofile/Android.bp
+++ b/libprofile/Android.bp
@@ -188,6 +188,12 @@
         "profile/profile_boot_info_test.cc",
         "profile/profile_compilation_info_test.cc",
     ],
+    static_libs: [
+        "libziparchive",
+    ],
+    shared_libs: [
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
+    ],
 }
 
 // Version of ART gtest `art_libprofile_tests` bundled with the ART APEX on target.
@@ -198,6 +204,10 @@
         "art_gtest_defaults",
         "art_libprofile_tests_defaults",
     ],
+    shared_libs: [
+        "libartbased",
+        "libdexfiled",
+    ],
 }
 
 // Standalone version of ART gtest `art_libprofile_tests`, not bundled with the ART APEX on target.
@@ -207,5 +217,9 @@
         "art_standalone_gtest_defaults",
         "art_libprofile_tests_defaults",
     ],
+    shared_libs: [
+        "libartbase",
+        "libdexfile",
+    ],
     test_config: "art_standalone_libprofile_tests.xml",
 }
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp
index 97fec58..809e18d 100644
--- a/odrefresh/Android.bp
+++ b/odrefresh/Android.bp
@@ -207,6 +207,9 @@
         "art_odrefresh_tests_defaults",
     ],
     host_supported: false,
+    shared_libs: [
+        "libdexfiled",
+    ],
     // The test config template is needed even though it's not used by the test
     // runner. Otherwise, Soong will generate a test config, which is adding
     // `art-host-test` as a test tag, while this test does not support running
@@ -222,6 +225,9 @@
         "art_standalone_gtest_defaults",
         "art_odrefresh_tests_defaults",
     ],
+    shared_libs: [
+        "libdexfile",
+    ],
 }
 
 genrule {
diff --git a/profman/Android.bp b/profman/Android.bp
index 7eff771..ac80641 100644
--- a/profman/Android.bp
+++ b/profman/Android.bp
@@ -199,6 +199,9 @@
         "art_gtest_defaults",
         "art_profman_tests_defaults",
     ],
+    shared_libs: [
+        "libprofiled",
+    ],
     target: {
         host: {
             required: ["profmand"],
@@ -214,6 +217,9 @@
         "art_profman_tests_defaults",
     ],
     data: [":generate-boot-image"],
+    shared_libs: [
+        "libprofile",
+    ],
     target: {
         host: {
             required: ["profman"],
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 657076b..1d42ccd 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -87,14 +87,8 @@
     // ART's macros.h depends on libbase's macros.h.
     // Note: runtime_options.h depends on cmdline. But we don't really want to export this
     //       generically. dex2oat takes care of it itself.
-    header_libs: [
-        "art_libartbase_headers",
-        "dlmalloc",
-    ],
-    export_header_lib_headers: [
-        "art_libartbase_headers",
-        "dlmalloc",
-    ],
+    header_libs: ["art_libartbase_headers"],
+    export_header_lib_headers: ["art_libartbase_headers"],
 
     // We optimize Thread::Current() with a direct TLS access. This requires
     // access to a platform specific Bionic header.
@@ -115,23 +109,6 @@
     ],
 }
 
-// Generated headers target required by libart.
-cc_library_headers {
-    name: "libart_generated_headers",
-    defaults: ["art_defaults"],
-    host_supported: true,
-
-    // asm_support_gen.h (used by asm_support.h) is generated with cpp-define-generator
-    generated_headers: ["cpp-define-generator-asm-support"],
-    // export our headers so the libart(d)-gtest targets can use it as well.
-    export_generated_headers: ["cpp-define-generator-asm-support"],
-
-    apex_available: [
-        "com.android.art",
-        "com.android.art.debug",
-    ],
-}
-
 cc_defaults {
     name: "libart_defaults",
     defaults: ["art_defaults"],
@@ -502,23 +479,26 @@
             ],
         },
     },
-    static: {
-        cflags: ["-DART_STATIC_LIBART"],
-    },
+
     generated_sources: [
         "art_operator_srcs",
     ],
+    // asm_support_gen.h (used by asm_support.h) is generated with cpp-define-generator
+    generated_headers: ["cpp-define-generator-asm-support"],
+    // export our headers so the libart(d)-gtest targets can use it as well.
+    export_generated_headers: ["cpp-define-generator-asm-support"],
+
     header_libs: [
         "art_cmdlineparser_headers",
         "cpp-define-generator-definitions",
+        "dlmalloc",
         "jni_platform_headers",
         "libart_headers",
         "libnativehelper_header_only",
-        "libart_generated_headers",
     ],
     export_header_lib_headers: [
+        "dlmalloc",
         "libart_headers",
-        "libart_generated_headers",
     ],
     whole_static_libs: [
         "libcpu_features",
@@ -559,7 +539,9 @@
         "liblz4",
         "liblzma", // libelffile dependency; must be repeated here since it's a static lib.
         "libnativebridge",
+        "libnativeloader",
         "libodrstatslog",
+        "libsigchain_fake",
         "libunwindstack",
         "libz",
     ],
@@ -590,8 +572,6 @@
     whole_static_libs: [
         "libart",
         "libelffile",
-        "libsigchain_fake",
-        "libnativeloader",
     ],
 }
 
@@ -607,43 +587,6 @@
     whole_static_libs: [
         "libartd",
         "libelffiled",
-        "libsigchain_fake",
-        "libnativeloader",
-    ],
-}
-
-// libart_static_defaults for standalone gtests.
-// Doesn't link libsigchain_fake.
-// Uses libart-for-test instead of libart.
-cc_defaults {
-    name: "libart-for-test_static_defaults",
-    defaults: [
-        "libart_static_base_defaults",
-        "libartbase_static_defaults",
-        "libdexfile_static_defaults",
-        "libdexfile_support_static_defaults",
-        "libprofile_static_defaults",
-    ],
-    whole_static_libs: [
-        "libart-for-test",
-        "libelffile",
-    ],
-}
-
-// libartd_static_defaults for gtests.
-// Doesn't link libsigchain_fake.
-cc_defaults {
-    name: "libartd-for-test_static_defaults",
-    defaults: [
-        "libart_static_base_defaults",
-        "libartbased_static_defaults",
-        "libdexfiled_static_defaults",
-        "libdexfiled_support_static_defaults",
-        "libprofiled_static_defaults",
-    ],
-    whole_static_libs: [
-        "libartd",
-        "libelffiled",
     ],
 }
 
@@ -710,6 +653,13 @@
     export_shared_lib_headers: [
         "libdexfile",
     ],
+    target: {
+        android: {
+            lto: {
+                thin: true,
+            },
+        },
+    },
 }
 
 // Release version of the ART runtime library.
@@ -727,13 +677,6 @@
         "test_broken_com.android.art",
     ],
     afdo: true,
-    target: {
-        android: {
-            lto: {
-                thin: true,
-            },
-        },
-    },
 }
 
 // "Broken" version of the ART runtime library, used only for testing.
@@ -753,19 +696,6 @@
     ],
 }
 
-// For static linking with gtests. Same as `libart`, but without LTO.
-// When gtests static link a library with LTO enabled, they are also built with LTO.
-// This makes the build process use a lot of memory. b/277207452
-art_cc_library_static {
-    name: "libart-for-test",
-    defaults: ["libart_common_defaults"],
-    shared_libs: [
-        "libartbase",
-        "libdexfile",
-        "libprofile",
-    ],
-}
-
 // Debug version of the ART runtime library.
 art_cc_library {
     name: "libartd",
@@ -813,30 +743,40 @@
         "common_runtime_test.cc",
         "dexopt_test.cc",
     ],
+    shared_libs: [
+        "libbase",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
+    ],
     static_libs: [
         "libprocinfo",
+        "libziparchive",
     ],
     header_libs: [
         "libnativehelper_header_only",
     ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libart-runtime-gtest",
     defaults: [
         "libart-runtime-gtest-defaults",
         "libart-gtest-defaults",
-        "libart-for-test_static_defaults",
+    ],
+    shared_libs: [
+        "libart",
+        "libartbase-art-gtest",
     ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartd-runtime-gtest",
     defaults: [
-        "art_debug_defaults",
         "libart-runtime-gtest-defaults",
-        "libart-gtest-defaults",
-        "libartd-for-test_static_defaults",
+        "libartd-gtest-defaults",
+    ],
+    shared_libs: [
+        "libartd",
+        "libartbased-art-gtest",
     ],
 }
 
@@ -992,9 +932,11 @@
     ],
     shared_libs: [
         "libunwindstack",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
     static_libs: [
         "libgmock",
+        "libziparchive",
     ],
     header_libs: [
         "art_cmdlineparser_headers", // For parsed_options_test.
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index ecaf679..3d7ba53 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -242,16 +242,7 @@
   return true;
 }
 
-#ifdef ART_STATIC_LIBART
-extern "C" JitCompilerInterface* jit_load();
-#endif
-
 bool Jit::LoadCompilerLibrary(std::string* error_msg) {
-#ifdef ART_STATIC_LIBART
-  (void)error_msg;
-  jit_load_ = &jit_load;
-  return true;
-#else
   jit_library_handle_ = dlopen(
       kIsDebugBuild ? "libartd-compiler.so" : "libart-compiler.so", RTLD_NOW);
   if (jit_library_handle_ == nullptr) {
@@ -265,7 +256,6 @@
     return false;
   }
   return true;
-#endif
 }
 
 bool Jit::CompileMethodInternal(ArtMethod* method,
diff --git a/runtime/monitor-inl.h b/runtime/monitor-inl.h
index 3b1a998..f7e31a0 100644
--- a/runtime/monitor-inl.h
+++ b/runtime/monitor-inl.h
@@ -30,7 +30,7 @@
 }
 
 // Check for request to set lock owner info.
-inline void Monitor::CheckLockOwnerRequest(Thread* self) {
+void Monitor::CheckLockOwnerRequest(Thread* self) {
   DCHECK(self != nullptr);
   Thread* request_thread = lock_owner_request_.load(std::memory_order_relaxed);
   if (request_thread == self) {
@@ -40,13 +40,13 @@
   }
 }
 
-inline uintptr_t Monitor::LockOwnerInfoChecksum(ArtMethod* m, uint32_t dex_pc, Thread* t) {
+uintptr_t Monitor::LockOwnerInfoChecksum(ArtMethod* m, uint32_t dex_pc, Thread* t) {
   uintptr_t dpc_and_thread = static_cast<uintptr_t>(dex_pc << 8) ^ reinterpret_cast<uintptr_t>(t);
   return reinterpret_cast<uintptr_t>(m) ^ dpc_and_thread
       ^ (dpc_and_thread << (/* ptr_size / 2 */ (sizeof m) << 2));
 }
 
-inline void Monitor::SetLockOwnerInfo(ArtMethod* method, uint32_t dex_pc, Thread* t) {
+void Monitor::SetLockOwnerInfo(ArtMethod* method, uint32_t dex_pc, Thread* t) {
   lock_owner_method_.store(method, std::memory_order_relaxed);
   lock_owner_dex_pc_.store(dex_pc, std::memory_order_relaxed);
   lock_owner_.store(t, std::memory_order_relaxed);
@@ -54,9 +54,8 @@
   lock_owner_sum_.store(sum, std::memory_order_relaxed);
 }
 
-inline void Monitor::GetLockOwnerInfo(/*out*/ ArtMethod** method,
-                                      /*out*/ uint32_t* dex_pc,
-                                      Thread* t) {
+void Monitor::GetLockOwnerInfo(/*out*/ArtMethod** method, /*out*/uint32_t* dex_pc,
+                               Thread* t) {
   ArtMethod* owners_method;
   uint32_t owners_dex_pc;
   Thread* owner;
@@ -80,6 +79,7 @@
   }
 }
 
+
 }  // namespace art
 
 #endif  // ART_RUNTIME_MONITOR_INL_H_
diff --git a/simulator/Android.bp b/simulator/Android.bp
index 043a1bc..d29319a 100644
--- a/simulator/Android.bp
+++ b/simulator/Android.bp
@@ -83,24 +83,34 @@
     srcs: [
         "code_simulator_container.cc",
     ],
-    header_libs: [
-        "libart_simulator_headers",
-        "libbase_headers",
-        "libart_headers",
-        "art_libartbase_headers",
+    shared_libs: [
+        "libbase",
     ],
+
+    header_libs: ["libart_simulator_headers"],
     export_include_dirs: ["."], // TODO: Consider a proper separation.
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libart-simulator-container",
     defaults: ["libart_simulator_container_defaults"],
+    shared_libs: [
+        "libartbase",
+        "libart",
+    ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartd-simulator-container",
     defaults: [
         "art_debug_defaults",
         "libart_simulator_container_defaults",
     ],
+    shared_libs: [
+        "libartbased",
+        "libartd",
+    ],
+    apex_available: [
+        "com.android.art.debug",
+    ],
 }
diff --git a/test/Android.bp b/test/Android.bp
index efff429..836beb8 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -65,10 +65,6 @@
             ],
         },
     },
-    // Reduce test executable size by disabling automatic export of static lib symbols.
-    ldflags: [
-        "-Wl,--exclude-libs=ALL",
-    ],
 }
 
 art_module_cc_defaults {
@@ -208,33 +204,12 @@
     gtest: false,
 
     shared_libs: [
-        // `libsigchain` must be shared for art_standalone_libsigchain_tests to work.
-        "libsigchain",
-        // `libnativeloader` must be shared, otherwise host gtests can't load libraries from
-        // "art_common/out/host", which is present in `libnativeloader` RUNPATH.
-        // TODO(b/247108425): modify gtests RUNPATH so that `libnativeloader` can be static linked.
-        "libnativeloader",
-
-        // `libart(d)` (`art/runtime/jni/java_vm_ext.cc`) and `libnativehelper`
-        // (`libnativehelper/JniInvocation.c`) define symbols with the same name
-        // (e.g. `JNI_GetDefaultJavaVMInitArgs`).
-        // `JavaVmExtTest#*` tests require `libart(d)` implementation of these symbols.
-        // At the moment `libart(d)` is linked statically (through `libart(d)-gtest`)
-        // and these symbols are correctly resolved to `libart(d)`.
-        // If `libnativehelper` and `libart(d)` are both linked dynamically,
-        // `libart(d)` must be specified in shared_libs list before `libnativehelper`,
-        // so that its symbols have precedence over `libnativehelper`.
-        "libnativehelper",
+        "libbase",
+        "liblog",
+        "libz",
     ],
+
     target: {
-        android: {
-            shared_libs: [
-                // Dependencies of `libart(d)`, that are not included in *static_defaults.
-                "libdl_android",
-                "libstatssocket",
-                "heapprofd_client_api",
-            ],
-        },
         linux: {
             ldflags: [
                 // Allow jni_compiler_test to find Java_MyClassNatives_bar
@@ -252,15 +227,15 @@
             ],
         },
         host: {
+            shared_libs: [
+                "libziparchive",
+            ],
             cflags: [
                 "-fsanitize-address-use-after-return=never",
                 "-Wno-unused-command-line-argument",
             ],
         },
     },
-    static_libs: [
-        "libartbase-testing",
-    ],
 }
 
 art_cc_defaults {
@@ -270,12 +245,33 @@
         "art_gtest_common_defaults",
         "art_debug_defaults",
     ],
+
     test_suites: ["art-host-tests"],
     test_options: {
         test_suite_tag: ["art-host-gtest"],
     },
-    static_libs: [
+
+    shared_libs: [
+        "libartd",
+        "libartd-disassembler",
         "libartd-gtest",
+        "libdexfiled",
+        "libprofiled",
+        "libartbased",
+        "libartbased-testing",
+
+        // Library `libnativehelper` needs to appear after `libartd` here,
+        // otherwise the following tests from module `libartd-runtime-gtest`
+        // will fail because `art/runtime/jni/java_vm_ext.cc` and
+        // `libnativehelper/JniInvocation.c` define symbols with the same name
+        // (e.g. `JNI_GetDefaultJavaVMInitArgs`) and the link order does matter
+        // for these tests:
+        // - JavaVmExtTest#JNI_GetDefaultJavaVMInitArgs
+        // - JavaVmExtTest#JNI_GetCreatedJavaVMs
+        // - JavaVmExtTest#AttachCurrentThread
+        // - JavaVmExtTest#AttachCurrentThreadAsDaemon
+        // - JavaVmExtTest#AttachCurrentThread_SmallStack
+        "libnativehelper",
     ],
 }
 
@@ -289,10 +285,12 @@
         "art_standalone_test_defaults",
         "art_gtest_common_defaults",
     ],
+
     test_suites: [
         "general-tests",
         "mts-art",
     ],
+
     // Support multilib variants (using different suffix per sub-architecture), which is needed on
     // build targets with secondary architectures, as the MTS test suite packaging logic flattens
     // all test artifacts into a single `testcases` directory.
@@ -305,17 +303,49 @@
             suffix: "64",
         },
     },
-    static_libs: [
-        "libart-gtest",
+
+    // We use the "non-d" variants of libraries, as the Release ART APEX does
+    // not contain the "d" (debug) variants.
+    shared_libs: [
+        "libart",
+        "libart-compiler",
+        "libart-disassembler",
+        "libdexfile",
+        "libprofile",
+        "libartbase",
+
+        // Library `libnativehelper` needs to appear after `libart` here,
+        // otherwise the following tests from module `libart-runtime-gtest`
+        // will fail because `art/runtime/jni/java_vm_ext.cc` and
+        // `libnativehelper/JniInvocation.c` define symbols with the same name
+        // (e.g. `JNI_GetDefaultJavaVMInitArgs`) and the link order does matter
+        // for these tests:
+        // - JavaVmExtTest#JNI_GetDefaultJavaVMInitArgs
+        // - JavaVmExtTest#JNI_GetCreatedJavaVMs
+        // - JavaVmExtTest#AttachCurrentThread
+        // - JavaVmExtTest#AttachCurrentThreadAsDaemon
+        // - JavaVmExtTest#AttachCurrentThread_SmallStack
+        "libnativehelper",
     ],
+    static_libs: [
+        // For now, link `libart-gtest` and `libartbase-testing` statically for
+        // simplicity, to save the added complexity to package it in test suites
+        // (along with other test artifacts) and install it on device during
+        // tests.
+        // TODO(b/192070541): Consider linking `libart-gtest` dynamically.
+        "libart-gtest",
+        "libartbase-testing",
+    ],
+
     test_for: [
         "com.android.art",
         "com.android.art.debug",
     ],
 }
 
+// Properties common to `libart-gtest-defaults` and `libartd-gtest-defaults`.
 art_cc_defaults {
-    name: "libart-gtest-defaults",
+    name: "libart-gtest-common-defaults",
     defaults: [
         "art_defaults",
     ],
@@ -351,6 +381,43 @@
             enabled: false,
         },
     },
+    apex_available: [
+        "com.android.art.debug",
+        // TODO(b/183882457): This lib doesn't go into com.android.art, but
+        // apex_available lists need to be the same for internal libs to avoid
+        // stubs, and this depends on libdexfiled and others.
+        "com.android.art",
+        "test_broken_com.android.art",
+    ],
+}
+
+art_cc_defaults {
+    name: "libart-gtest-defaults",
+    defaults: [
+        "libart-gtest-common-defaults",
+    ],
+    shared_libs: [
+        "libart",
+        "libart-compiler",
+        "libdexfile",
+        "libprofile",
+        "libartbase",
+    ],
+}
+
+art_cc_defaults {
+    name: "libartd-gtest-defaults",
+    defaults: [
+        "art_debug_defaults",
+        "libart-gtest-common-defaults",
+    ],
+    shared_libs: [
+        "libartd",
+        "libartd-compiler",
+        "libdexfiled",
+        "libprofiled",
+        "libartbased",
+    ],
 }
 
 // Properties common to `libart-gtest` and `libartd-gtest`.
@@ -367,6 +434,7 @@
         "libgtest_isolated",
     ],
     shared_libs: [
+        "libbase",
         "liblog",
     ],
     target: {
@@ -380,9 +448,17 @@
             enabled: false,
         },
     },
+    apex_available: [
+        "com.android.art.debug",
+        // TODO(b/183882457): This lib doesn't go into com.android.art, but
+        // apex_available lists need to be the same for internal libs to avoid
+        // stubs, and this depends on libdexfiled and others.
+        "com.android.art",
+        "test_broken_com.android.art",
+    ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libart-gtest",
     defaults: [
         "libart-gtest-common",
@@ -392,9 +468,17 @@
         "libart-runtime-gtest",
         "libartbase-art-gtest",
     ],
+    shared_libs: [
+        "libart",
+        "libart-compiler",
+        "libdexfile",
+        "libprofile",
+        "libartbase",
+        "libartbase-testing",
+    ],
 }
 
-art_cc_library_static {
+art_cc_library {
     name: "libartd-gtest",
     defaults: [
         "art_debug_defaults",
@@ -405,6 +489,14 @@
         "libartd-runtime-gtest",
         "libartbased-art-gtest",
     ],
+    shared_libs: [
+        "libartd",
+        "libartd-compiler",
+        "libdexfiled",
+        "libprofiled",
+        "libartbased",
+        "libartbased-testing",
+    ],
 }
 
 // ART run-tests.
@@ -660,7 +752,7 @@
         "2005-pause-all-redefine-multithreaded/pause-all.cc",
         "2009-structural-local-ref/local-ref.cc",
         "2035-structural-native-method/structural-native.cc",
-        "2243-single-step-default/single_step_helper.cc",
+	"2243-single-step-default/single_step_helper.cc"
     ],
     // Use NDK-compatible headers for ctstiagent.
     header_libs: [
@@ -899,7 +991,7 @@
         "2040-huge-native-alloc/huge_native_buf.cc",
         "2048-bad-native-registry/native_finalizer.cc",
         "2235-JdkUnsafeTest/unsafe_test.cc",
-        "2262-miranda-methods/jni_invoke.cc",
+	"2262-miranda-methods/jni_invoke.cc",
         "common/runtime_state.cc",
         "common/stack_inspect.cc",
     ],
diff --git a/tools/art_verifier/Android.bp b/tools/art_verifier/Android.bp
index 19498e0..5d19215 100644
--- a/tools/art_verifier/Android.bp
+++ b/tools/art_verifier/Android.bp
@@ -59,8 +59,6 @@
     defaults: [
         "art_verifier-defaults",
         "libart_static_defaults",
-        // TODO(b/186902856): remove once libart-compiler is merged into libart
-        "libart-compiler_static_defaults",
     ],
 }
 
@@ -70,7 +68,5 @@
         "art_debug_defaults",
         "art_verifier-defaults",
         "libartd_static_defaults",
-        // TODO(b/186902856): remove once libart-compiler is merged into libart
-        "libartd-compiler_static_defaults",
     ],
 }
diff --git a/tools/fuzzer/Android.bp b/tools/fuzzer/Android.bp
index c3f35d2..0d99943 100644
--- a/tools/fuzzer/Android.bp
+++ b/tools/fuzzer/Android.bp
@@ -30,8 +30,6 @@
     defaults: [
         // Run in release mode since debug is too slow.
         "libart_static_defaults",
-        // TODO(b/186902856): remove once libart-compiler is merged into libart
-        "libart-compiler_static_defaults",
         // To allow the ART module to build correctly.
         "art_module_source_build_defaults",
     ],
@@ -52,10 +50,7 @@
     dictionary: "dex.dict",
     fuzz_config: {
         triage_assignee: "art-perf-team@google.com",
-        cc: [
-            "solanes@google.com",
-            "art-bugs@google.com",
-        ],
+        cc: ["solanes@google.com", "art-bugs@google.com"],
         componentid: 86431,
         acknowledgement: [
             "Santiago Aboy Solanes of Google",