static_java_library.mk revision 83dbd2f158169c41c0ec9809ae5c3a9b87ec15cb
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
22LOCAL_UNINSTALLABLE_MODULE := true
23LOCAL_IS_STATIC_JAVA_LIBRARY := true
24
25# Hack to build static Java library with Android resource
26# See bug 5714516
27all_resources :=
28ifdef LOCAL_RESOURCE_DIR
29all_resources := $(strip \
30    $(foreach dir, $(LOCAL_RESOURCE_DIR), \
31      $(addprefix $(dir)/, \
32        $(patsubst res/%,%, \
33          $(call find-subdir-assets,$(dir)) \
34        ) \
35      ) \
36    ))
37
38ifneq (,$(all_resources))
39# Those files will be excluded from the built jar.
40# The R/Manifest classes should be re-generated in the app Module instead.
41# Use '' and $ escape because they will be passed to bash.
42ifneq (true,$(LOCAL_KEEP_R_CLASS_IN_STATIC_JAVA_LIBRARY))
43LOCAL_JAR_EXCLUDE_FILES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
44endif
45endif
46endif
47
48include $(BUILD_SYSTEM)/java_library.mk
49
50ifneq (,$(all_resources))
51R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp
52
53ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
54LOCAL_MANIFEST_FILE := AndroidManifest.xml
55endif
56full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
57
58LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
59ifeq ($(LOCAL_SDK_RES_VERSION),)
60  LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
61endif
62
63framework_res_package_export :=
64framework_res_package_export_deps :=
65# Please refer to package.mk
66ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
67ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION)),)
68framework_res_package_export := \
69    $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
70framework_res_package_export_deps := $(framework_res_package_export)
71else
72framework_res_package_export := \
73    $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
74framework_res_package_export_deps := \
75    $(dir $(framework_res_package_export))src/R.stamp
76endif
77endif
78
79$(R_file_stamp): PRIVATE_MODULE := $(LOCAL_MODULE)
80# add --non-constant-id to prevent inlining constants.
81$(R_file_stamp): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id
82$(R_file_stamp): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
83$(R_file_stamp): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
84$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
85$(R_file_stamp): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
86$(R_file_stamp): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
87ifneq (,$(filter-out current, $(LOCAL_SDK_VERSION)))
88$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
89else
90$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
91endif
92$(R_file_stamp): PRIVATE_ASSET_DIR :=
93$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE :=
94$(R_file_stamp): PRIVATE_MANIFEST_PACKAGE_NAME :=
95$(R_file_stamp): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
96
97$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps)
98	@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
99	$(create-resource-java-files)
100	$(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@
101
102$(LOCAL_BUILT_MODULE): $(R_file_stamp)
103ifneq ($(full_classes_jar),)
104$(full_classes_compiled_jar): $(R_file_stamp)
105endif
106
107endif  # $(all_resources) not empty
108
109LOCAL_IS_STATIC_JAVA_LIBRARY :=
110LOCAL_JAR_EXCLUDE_FILES :=
111