Do not link libziparchive both statically and dynamically in libartbase
and libprofile.

For the sake of consistency, switch to linking it statically everywhere
on device, even in tests. This allows dropping libziparchive.so from
the APEX.

Also clean up some other Soong properties that were duplicated in
libartbase vs libartbased, and libprofile vs libprofiled.

Test: art/build/apex/runtests.sh
Test: gtests on host and target
Bug: 261402130
Change-Id: Iec03fa1da3cf64edc817b14c491493a63c423f6e
diff --git a/Android.mk b/Android.mk
index bfe1376..d560276 100644
--- a/Android.mk
+++ b/Android.mk
@@ -471,7 +471,6 @@
   lib/libprofile.so \
   lib/libsigchain.so \
   lib/libunwindstack.so \
-  lib/libziparchive.so \
   lib64/libadbconnection.so \
   lib64/libandroidio.so \
   lib64/libartbase.so \
@@ -500,7 +499,6 @@
   lib64/libprofile.so \
   lib64/libsigchain.so \
   lib64/libunwindstack.so \
-  lib64/libziparchive.so \
 
 PRIVATE_RUNTIME_APEX_DEPENDENCY_FILES := \
   bin/linker \
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 41b587f..6e58cf6 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -520,7 +520,6 @@
     self._checker.check_native_library('liblzma')
     self._checker.check_native_library('libnpt')
     self._checker.check_native_library('libunwindstack')
-    self._checker.check_native_library('libziparchive')
 
     # Allow extra dependencies that appear in ASAN builds.
     self._checker.check_optional_native_library('libclang_rt.asan*')
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 5f7735f..2f7d2f1 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -554,6 +554,9 @@
         },
     },
 
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
         "libartpalette",
         "libbase",
@@ -561,7 +564,7 @@
         "liblz4", // libart(d)-dex2oat dependency; must be repeated here since it's a static lib.
         "liblog",
         "libsigchain",
-        "libziparchive",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
 }
 
@@ -626,6 +629,9 @@
         ":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",
diff --git a/dexoptanalyzer/Android.bp b/dexoptanalyzer/Android.bp
index 66b0901..82f0c1a 100644
--- a/dexoptanalyzer/Android.bp
+++ b/dexoptanalyzer/Android.bp
@@ -83,9 +83,12 @@
 
 art_cc_defaults {
     name: "art_dexoptanalyzer_tests_defaults",
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
         "libunwindstack",
-        "libziparchive",
+        "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 f2f71cc..a7bb641 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -207,13 +207,11 @@
         "com.android.art.debug",
     ],
 
-    shared_libs: [
-        "libbase",
-        "libziparchive",
-    ],
-    export_shared_lib_headers: ["libbase"],
     target: {
         windows: {
+            // Control the enabled property here rather than in
+            // libartbase_defaults, to ensure it overrides properties inherited
+            // from other defaults.
             enabled: true,
             shared: {
                 enabled: false,
@@ -232,13 +230,13 @@
     apex_available: [
         "com.android.art.debug",
     ],
-    shared_libs: [
-        "libbase",
-        "libziparchive",
-    ],
-    export_shared_lib_headers: ["libbase"],
+
     target: {
         windows: {
+            // Control the enabled property here rather than in
+            // libartbase_defaults, to ensure it overrides properties inherited
+            // from other defaults, in particular any inherited via
+            // art_debug_defaults.
             enabled: true,
             shared: {
                 enabled: false,
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index b5a411b..9d9d8ce 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -293,9 +293,12 @@
         ":art-gtest-jars-Nested",
     ],
     header_libs: ["jni_headers"],
+    static_libs: [
+        "libziparchive",
+    ],
     shared_libs: [
         "libunwindstack",
-        "libziparchive",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
 }
 
diff --git a/libprofile/Android.bp b/libprofile/Android.bp
index ecbcd0b..55bdcd1 100644
--- a/libprofile/Android.bp
+++ b/libprofile/Android.bp
@@ -106,11 +106,6 @@
         "libprofile_defaults",
         "libart_nativeunwind_defaults",
     ],
-    shared_libs: [
-        "libbase",
-        "libziparchive",
-    ],
-    export_shared_lib_headers: ["libbase"],
     target: {
         android: {
             shared_libs: [
@@ -147,10 +142,6 @@
         "art_debug_defaults",
         "libprofile_defaults",
     ],
-    shared_libs: [
-        "libbase",
-        "libziparchive",
-    ],
     target: {
         android: {
             shared_libs: [
@@ -171,7 +162,6 @@
             ],
         },
     },
-    export_shared_lib_headers: ["libbase"],
     apex_available: [
         "com.android.art.debug",
         // TODO(b/183882457): This lib doesn't go into com.android.art, but
@@ -195,9 +185,12 @@
         "profile/profile_boot_info_test.cc",
         "profile/profile_compilation_info_test.cc",
     ],
-    shared_libs: [
+    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.
diff --git a/runtime/Android.bp b/runtime/Android.bp
index f3f5caa..166c342 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -710,10 +710,11 @@
     ],
     shared_libs: [
         "libbase",
-        "libziparchive",
+        "libz", // libziparchive dependency; must be repeated here since it's a static lib.
     ],
     static_libs: [
         "libprocinfo",
+        "libziparchive",
     ],
     header_libs: [
         "libnativehelper_header_only",
@@ -894,10 +895,11 @@
     ],
     shared_libs: [
         "libunwindstack",
-        "libziparchive",
+        "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.