Allow LOCAL_RESOURCE_DIR pointing to dir generated during the build

Bug: 15850610
Change-Id: I46b98adb556d8e6bf166761f8bb240006dbe5b14
This commit is contained in:
Ying Wang 2014-06-25 13:23:58 -07:00
parent e69d4350cd
commit 6129192ed6
2 changed files with 18 additions and 9 deletions

View file

@ -82,8 +82,12 @@ ifeq (,$(LOCAL_ASSET_DIR))
LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
endif
# LOCAL_RESOURCE_DIR may point to resource generated during the build
need_compile_res :=
ifeq (,$(LOCAL_RESOURCE_DIR))
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
else
need_compile_res := true
endif
package_resource_overlays := $(strip \
@ -106,6 +110,10 @@ all_resources := $(strip \
) \
))
ifneq ($(all_resources),)
need_compile_res := true
endif
all_res_assets := $(strip $(all_assets) $(all_resources))
package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
@ -114,7 +122,7 @@ package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
ifeq (,$(all_assets))
LOCAL_ASSET_DIR:=
endif
ifeq (,$(all_resources))
ifneq (true,$(need_compile_res))
LOCAL_RESOURCE_DIR:=
R_file_stamp :=
else
@ -139,9 +147,9 @@ ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
endif
proguard_options_file :=
ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
ifneq ($(all_resources),)
ifeq ($(need_compile_res),true)
proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
endif # all_resources
endif # need_compile_res
endif # !custom
LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
@ -196,7 +204,7 @@ $(LOCAL_INTERMEDIATE_TARGETS): \
PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
endif
ifneq ($(all_resources),)
ifeq ($(need_compile_res),true)
# Since we don't know where the real R.java file is going to end up,
# we need to use another file to stand in its place. We'll just
@ -265,7 +273,7 @@ ifneq ($(full_classes_jar),)
$(full_classes_compiled_jar): $(R_file_stamp)
endif
endif # all_resources
endif # need_compile_res
ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
# We need to explicitly clear this var so that we don't

View file

@ -26,7 +26,10 @@ LOCAL_MODULE_CLASS := JAVA_LIBRARIES
# Hack to build static Java library with Android resource
# See bug 5714516
all_resources :=
need_compile_res :=
# A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
ifdef LOCAL_RESOURCE_DIR
need_compile_res := true
all_resources := $(strip \
$(foreach dir, $(LOCAL_RESOURCE_DIR), \
$(addprefix $(dir)/, \
@ -36,7 +39,6 @@ all_resources := $(strip \
) \
))
ifneq (,$(all_resources))
# By default we should remove the R/Manifest classes from a static Java library,
# because they will be regenerated in the app that uses it.
# But if the static Java library will be used by a library, then we may need to
@ -56,14 +58,13 @@ ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
endif
LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
endif # all_resources
endif # LOCAL_RESOURCE_DIR
all_res_assets := $(all_resources)
include $(BUILD_SYSTEM)/java_library.mk
ifneq (,$(all_resources))
ifeq (true,$(need_compile_res))
R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp
ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
@ -124,7 +125,7 @@ ifneq ($(full_classes_jar),)
$(full_classes_compiled_jar): $(R_file_stamp)
endif
endif # $(all_resources) not empty
endif # need_compile_res
# Reset internal variables.
all_res_assets :=