Untwist the target/host shared library dependencies.

Before this, if there are duplicate module names in both the host and
target spaces, LOCAL_SHARED_LIBRARIES results in mixed dependencies.

Bug: 7026946
Change-Id: I5407e3d078a8903c94978cc6d3e256851c52340f
diff --git a/core/binary.mk b/core/binary.mk
index c136a00..18f67fe 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -102,14 +102,20 @@
   installed_shared_library_module_names := \
       $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)
 endif
-# The real dependency will be added after all Android.mks are loaded and the install paths
-# of the shared libraries are determined.
-LOCAL_REQUIRED_MODULES += $(installed_shared_library_module_names)
+installed_shared_library_module_names := $(sort $(installed_shared_library_module_names))
 
 #######################################
 include $(BUILD_SYSTEM)/base_rules.mk
 #######################################
 
+# The real dependency will be added after all Android.mks are loaded and the install paths
+# of the shared libraries are determined.
+ifdef LOCAL_INSTALLED_MODULE
+ifdef installed_shared_library_module_names
+$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += $(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
+endif
+endif
+
 ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
   LOCAL_CLANG := true
   LOCAL_CFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)