Fix dependency of prebuilt target non-static Java libraries.

Change-Id: I498b96ce737e5fc9076de39108252284ee53218f
diff --git a/core/ b/core/
index b4717e0..f5eebc8 100644
--- a/core/
+++ b/core/
@@ -45,10 +45,20 @@
 # 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.
-common_library_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/$(notdir $(LOCAL_BUILT_MODULE))
-$(common_library_jar) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ACP)
+# For nonstatic library, $(common_javalib_jar) is the dependency file,
+# while $(common_classes_jar) is used to link.
+common_classes_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/classes.jar
+common_javalib_jar := $(dir $(common_classes_jar))javalib.jar
+$(common_classes_jar) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ACP)
+$(common_javalib_jar) : $(common_classes_jar) | $(ACP)
+	$(transform-prebuilt-to-target)
+# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
+$(LOCAL_BUILT_MODULE) : $(common_javalib_jar)
   # The magic string "EXTERNAL" means this package will be signed with