platform_build/core/java_library.mk

91 lines
3.2 KiB
Makefile
Raw Normal View History

###########################################################
## Standard rules for building a java library.
##
###########################################################
$(call record-module-type,JAVA_LIBRARY)
ifdef LOCAL_IS_HOST_MODULE
$(error $(LOCAL_PATH): Host java libraries must use BUILD_HOST_JAVA_LIBRARY)
endif
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
ifneq (,$(LOCAL_ASSET_DIR))
$(error $(LOCAL_PATH): Target java libraries may not set LOCAL_ASSET_DIR)
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
ifneq (true,$(LOCAL_IS_STATIC_JAVA_LIBRARY))
ifneq (,$(LOCAL_RESOURCE_DIR))
$(error $(LOCAL_PATH): Target java libraries may not set LOCAL_RESOURCE_DIR)
endif
# base_rules.mk looks at this
all_res_assets :=
endif
LOCAL_BUILT_MODULE_STEM := javalib.jar
# For java libraries, other modules should depend on
# out/target/common/obj/JAVA_LIBRARIES/.../classes.jar.
# There are some dependencies outside the build system that assume static
# java libraries produce javalib.jar, so we will copy classes.jar there too.
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
common_javalib.jar := $(intermediates.COMMON)/javalib.jar
dex_preopt_profile_src_file := $(common_javalib.jar)
LOCAL_INTERMEDIATE_TARGETS += $(common_javalib.jar)
ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
LOCAL_PROGUARD_ENABLED :=
endif
ifeq (true,$(EMMA_INSTRUMENT))
ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
ifeq (true,$(EMMA_INSTRUMENT_STATIC))
LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
# Exclude jacoco classes from proguard
LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags
endif # LOCAL_EMMA_INSTRUMENT
endif # EMMA_INSTRUMENT_STATIC
else
LOCAL_EMMA_INSTRUMENT := false
endif # EMMA_INSTRUMENT
my_dex_jar := $(common_javalib.jar)
#################################
include $(BUILD_SYSTEM)/java.mk
#################################
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
# There are some dependencies outside the build system that assume classes.jar
# is available as javalib.jar so copy it there too.
$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(common_javalib.jar)))
$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(LOCAL_BUILT_MODULE)))
else # !LOCAL_IS_STATIC_JAVA_LIBRARY
$(common_javalib.jar): PRIVATE_DEX_FILE := $(built_dex)
$(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
$(common_javalib.jar): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
$(common_javalib.jar) : $(full_classes_pre_proguard_jar) $(built_dex) $(java_resource_sources) | $(ZIPTIME) $(ZIPALIGN)
@echo "target Jar: $(PRIVATE_MODULE) ($@)"
rm -rf $@.parts && mkdir -p $@.parts
$(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
$(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
$(MERGE_ZIPS) -j $@.tmp $@.parts/dex.zip $@.parts/res.zip
rm -rf $@.parts
$(hide) $(ZIPTIME) $@.tmp
$(call commit-change-for-toc,$@)
ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
$(uncompress-dexs)
$(align-package)
endif # LOCAL_UNCOMPRESS_DEX
.KATI_RESTAT: $(common_javalib.jar)
$(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
endif # !LOCAL_IS_STATIC_JAVA_LIBRARY