Forbid depending directly on SDK modules.

They should be depended on by specifying LOCAL_SDK_VERSION. Depending
on them directly makes it difficult to rename or modify these targets,
as I've found when working on b/77525052.

This list can be further extended to other libraries that should not
be depended on directly.

Bug: b/77525052
Test: make
Change-Id: I911bcc8a5a90995b3607599388dc6119eb88ea96
diff --git a/core/java_common.mk b/core/java_common.mk
index 9fd6bfe..2695aff 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -225,6 +225,15 @@
 
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
 
+# Sanity check class path vars.
+disallowed_deps := $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),$(call resolve-prebuilt-sdk-module,$(sdk)))
+disallowed_deps += $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),\
+  $(foreach sdk_lib,$(JAVA_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,$(sdk),$(sdk_lib))))
+bad_deps := $(filter $(disallowed_deps),$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
+ifneq (,$(bad_deps))
+  $(call pretty-error,SDK modules should not be depended on directly. Please use LOCAL_SDK_VERSION for $(bad_deps))
+endif
+
 full_java_bootclasspath_libs :=
 empty_bootclasspath :=
 my_system_modules :=