platform_build/core/static_java_library.mk

221 lines
8.4 KiB
Makefile
Raw Normal View History

#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Standard rules for building a "static" java library.
# Static java libraries are not installed, nor listed on any
# classpaths. They can, however, be included wholesale in
# other java modules.
$(call record-module-type,STATIC_JAVA_LIBRARY)
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_IS_STATIC_JAVA_LIBRARY := true
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
my_res_package :=
ifdef LOCAL_AAPT2_ONLY
LOCAL_USE_AAPT2 := true
endif
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
# 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.
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
ifdef LOCAL_RESOURCE_DIR
need_compile_res := true
LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d)))
endif
ifdef LOCAL_USE_AAPT2
ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),)
need_compile_res := true
endif
endif
ifeq ($(need_compile_res),true)
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
all_resources := $(strip \
$(foreach dir, $(LOCAL_RESOURCE_DIR), \
$(addprefix $(dir)/, \
$(patsubst res/%,%, \
$(call find-subdir-assets,$(dir)) \
) \
) \
))
# 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
# keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none".
ifndef LOCAL_JAR_EXCLUDE_FILES
LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES)
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
endif
ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES))
LOCAL_JAR_EXCLUDE_FILES :=
endif
proguard_options_file :=
ifneq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom)
proguard_options_file := $(intermediates.COMMON)/proguard_options
endif
LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
R_file_stamp := $(intermediates.COMMON)/src/R.stamp
LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
ifdef LOCAL_USE_AAPT2
# For library we treat all the resource equal with no overlay.
my_res_resources := $(all_resources)
my_overlay_resources :=
# For libraries put everything in the COMMON intermediate directory.
my_res_package := $(intermediates.COMMON)/package-res.apk
LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
endif # LOCAL_USE_AAPT2
endif # LOCAL_RESOURCE_DIR
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
all_res_assets := $(all_resources)
include $(BUILD_SYSTEM)/java_library.mk
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
ifeq (true,$(need_compile_res))
include $(BUILD_SYSTEM)/android_manifest.mk
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
ifeq ($(LOCAL_SDK_RES_VERSION),)
LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
endif
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
framework_res_package_export :=
framework_res_package_export_deps :=
# Please refer to package.mk
ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
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))),)
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
framework_res_package_export := \
$(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
framework_res_package_export_deps := $(framework_res_package_export)
else
framework_res_package_export := \
$(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
framework_res_package_export_deps := \
$(dir $(framework_res_package_export))src/R.stamp
endif
endif
ifdef LOCAL_USE_AAPT2
$(intermediates.COMMON)/export_proguard_flags: $(addprefix $(LOCAL_PATH)/,$(LOCAL_EXPORT_PROGUARD_FLAG_FILES))
@echo "Export proguard flags: $@"
rm -f $@
cat $+ >$@
endif
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
# add --non-constant-id to prevent inlining constants.
# AAR needs text symbol file R.txt.
ifdef LOCAL_USE_AAPT2
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --static-lib --no-static-lib-packages
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_CONFIG :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
else
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR)
endif
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
ifdef LOCAL_USE_AAPT2
# One more level with name res so we can zip up the flat resources that can be linked by apps.
my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res
renderscript_target_api :=
ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
else
ifneq (,$(LOCAL_SDK_VERSION))
# Set target-api for LOCAL_SDK_VERSIONs other than current.
ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
endif
endif # LOCAL_SDK_VERSION is set
endif # LOCAL_RENDERSCRIPT_TARGET_API is set
ifneq (,$(renderscript_target_api))
ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true)
my_generated_res_dirs := $(rs_generated_res_dir)
my_generated_res_dirs_deps := $(RenderScript_file_stamp)
endif # renderscript_target_api < 21
endif # renderscript_target_api is set
include $(BUILD_SYSTEM)/aapt2.mk
$(my_res_package) : $(framework_res_package_export_deps)
else
$(R_file_stamp): PRIVATE_RESOURCE_LIST := $(all_resources)
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps)
@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
$(create-resource-java-files)
$(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@
endif # LOCAL_USE_AAPT2
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
$(LOCAL_BUILT_MODULE): $(R_file_stamp)
$(java_source_list_file): $(R_file_stamp)
Support java compilation sharding for target side. Add "LOCAL_JAVAC_SHARD_SIZE" to represent the number of java source path entries in each shard. Sharding is not allowed when "LOCAL_JAVAC_SHARD_SIZE" and "LOCAL_JAR_PROCESSORS" are both enabled. Limitation: 1. 0 <= LOCAL_JAVAC_SHARD_SIZE <= 8192 1. 0 < NUM(java_sources) <= 8192 2. 0 <= NUM(shards) <= 100 Performance Compare: <Unsharded Build------------------------------------------------> 1. Build from clean state rm -r -f out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/ && time m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar real 1m2.720s user 5m26.604s sys 0m39.552s 2. Incremental build m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar && touch frameworks/base/core/java/android/net/http/HttpResponseCache.java && time m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar real 0m37.586s user 5m47.804s sys 0m50.388s <Sharded Build--------------------------------------------------> 1. Build from clean state rm -r -f out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/ && time m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar Javac Shard Size: 50----real 1m10.163s user 25m59.008s sys 1m58.460s Javac Shard Size: 100---real 1m2.115s user 21m3.600s sys 1m15.964s Javac Shard Size: 150---real 0m59.520s user 18m10.544s sys 1m12.628s Javac Shard Size: 200---real 0m56.894s user 15m39.244s sys 1m11.608s Javac Shard Size: 250---real 0m55.991s user 14m38.716s sys 1m2.292s Javac Shard Size: 300---real 0m55.114s user 13m6.568s sys 1m8.200s Javac Shard Size: 350---real 0m53.144s user 12m7.740s sys 1m3.836s Javac Shard Size: 400---real 0m54.929s user 12m9.324s sys 1m4.340s Javac Shard Size: 450---real 1m30.194s user 25m31.468s sys 1m52.416s Javac Shard Size: 500---real 0m53.976s user 10m35.500s sys 0m55.160s 2. Incremental build m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar && touch frameworks/base/core/java/android/net/http/HttpResponseCache.java && time m out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar Javac Shard Size: 50-----real 0m16.322s user 1m8.648s sys 0m31.700s Javac Shard Size: 100----real 0m16.163s user 1m22.932s sys 0m29.440s Javac Shard Size: 150----real 0m16.611s user 1m37.828s sys 0m21.168s Javac Shard Size: 200----real 0m16.936s user 1m49.248s sys 0m28.636s Javac Shard Size: 250----real 0m17.509s user 1m54.944s sys 0m32.768s Javac Shard Size: 300----real 0m18.868s user 1m54.088s sys 0m28.824s Javac Shard Size: 350----real 0m17.629s user 1m54.108s sys 0m31.056s Javac Shard Size: 400----real 0m18.658s user 2m7.712s sys 0m30.636s Javac Shard Size: 450----real 0m18.874s user 2m8.808s sys 0m33.540s Javac Shard Size: 500----real 0m19.432s user 2m24.400s sys 0m30.368s time m nothing: real 0m5.799s user 0m7.236s sys 0m3.068s Test: m clean && m -j checkbuild Bug: b/67424047 Change-Id: Id0766d2b7de7c4546d29bbc7f8a0dd0e4b9ad45b
2017-10-04 18:26:06 +02:00
$(foreach x,$(sharded_java_source_list_files),$(eval $(x): $(R_file_stamp)))
$(full_classes_compiled_jar): $(R_file_stamp)
$(full_classes_turbine_jar): $(R_file_stamp)
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
# if we have custom proguarding done use the proguarded classes jar instead of the normal classes jar
ifeq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom)
aar_classes_jar = $(full_classes_jar)
else
aar_classes_jar = $(full_classes_pre_proguard_jar)
endif
# Rule to build AAR, archive including classes.jar, resource, etc.
built_aar := $(intermediates.COMMON)/javalib.aar
$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE)
$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
$(built_aar): PRIVATE_CLASSES_JAR := $(aar_classes_jar)
$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
$(built_aar): PRIVATE_R_TXT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.txt
$(built_aar): $(JAR_ARGS)
$(built_aar) : $(aar_classes_jar) $(full_android_manifest)
@echo "target AAR: $(PRIVATE_MODULE) ($@)"
$(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res
$(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml
$(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar
# Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist.
$(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;)
$(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt
$(hide) $(JAR) -cMf $@ \
$(call jar-args-sorted-files-in-directory,$(dir $@)aar)
# Register the aar file.
ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar)
endif # need_compile_res
Support to build static Java library with Android resource Bug: 5714516 The rationale behind this change: - the library is compiled into a jar file, but its R class is generated making the constant not constant (static, not final static) (aapt option --non-constant-id). Also the jar file does not contain the R class. - this allows the integer value to not be inlined in the compiled class files. Note that this prevents using switch statements. - the main project use this jar file as a normal static library: it will add all the class files except the R.class. - the main project uses the library res folder as a resource folder with lower priority than the main project (basically the main project is an overlay. This is accomplished using aapt's --auto-add-overlay to handle resources only in the main project (which the normal overlay mechanism doesn't allow). - the main project creates R classes in the main project's package but also in the library's package. This is done with aapt's --extra-packages which accept as many packages as needed, separated by a :. - manifest merging is not done yet, so activities/services/permissions/etc... have to be manually declared in the main app. To use a static library with Android resource in your app, 1. Add the library's resource dir to your app as an overlay: LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs> 2. Set the proper aapt flags: LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \ --extra-packages <lib1_package_name>:<lib2_package_name>:... Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
2011-12-14 23:29:28 +01:00
# Reset internal variables.
aar_classes_jar :=
all_res_assets :=
LOCAL_IS_STATIC_JAVA_LIBRARY :=