github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/make/core/java_common.mk (about)

     1  # Common to host and target Java modules.
     2  
     3  my_soong_problems :=
     4  
     5  ifneq ($(filter ../%,$(LOCAL_SRC_FILES)),)
     6  my_soong_problems += dotdot_srcs
     7  endif
     8  
     9  ###########################################################
    10  ## Java version
    11  ###########################################################
    12  # Use the LOCAL_JAVA_LANGUAGE_VERSION if it is set, otherwise
    13  # use one based on the LOCAL_SDK_VERSION. If it is < 24
    14  # pass "1.7" to the tools, if it is unset, >= 24 or "current"
    15  # pass "1.8".
    16  #
    17  # The LOCAL_SDK_VERSION behavior is to ensure that, by default,
    18  # code that is expected to run on older releases of Android
    19  # does not use any 1.8 language features that are not supported
    20  # on earlier runtimes (like default / static interface methods).
    21  # Modules can override this logic by specifying
    22  # LOCAL_JAVA_LANGUAGE_VERSION explicitly.
    23  ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
    24    ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT)))
    25      LOCAL_JAVA_LANGUAGE_VERSION := 1.7
    26    else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT)))
    27      LOCAL_JAVA_LANGUAGE_VERSION := 1.8
    28    else ifneq (,$(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS))
    29      # TODO(ccross): allow 1.9 for current and unbundled once we have SDK system modules
    30      LOCAL_JAVA_LANGUAGE_VERSION := 1.8
    31    else
    32      # DEFAULT_JAVA_LANGUAGE_VERSION is 1.8, unless TARGET_OPENJDK9 in which case it is 1.9
    33      LOCAL_JAVA_LANGUAGE_VERSION := $(DEFAULT_JAVA_LANGUAGE_VERSION)
    34    endif
    35  endif
    36  LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
    37  
    38  ###########################################################
    39  
    40  # OpenJDK versions up to 8 shipped with bootstrap and tools jars
    41  # (rt.jar, jce.jar, tools.jar etc.). These are no longer part of
    42  # OpenJDK 9, but we still make them available for host tools that
    43  # are targeting older versions.
    44  USE_HOST_BOOTSTRAP_JARS := true
    45  ifeq (,$(filter $(LOCAL_JAVA_LANGUAGE_VERSION), 1.6 1.7 1.8))
    46  USE_HOST_BOOTSTRAP_JARS := false
    47  endif
    48  
    49  ###########################################################
    50  
    51  # Drop HOST_JDK_TOOLS_JAR from classpath when targeting versions > 9 (which don't have it).
    52  # TODO: Remove HOST_JDK_TOOLS_JAR and all references to it once host
    53  # bootstrap jars are no longer supported (ie. when USE_HOST_BOOTSTRAP_JARS
    54  # is always false). http://b/38418220
    55  ifneq ($(USE_HOST_BOOTSTRAP_JARS),true)
    56  LOCAL_CLASSPATH := $(filter-out $(HOST_JDK_TOOLS_JAR),$(LOCAL_CLASSPATH))
    57  endif
    58  
    59  ###########################################################
    60  ## .proto files: Compile proto files to .java
    61  ###########################################################
    62  ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
    63    LOCAL_PROTOC_OPTIMIZE_TYPE := lite
    64  endif
    65  proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
    66  # Because names of the .java files compiled from .proto files are unknown until the
    67  # .proto files are compiled, we use a timestamp file as depedency.
    68  proto_java_sources_file_stamp :=
    69  ifneq ($(proto_sources),)
    70  proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
    71  
    72  proto_java_intemediate_dir := $(intermediates.COMMON)/proto
    73  proto_java_sources_file_stamp := $(proto_java_intemediate_dir)/Proto.stamp
    74  proto_java_sources_dir := $(proto_java_intemediate_dir)/src
    75  
    76  $(proto_java_sources_file_stamp): PRIVATE_PROTO_INCLUDES := $(TOP)
    77  $(proto_java_sources_file_stamp): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
    78  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
    79  ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
    80  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
    81  else
    82    ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
    83  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javanano_out
    84    else
    85      ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
    86  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javastream_out
    87  $(proto_java_sources_file_stamp): $(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
    88      else
    89  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
    90      endif
    91    endif
    92  endif
    93  $(proto_java_sources_file_stamp): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
    94  $(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_PARAMS := $(if $(filter lite,$(LOCAL_PROTOC_OPTIMIZE_TYPE)),lite$(if $(LOCAL_PROTO_JAVA_OUTPUT_PARAMS),:,),)$(LOCAL_PROTO_JAVA_OUTPUT_PARAMS)
    95  $(proto_java_sources_file_stamp) : $(proto_sources_fullpath) $(PROTOC)
    96  	$(call transform-proto-to-java)
    97  
    98  #TODO: protoc should output the dependencies introduced by imports.
    99  
   100  ALL_MODULES.$(my_register_name).PROTO_FILES := $(proto_sources_fullpath)
   101  endif # proto_sources
   102  
   103  #########################################
   104  ## Java resources
   105  
   106  # Look for resource files in any specified directories.
   107  # Non-java and non-doc files will be picked up as resources
   108  # and included in the output jar file.
   109  java_resource_file_groups :=
   110  
   111  LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
   112  ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
   113    # This makes a list of words like
   114    #     <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
   115    # where each of the files is relative to the directory it's grouped with.
   116    # Directories that don't contain any resource files will result in groups
   117    # that end with a colon, and they are stripped out in the next step.
   118    java_resource_file_groups += \
   119      $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
   120  	$(subst $(space),:,$(strip \
   121  		$(LOCAL_PATH)/$(dir): \
   122  	    $(patsubst ./%,%,$(sort $(shell cd $(LOCAL_PATH)/$(dir) && \
   123  		find . \
   124  		    -type d -a -name ".svn" -prune -o \
   125  		    -type f \
   126  			-a \! -name "*.java" \
   127  			-a \! -name "package.html" \
   128  			-a \! -name "overview.html" \
   129  			-a \! -name ".*.swp" \
   130  			-a \! -name ".DS_Store" \
   131  			-a \! -name "*~" \
   132  			-print \
   133  		    ))) \
   134  	)) \
   135      )
   136    java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
   137  endif # LOCAL_JAVA_RESOURCE_DIRS
   138  
   139  ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
   140    # Converts LOCAL_JAVA_RESOURCE_FILES := <file> to $(dir $(file))::$(notdir $(file))
   141    # and LOCAL_JAVA_RESOURCE_FILES := <dir>:<file> to <dir>::<file>
   142    java_resource_file_groups += $(strip $(foreach res,$(LOCAL_JAVA_RESOURCE_FILES), \
   143      $(eval _file := $(call word-colon,2,$(res))) \
   144      $(if $(_file), \
   145        $(eval _base := $(call word-colon,1,$(res))), \
   146        $(eval _base := $(dir $(res))) \
   147          $(eval _file := $(notdir $(res)))) \
   148      $(if $(filter /%, \
   149        $(filter-out $(OUT_DIR)/%,$(_base) $(_file))), \
   150          $(call pretty-error,LOCAL_JAVA_RESOURCE_FILES may not include absolute paths: $(_base) $(_file))) \
   151      $(patsubst %/,%,$(_base))::$(_file)))
   152  
   153  endif # LOCAL_JAVA_RESOURCE_FILES
   154  
   155  ifdef java_resource_file_groups
   156    # The full paths to all resources, used for dependencies.
   157    java_resource_sources := \
   158      $(foreach group,$(java_resource_file_groups), \
   159  	$(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
   160  	    $(wordlist 2,9999,$(subst :,$(space),$(group))) \
   161  	) \
   162      )
   163    # The arguments to jar that will include these files in a jar file.
   164    # Quote the file name to handle special characters (such as #) correctly.
   165    extra_jar_args := \
   166      $(foreach group,$(java_resource_file_groups), \
   167  	$(addprefix -C "$(word 1,$(subst :,$(space),$(group)))" , \
   168  	    $(foreach w, $(wordlist 2,9999,$(subst :,$(space),$(group))), "$(w)" ) \
   169  	) \
   170      )
   171    java_resource_file_groups :=
   172  else
   173    java_resource_sources :=
   174    extra_jar_args :=
   175  endif # java_resource_file_groups
   176  
   177  #####################################
   178  ## Warn if there is unrecognized file in LOCAL_SRC_FILES.
   179  my_unknown_src_files := $(filter-out \
   180    %.java %.aidl %.proto %.logtags, \
   181    $(LOCAL_SRC_FILES) $(LOCAL_INTERMEDIATE_SOURCES) $(LOCAL_GENERATED_SOURCES))
   182  ifneq ($(my_unknown_src_files),)
   183  $(warning $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unknown_src_files))
   184  endif
   185  
   186  ######################################
   187  ## PRIVATE java vars
   188  # LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
   189  # but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
   190  # You have to set up the dependency in some other way.
   191  need_compile_java := $(strip $(all_java_sources)$(LOCAL_SRCJARS)$(all_res_assets)$(java_resource_sources))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED))
   192  ifdef need_compile_java
   193  
   194  annotation_processor_flags :=
   195  annotation_processor_deps :=
   196  
   197  ifdef LOCAL_ANNOTATION_PROCESSORS
   198    annotation_processor_jars := $(call java-lib-files,$(LOCAL_ANNOTATION_PROCESSORS),true)
   199    annotation_processor_flags += -processorpath $(call normalize-path-list,$(annotation_processor_jars))
   200    annotation_processor_deps += $(annotation_processor_jars)
   201  
   202    # b/25860419: annotation processors must be explicitly specified for grok
   203    annotation_processor_flags += $(foreach class,$(LOCAL_ANNOTATION_PROCESSOR_CLASSES),-processor $(class))
   204  
   205    annotation_processor_jars :=
   206  endif
   207  
   208  full_static_java_libs := $(call java-lib-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
   209  full_static_java_header_libs := $(call java-lib-header-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
   210  
   211  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
   212  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_HEADER_LIBRARIES := $(full_static_java_header_libs)
   213  
   214  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
   215  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
   216  
   217  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
   218  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno
   219  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
   220  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_PROTO_SOURCES := $(if $(proto_sources),true)
   221  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/proto
   222  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES :=
   223  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
   224  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
   225  
   226  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
   227  
   228  full_java_bootclasspath_libs :=
   229  empty_bootclasspath :=
   230  my_system_modules :=
   231  
   232  ifndef LOCAL_IS_HOST_MODULE
   233    ifeq ($(LOCAL_SDK_VERSION),)
   234      ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
   235        # No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
   236        empty_bootclasspath := ""
   237        # Most users of LOCAL_NO_STANDARD_LIBRARIES really mean no framework libs,
   238        # and manually add back the core libs.  The ones that don't are in soong
   239        # now, so just always assume that they want the default system modules
   240        my_system_modules := $(DEFAULT_SYSTEM_MODULES)
   241      else  # LOCAL_NO_STANDARD_LIBRARIES
   242        full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
   243        LOCAL_JAVA_LIBRARIES := $(filter-out $(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
   244        my_system_modules := $(DEFAULT_SYSTEM_MODULES)
   245      endif  # LOCAL_NO_STANDARD_LIBRARIES
   246    else
   247      ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
   248        $(call pretty-error,Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
   249      endif
   250      ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
   251        $(call pretty-error,Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
   252               Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
   253      endif
   254      ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
   255        # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
   256        full_java_bootclasspath_libs := $(call java-lib-header-files,android_stubs_current)
   257      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
   258        full_java_bootclasspath_libs := $(call java-lib-header-files,android_system_stubs_current)
   259      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),test_current)
   260        full_java_bootclasspath_libs := $(call java-lib-header-files,android_test_stubs_current)
   261      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),core_current)
   262        full_java_bootclasspath_libs := $(call java-lib-header-files,core.current.stubs)
   263      else
   264        # core_<ver> is subset of <ver>. Instead of defining a prebuilt lib for core_<ver>,
   265        # use the stub for <ver> when building for apps.
   266        _version := $(patsubst core_%,%,$(LOCAL_SDK_VERSION))
   267        full_java_bootclasspath_libs := $(call java-lib-header-files,sdk_v$(_version))
   268        _version :=
   269      endif # current, system_current, system_${VER}, test_current or core_current
   270    endif # LOCAL_SDK_VERSION
   271  
   272    ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
   273      ifneq ($(LOCAL_MODULE),jacocoagent)
   274        ifeq ($(EMMA_INSTRUMENT),true)
   275          ifneq ($(EMMA_INSTRUMENT_STATIC),true)
   276            # For instrumented build, if Jacoco is not being included statically
   277            # in instrumented packages then include Jacoco classes into the
   278            # bootclasspath.
   279            full_java_bootclasspath_libs += $(call java-lib-header-files,jacocoagent)
   280          endif # EMMA_INSTRUMENT_STATIC
   281        endif # EMMA_INSTRUMENT
   282      endif # LOCAL_MODULE == jacocoagent
   283    endif # LOCAL_NO_STANDARD_LIBRARIES
   284  
   285    # In order to compile lambda code javac requires various invokedynamic-
   286    # related classes to be present. This change adds stubs needed for
   287    # javac to compile lambdas.
   288    ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
   289      ifdef TARGET_BUILD_APPS
   290        full_java_bootclasspath_libs += $(call java-lib-header-files,sdk-core-lambda-stubs)
   291      else
   292        full_java_bootclasspath_libs += $(call java-lib-header-files,core-lambda-stubs)
   293      endif
   294    endif
   295  
   296    full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
   297    full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
   298  
   299  else # LOCAL_IS_HOST_MODULE
   300  
   301    ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
   302      ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
   303        empty_bootclasspath := ""
   304      else
   305        full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)),true)
   306      endif
   307  
   308      my_system_modules := $(DEFAULT_SYSTEM_MODULES)
   309      full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
   310      full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
   311    else # !USE_CORE_LIB_BOOTCLASSPATH
   312      # Give host-side tools a version of OpenJDK's standard libraries
   313      # close to what they're targeting. As of Dec 2017, AOSP is only
   314      # bundling OpenJDK 8 and 9, so nothing < 8 is available.
   315      #
   316      # When building with OpenJDK 8, the following should have no
   317      # effect since those jars would be available by default.
   318      #
   319      # When building with OpenJDK 9 but targeting a version < 1.8,
   320      # putting them on the bootclasspath means that:
   321      # a) code can't (accidentally) refer to OpenJDK 9 specific APIs
   322      # b) references to existing APIs are not reinterpreted in an
   323      #    OpenJDK 9-specific way, eg. calls to subclasses of
   324      #    java.nio.Buffer as in http://b/70862583
   325      ifeq ($(USE_HOST_BOOTSTRAP_JARS),true)
   326        full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/jce.jar
   327        full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/rt.jar
   328      endif
   329      full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
   330        $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
   331      full_shared_java_header_libs := $(full_shared_java_libs)
   332    endif # USE_CORE_LIB_BOOTCLASSPATH
   333  endif # !LOCAL_IS_HOST_MODULE
   334  
   335  ifdef empty_bootclasspath
   336    ifdef full_java_bootclasspath_libs
   337      $(call pretty-error,internal error: empty_bootclasspath and full_java_bootclasspath_libs should not both be set)
   338    endif
   339  endif
   340  
   341  full_java_system_modules_deps :=
   342  my_system_modules_dir :=
   343  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES :=
   344  ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.9)
   345    $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES := true
   346    ifdef my_system_modules
   347      ifneq ($(my_system_modules),none)
   348        ifndef SOONG_SYSTEM_MODULES_$(my_system_modules)
   349          $(call pretty-error, Invalid system modules $(my_system_modules))
   350        endif
   351        full_java_system_modules_deps := $(SOONG_SYSTEM_MODULES_$(my_system_modules))
   352        my_system_modules_dir := $(patsubst %/lib/modules,%,$(SOONG_SYSTEM_MODULES_$(my_system_modules)))
   353      endif
   354    endif
   355  endif
   356  
   357  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs)
   358  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath)
   359  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES := $(my_system_modules)
   360  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_DIR := $(my_system_modules_dir)
   361  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_LIBS := $(call java-lib-files,$(SOONG_SYSTEM_MODULES_LIBS_$(my_system_modules)))
   362  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PATCH_MODULE := $(LOCAL_PATCH_MODULE)
   363  
   364  ifndef LOCAL_IS_HOST_MODULE
   365  # This is set by packages that are linking to other packages that export
   366  # shared libraries, allowing them to make use of the code in the linked apk.
   367  apk_libraries := $(sort $(LOCAL_APK_LIBRARIES) $(LOCAL_RES_LIBRARIES))
   368  ifneq ($(apk_libraries),)
   369    link_apk_libraries := $(call app-lib-files,$(apk_libraries))
   370    link_apk_header_libs := $(call app-lib-header-files,$(apk_libraries))
   371  
   372    # link against the jar with full original names (before proguard processing).
   373    full_shared_java_libs += $(link_apk_libraries)
   374    full_shared_java_header_libs += $(link_apk_header_libs)
   375  endif
   376  
   377  # This is set by packages that contain instrumentation, allowing them to
   378  # link against the package they are instrumenting.  Currently only one such
   379  # package is allowed.
   380  LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
   381  ifdef LOCAL_INSTRUMENTATION_FOR
   382    ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
   383      $(error \
   384          $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
   385    endif
   386  
   387    link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
   388        APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
   389    # link against the jar with full original names (before proguard processing).
   390    link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
   391    ifneq ($(TURBINE_ENABLED),false)
   392      link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
   393    else
   394      link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
   395    endif
   396    full_shared_java_libs += $(link_instr_classes_jar)
   397    full_shared_java_header_libs += $(link_instr_classes_header_jar)
   398  endif  # LOCAL_INSTRUMENTATION_FOR
   399  endif  # LOCAL_IS_HOST_MODULE
   400  
   401  endif  # need_compile_java
   402  
   403  # We may want to add jar manifest or jar resource files even if there is no java code at all.
   404  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
   405  jar_manifest_file :=
   406  ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
   407  jar_manifest_file := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
   408  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(jar_manifest_file)
   409  else
   410  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
   411  endif
   412  
   413  ##########################################################
   414  
   415  full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
   416  full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
   417  
   418  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
   419  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
   420  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SHARED_JAVA_HEADER_LIBRARIES := $(full_shared_java_header_libs)
   421  
   422  ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
   423      $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
   424  
   425  
   426  ##########################################################
   427  # Copy NOTICE files of transitive static dependencies
   428  # Don't do this in mm, since many of the targets won't exist.
   429  ifeq ($(ONE_SHOT_MAKEFILE),)
   430  installed_static_library_notice_file_targets := \
   431      $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
   432        NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-JAVA_LIBRARIES-$(lib))
   433  else
   434  installed_static_library_notice_file_targets :=
   435  endif
   436  
   437  $(notice_target): | $(installed_static_library_notice_file_targets)
   438  $(LOCAL_INSTALLED_MODULE): | $(notice_target)
   439  
   440  ###########################################################
   441  # Verify that all libraries are safe to use
   442  ###########################################################
   443  ifndef LOCAL_IS_HOST_MODULE
   444  ifeq ($(LOCAL_SDK_VERSION),system_current)
   445  my_link_type := java:system
   446  my_warn_types :=
   447  my_allowed_types := java:sdk java:system java:core
   448  else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
   449  my_link_type := java:system
   450  my_warn_types :=
   451  my_allowed_types := java:sdk java:system java:core
   452  else ifeq ($(LOCAL_SDK_VERSION),core_current)
   453  my_link_type := java:core
   454  my_warn_types :=
   455  my_allowed_types := java:core
   456  else ifneq ($(LOCAL_SDK_VERSION),)
   457  my_link_type := java:sdk
   458  my_warn_types :=
   459  my_allowed_types := java:sdk java:core
   460  else
   461  my_link_type := java:platform
   462  my_warn_types :=
   463  my_allowed_types := java:sdk java:system java:platform java:core
   464  endif
   465  
   466  ifdef LOCAL_AAPT2_ONLY
   467  my_link_type += aapt2_only
   468  endif
   469  ifdef LOCAL_USE_AAPT2
   470  my_allowed_types += aapt2_only
   471  endif
   472  
   473  my_link_deps := $(addprefix JAVA_LIBRARIES:,$(LOCAL_STATIC_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES))
   474  my_link_deps += $(addprefix APPS:,$(apk_libraries))
   475  
   476  my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
   477  my_common := COMMON
   478  include $(BUILD_SYSTEM)/link_type.mk
   479  endif  # !LOCAL_IS_HOST_MODULE
   480  
   481  ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
   482  
   483  SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
   484      $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
   485  SOONG_CONV.$(LOCAL_MODULE).DEPS := \
   486      $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
   487      $(LOCAL_STATIC_JAVA_LIBRARIES) \
   488      $(LOCAL_JAVA_LIBRARIES) \
   489      $(LOCAL_JNI_SHARED_LIBRARIES)
   490  SOONG_CONV.$(LOCAL_MODULE).TYPE := java
   491  SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
   492  
   493  endif