Home | History | Annotate | Download | only in core
      1 #
      2 # Copyright (C) 2008 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 #
     16 
     17 # Standard rules for building a "static" java library.
     18 # Static java libraries are not installed, nor listed on any
     19 # classpaths.  They can, however, be included wholesale in
     20 # other java modules.
     21 
     22 LOCAL_UNINSTALLABLE_MODULE := true
     23 LOCAL_IS_STATIC_JAVA_LIBRARY := true
     24 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
     25 
     26 #################################
     27 include $(BUILD_SYSTEM)/configure_local_jack.mk
     28 #################################
     29 
     30 intermediates.COMMON := $(call local-intermediates-dir,COMMON)
     31 
     32 my_res_package :=
     33 
     34 # Hack to build static Java library with Android resource
     35 # See bug 5714516
     36 all_resources :=
     37 need_compile_res :=
     38 # A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
     39 ifdef LOCAL_RESOURCE_DIR
     40 need_compile_res := true
     41 endif
     42 ifdef LOCAL_USE_AAPT2
     43 ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),)
     44 need_compile_res := true
     45 endif
     46 endif
     47 
     48 ifeq ($(need_compile_res),true)
     49 all_resources := $(strip \
     50     $(foreach dir, $(LOCAL_RESOURCE_DIR), \
     51       $(addprefix $(dir)/, \
     52         $(patsubst res/%,%, \
     53           $(call find-subdir-assets,$(dir)) \
     54         ) \
     55       ) \
     56     ))
     57 
     58 # By default we should remove the R/Manifest classes from a static Java library,
     59 # because they will be regenerated in the app that uses it.
     60 # But if the static Java library will be used by a library, then we may need to
     61 # keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none".
     62 ifndef LOCAL_JAR_EXCLUDE_FILES
     63 LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES)
     64 endif
     65 ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES))
     66 LOCAL_JAR_EXCLUDE_FILES :=
     67 endif
     68 
     69 proguard_options_file :=
     70 
     71 ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
     72   proguard_options_file := $(intermediates.COMMON)/proguard_options
     73 endif
     74 
     75 LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
     76 
     77 ifdef LOCAL_JACK_ENABLED
     78 ifndef LOCAL_JACK_PROGUARD_FLAGS
     79     LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
     80 endif
     81 LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
     82 endif # LOCAL_JACK_ENABLED
     83 
     84 R_file_stamp := $(intermediates.COMMON)/src/R.stamp
     85 LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
     86 
     87 ifdef LOCAL_USE_AAPT2
     88 # For library we treat all the resource equal with no overlay.
     89 my_res_resources := $(all_resources)
     90 my_overlay_resources :=
     91 # For libraries put everything in the COMMON intermediate directory.
     92 my_res_package := $(intermediates.COMMON)/package-res.apk
     93 
     94 LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
     95 endif  # LOCAL_USE_AAPT2
     96 endif  # LOCAL_RESOURCE_DIR
     97 
     98 all_res_assets := $(all_resources)
     99 
    100 include $(BUILD_SYSTEM)/java_library.mk
    101 
    102 ifeq (true,$(need_compile_res))
    103 include $(BUILD_SYSTEM)/android_manifest.mk
    104 
    105 LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
    106 ifeq ($(LOCAL_SDK_RES_VERSION),)
    107   LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
    108 endif
    109 
    110 framework_res_package_export :=
    111 framework_res_package_export_deps :=
    112 # Please refer to package.mk
    113 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
    114 ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
    115 framework_res_package_export := \
    116     $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
    117 framework_res_package_export_deps := $(framework_res_package_export)
    118 else
    119 framework_res_package_export := \
    120     $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
    121 framework_res_package_export_deps := \
    122     $(dir $(framework_res_package_export))src/R.stamp
    123 endif
    124 endif
    125 
    126 # add --non-constant-id to prevent inlining constants.
    127 # AAR needs text symbol file R.txt.
    128 ifdef LOCAL_USE_AAPT2
    129 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --static-lib --no-static-lib-packages
    130 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_CONFIG :=
    131 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
    132 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
    133 else
    134 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR)
    135 endif
    136 
    137 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
    138 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
    139 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
    140 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
    141 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
    142 
    143 ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
    144 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
    145 else
    146 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
    147 endif
    148 
    149 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR :=
    150 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
    151 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME :=
    152 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
    153 
    154 ifdef LOCAL_USE_AAPT2
    155 # One more level with name res so we can zip up the flat resources that can be linked by apps.
    156 my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res
    157 my_generated_res_dirs := $(rs_generated_res_dir)
    158 my_generated_res_dirs_deps := $(RenderScript_file_stamp)
    159 include $(BUILD_SYSTEM)/aapt2.mk
    160 $(my_res_package) : $(framework_res_package_export_deps)
    161 else
    162 $(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps)
    163 	@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
    164 	$(create-resource-java-files)
    165 	$(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@
    166 endif  # LOCAL_USE_AAPT2
    167 
    168 $(LOCAL_BUILT_MODULE): $(R_file_stamp)
    169 ifdef LOCAL_JACK_ENABLED
    170 $(noshrob_classes_jack): $(R_file_stamp)
    171 $(full_classes_jack): $(R_file_stamp)
    172 $(jack_check_timestamp): $(R_file_stamp)
    173 endif # LOCAL_JACK_ENABLED
    174 $(full_classes_compiled_jar): $(R_file_stamp)
    175 
    176 # Rule to build AAR, archive including classes.jar, resource, etc.
    177 built_aar := $(intermediates.COMMON)/javalib.aar
    178 $(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE)
    179 $(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
    180 $(built_aar): PRIVATE_CLASSES_JAR := $(full_classes_jar)
    181 $(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
    182 $(built_aar): PRIVATE_R_TXT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.txt
    183 $(built_aar) : $(full_classes_jar) $(full_android_manifest)
    184 	@echo "target AAR:  $(PRIVATE_MODULE) ($@)"
    185 	$(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res
    186 	$(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml
    187 	$(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar
    188 	# Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist.
    189 	$(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;)
    190 	$(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt
    191 	$(hide) jar -cMf $@ \
    192 	  -C $(dir $@)aar .
    193 
    194 # Register the aar file.
    195 ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar)
    196 endif  # need_compile_res
    197 
    198 # Reset internal variables.
    199 all_res_assets :=
    200 LOCAL_IS_STATIC_JAVA_LIBRARY :=
    201