Fix dependency when switching between build variants with and without Proguard.

With this change, in a user build the dependency looks like:
package.apk -> progaurd.classes.dex -> ... -> proguard.classes.jar
While in an eng build:
package.apk -> noproguard.classes.dex -> ... -> noproguard.classes.jar

Because package.apk is product-specific and removed when switching between
user and eng builds, it can always be built with the correct and up-to-date .dex file.

Bug: 3022484

Change-Id: I3a732cb3e256f193088c294dc4a0573188283cb2
diff --git a/core/definitions.mk b/core/definitions.mk
index 6f7a05b..09ab96a 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1395,7 +1395,12 @@
 
 #TODO: update the manifest to point to the dex file
 define add-dex-to-package
-$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE)
+$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
+$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\
+$(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\
+$(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \
+$(AAPT) add -k $@ $(_adtp_classes.dex) && \
+rm -f $(_adtp_classes.dex))
 endef
 
 define add-java-resources-to-package