Better handle of need_compile_java.

Change-Id: I609a27e2b35b08962243b6516c6c525c0c938d3c
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 3d5f51d..33bc6fd 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -353,8 +353,11 @@
 endif # java_resource_file_groups
 
 ## PRIVATE java vars ######################################
-
-ifneq ($(strip $(all_java_sources)$(all_res_assets))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)),)
+# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
+# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
+# You have to set up the dependency in some other way.
+need_compile_java := $(strip $(all_java_sources)$(all_res_assets))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED))
+ifdef need_compile_java
 
 full_static_java_libs := \
     $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
@@ -449,7 +452,7 @@
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
 endif
 
-endif  # PRIVATE java vars
+endif  # need_compile_java
 
 
 ###########################################################
@@ -547,20 +550,16 @@
 ## CHECK_BUILD goals
 ###########################################################
 
+ifdef java_alternative_checked_module
+  LOCAL_CHECKED_MODULE := $(java_alternative_checked_module)
+endif
+
 # If nobody has defined a more specific module for the
 # checked modules, use LOCAL_BUILT_MODULE.
 ifndef LOCAL_CHECKED_MODULE
   LOCAL_CHECKED_MODULE := $(LOCAL_BUILT_MODULE)
 endif
 
-need_compile_java :=
-ifdef java_alternative_checked_module
-ifneq (,$(strip $(all_java_sources)$(full_static_java_libs))$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)))
-  need_compile_java := true
-  LOCAL_CHECKED_MODULE := $(java_alternative_checked_module)
-endif
-endif
-
 # If they request that this module not be checked, then don't.
 # PLEASE DON'T SET THIS.  ANY PLACES THAT SET THIS WITHOUT
 # GOOD REASON WILL HAVE IT REMOVED.
diff --git a/core/java.mk b/core/java.mk
index 1c4558f..4814a9a 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -12,16 +12,6 @@
 endif # !PDK_JAVA
 endif #PDK
 
-
-# Make sure there's something to build.
-# It's possible to build a package that doesn't contain any classes.
-# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
-# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
-# You have to set up the dependency in some other way.
-ifeq (,$(strip $(LOCAL_SRC_FILES)$(all_res_assets)$(LOCAL_STATIC_JAVA_LIBRARIES))$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)))
-$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
-endif
-
 LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
 LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
 
@@ -117,9 +107,14 @@
 built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)
 full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
 
-# full_classes_jar and built_dex are cleared below, and re-set if we really need them.
+ifeq ($(LOCAL_EXPORT_PACKAGE_RESOURCES),true)
+# This is framework-res, we don't need to compile any Java code.
+full_classes_jar :=
+built_dex :=
+else
 full_classes_jar := $(intermediates.COMMON)/classes.jar
 built_dex := $(intermediates.COMMON)/$(built_dex_leaf)
+endif
 
 LOCAL_INTERMEDIATE_TARGETS += \
     $(full_classes_compiled_jar) \
@@ -248,7 +243,11 @@
 # to fail except for bugs in their respective tools.  If you would
 # like to run these rules, add the "all" modifier goal to the make
 # command line.
+ifdef full_classes_jar
 java_alternative_checked_module := $(full_classes_compiled_jar)
+else
+java_alternative_checked_module :=
+endif
 
 # TODO: It looks like the only thing we need from base_rules is
 # all_java_sources.  See if we can get that by adding a
@@ -261,6 +260,13 @@
 
 java_alternative_checked_module :=
 
+# Make sure there's something to build.
+ifdef full_classes_jar
+ifndef need_compile_java
+$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
+endif
+endif
+
 # Install the RS compatibility libraries to /system/lib/ if necessary
 ifdef rs_compatibility_jni_libs
 installed_rs_compatibility_jni_libs := $(addprefix $(TARGET_OUT_SHARED_LIBRARIES)/,\
@@ -296,11 +302,7 @@
 # properly.
 $(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
 
-# If the module includes java code (i.e., it's not framework-res), compile it.
-full_classes_jar :=
-built_dex :=
-# need_compile_java is set in base_rules.mk
-ifeq ($(need_compile_java),true)
+ifdef full_classes_jar
 
 # If LOCAL_BUILT_MODULE_STEM wasn't overridden by our caller,
 # full_classes_jar will be the same module as LOCAL_BUILT_MODULE.
@@ -505,4 +507,4 @@
 
 $(LOCAL_MODULE)-findbugs : $(findbugs_html)
 
-endif
+endif  # full_classes_jar is defined
diff --git a/core/package.mk b/core/package.mk
index ff202cb..fd72cce 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -480,3 +480,6 @@
 lintall : lint-$(LOCAL_PACKAGE_NAME)
 
 endif # skip_definition
+
+# Reset internal variables.
+all_res_assets :=
diff --git a/core/static_java_library.mk b/core/static_java_library.mk
index cdb98f0..f95a382 100644
--- a/core/static_java_library.mk
+++ b/core/static_java_library.mk
@@ -126,4 +126,6 @@
 
 endif  # $(all_resources) not empty
 
+# Reset internal variables.
+all_res_assets :=
 LOCAL_IS_STATIC_JAVA_LIBRARY :=