Allow libz to be statically linked from APEXes

libz is in a special position in NDK. Read the comment around the code
for more detail.

Bug: 389067742
Test: add `static_libs: ["libz"]` to a random APEX
Change-Id: Ib4241df7880fcad386dd4530fea0bbc4b3f1e1c5
diff --git a/apex/apex.go b/apex/apex.go
index 428d57e..d98cfae 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2570,7 +2570,7 @@
 			fromName := ctx.OtherModuleName(from)
 			toName := ctx.OtherModuleName(to)
 
-			// The dynamic linker and crash_dump tool in the runtime APEX is the only
+			// The dynamic linker and crash_dump tool in the runtime APEX is an
 			// exception to this rule. It can't make the static dependencies dynamic
 			// because it can't do the dynamic linking for itself.
 			// Same rule should be applied to linkerconfig, because it should be executed
@@ -2579,6 +2579,15 @@
 				return false
 			}
 
+			// b/389067742 adds libz as an exception to this check. Although libz is
+			// a part of NDK and thus provides a stable interface, it never was the
+			// intention because the upstream zlib provides neither ABI- nor behavior-
+			// stability. Therefore, we want to allow portable components like APEXes to
+			// bundle libz by statically linking to it.
+			if toName == "libz" {
+				return false
+			}
+
 			isStubLibraryFromOtherApex := info.HasStubsVariants && !librariesDirectlyInApex[toName]
 			if isStubLibraryFromOtherApex && !externalDep {
 				ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+