Fix duplicate and dangling rules

I6730e2d3ec38004874265b2a690442dec57b33f4 introduced duplicate rules
to build classes.jar for static java library prebuilts, and left rules
to copy $(built_dex_intermediates) to $(built_dex) for modules that
don't build dex files.

Move prebuilts LOCAL_BUILT_MODULE back to javalib.jar to match
non-prebuilt modules, and remove the manual building of javalib.jar.

Add a check around $(built_dex_intermediates) for static java libraries.

Bug: 36901093
Test: m -j ANDROID_COMPILE_WITH_JACK=false
Change-Id: I291510b56162f0d35553e3c7ccd59b1382224d62
diff --git a/core/java.mk b/core/java.mk
index 009d807..bbbec0a 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -629,6 +629,7 @@
 
 $(call define-jar-to-toc-rule, $(full_classes_jar))
 
+ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
 ifndef LOCAL_JACK_ENABLED
 $(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
 # If you instrument class files that have local variable debug information in
@@ -650,6 +651,8 @@
 	$(hide) rm -f $(dir $@)/classes*.dex
 	$(hide) cp -fp $(dir $<)/classes*.dex $(dir $@)
 
+endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
+
 findbugs_xml := $(intermediates.COMMON)/findbugs.xml
 $(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
     $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
diff --git a/core/multi_prebuilt.mk b/core/multi_prebuilt.mk
index c53d755..77c57ab 100644
--- a/core/multi_prebuilt.mk
+++ b/core/multi_prebuilt.mk
@@ -116,7 +116,7 @@
     $(prebuilt_module_tags), \
     , \
     , \
-    $(if $(prebuilt_is_host),classes.jar,javalib.jar))
+    javalib.jar)
 
 $(call auto-prebuilt-boilerplate, \
     $(prebuilt_static_java_libraries), \
@@ -125,7 +125,7 @@
     $(prebuilt_module_tags), \
     , \
     true, \
-    classes.jar)
+    javalib.jar)
 
 prebuilt_static_libs :=
 prebuilt_shared_libs :=
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index de44369..6b16f73 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -438,16 +438,12 @@
 # for host java libraries deps should be in the common dir, so we make a copy in
 # the common dir.
 common_classes_jar := $(intermediates.COMMON)/classes.jar
-common_javalib_jar := $(intermediates.COMMON)/javalib.jar
 
-$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
+$(common_classes_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
 
 $(common_classes_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
 
-$(common_javalib_jar) : $(common_classes_jar)
-	$(transform-prebuilt-to-target)
-
 else # !LOCAL_IS_HOST_MODULE
 # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
 # while the deps should be in the common dir, so we make a copy in the common dir.