java.mk 30.4 KB
Newer Older
1
# Target Java.
2 3 4 5 6
# Requires:
# LOCAL_MODULE_SUFFIX
# LOCAL_MODULE_CLASS
# all_res_assets

7
ifeq ($(TARGET_BUILD_PDK),true)
8
ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
9 10
# LOCAL_SDK not defined or set to current
ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
11
ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
12
LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
13
endif #!LOCAL_NO_STANDARD_LIBRARIES
14
endif
15
endif # !PDK_JAVA
16 17
endif #PDK

18 19 20 21 22 23 24 25 26 27 28
LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))

ifneq ($(LOCAL_SDK_VERSION),)
  ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
    $(error $(LOCAL_PATH): Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
  else
    ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
      $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
             Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
    else
29 30
      ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
        # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
31
        LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES)
32 33
      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
        LOCAL_JAVA_LIBRARIES := android_system_stubs_current $(LOCAL_JAVA_LIBRARIES)
34 35
      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),test_current)
        LOCAL_JAVA_LIBRARIES := android_test_stubs_current $(LOCAL_JAVA_LIBRARIES)
36 37
      else
        LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES)
38 39 40 41 42 43 44 45 46
      endif

      ifeq ($(LOCAL_SDK_VERSION),current)
        my_jack_min_sdk_version := $(PLATFORM_JACK_MIN_SDK_VERSION)
      else ifeq ($(LOCAL_SDK_VERSION),system_current)
        my_jack_min_sdk_version := $(PLATFORM_JACK_MIN_SDK_VERSION)
      else ifeq ($(LOCAL_SDK_VERSION),test_current)
        my_jack_min_sdk_version := $(PLATFORM_JACK_MIN_SDK_VERSION)
      else
Yohann Roussel's avatar
Yohann Roussel committed
47
        my_jack_min_sdk_version := $(LOCAL_SDK_VERSION)
48
      endif
49 50 51
    endif
  endif
else
Yohann Roussel's avatar
Yohann Roussel committed
52
  my_jack_min_sdk_version := $(PLATFORM_JACK_MIN_SDK_VERSION)
53
  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
54
    LOCAL_JAVA_LIBRARIES := $(TARGET_DEFAULT_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES)
55 56
  endif
endif
57

58 59 60 61
ifneq (,$(strip $(LOCAL_MIN_SDK_VERSION)))
  my_jack_min_sdk_version := $(LOCAL_MIN_SDK_VERSION)
endif

62 63 64
proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
ifneq ($(proto_sources),)
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
65
    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
66
else
67
  ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
68
    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
69
  else
70
    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
71
  endif
72 73 74
endif
endif

75 76 77 78 79 80
# LOCAL_STATIC_JAVA_AAR_LIBRARIES and LOCAL_STATIC_ANDROID_LIBRARIES are also LOCAL_STATIC_JAVA_LIBRARIES.
LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) \
    $(LOCAL_STATIC_JAVA_AAR_LIBRARIES) \
    $(LOCAL_STATIC_ANDROID_LIBRARIES))
# LOCAL_SHARED_ANDROID_LIBRARIES are also LOCAL_JAVA_LIBRARIES.
LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES) $(LOCAL_SHARED_ANDROID_LIBRARIES))
81 82 83 84 85 86 87 88 89

LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
ifeq ($(LOCAL_BUILT_MODULE_STEM),)
$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
endif
ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
endif

Joe Onorato's avatar
Joe Onorato committed
90 91 92 93 94 95 96 97 98 99

##############################################################################
# Define the intermediate targets before including base_rules so they get
# the correct environment.
##############################################################################

intermediates := $(call local-intermediates-dir)
intermediates.COMMON := $(call local-intermediates-dir,COMMON)

# Choose leaf name for the compiled jar file.
100
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
Joe Onorato's avatar
Joe Onorato committed
101
full_classes_compiled_jar_leaf := classes-no-debug-var.jar
102
built_dex_intermediate_leaf := no-local
Joe Onorato's avatar
Joe Onorato committed
103 104
else
full_classes_compiled_jar_leaf := classes-full-debug.jar
105
built_dex_intermediate_leaf := with-local
106 107 108 109
endif

ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
LOCAL_PROGUARD_ENABLED :=
Joe Onorato's avatar
Joe Onorato committed
110 111
endif

112 113 114 115 116 117 118
ifdef LOCAL_PROGUARD_ENABLED
proguard_jar_leaf := proguard.classes.jar
else
proguard_jar_leaf := noproguard.classes.jar
endif

full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
119 120
jarjar_leaf := classes-jarjar.jar
full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf)
Joe Onorato's avatar
Joe Onorato committed
121
emma_intermediates_dir := $(intermediates.COMMON)/emma_out
122 123 124
# emma is hardcoded to use the leaf name of its input for the output file --
# only the output directory can be changed
full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(jarjar_leaf)
125
full_classes_proguard_jar := $(intermediates.COMMON)/$(proguard_jar_leaf)
126
built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)/classes.dex
127 128
full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar

129 130
ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
# If this is an apk without any Java code (e.g. framework-res), we should skip compiling Java.
131 132 133
full_classes_jar :=
built_dex :=
else
134
full_classes_jar := $(intermediates.COMMON)/classes.jar
135
built_dex := $(intermediates.COMMON)/classes.dex
136
endif
Yohann Roussel's avatar
Yohann Roussel committed
137 138 139 140
# final Jack library, shrinked and obfuscated if it must be
full_classes_jack := $(intermediates.COMMON)/classes.jack
# intermediate Jack library without shrink and obfuscation
noshrob_classes_jack := $(intermediates.COMMON)/classes.noshrob.jack
Yohann Roussel's avatar
Yohann Roussel committed
141
jack_check_timestamp := $(intermediates.COMMON)/jack.check.timestamp
Joe Onorato's avatar
Joe Onorato committed
142 143 144

LOCAL_INTERMEDIATE_TARGETS += \
    $(full_classes_compiled_jar) \
145
    $(full_classes_jarjar_jar) \
Joe Onorato's avatar
Joe Onorato committed
146
    $(full_classes_emma_jar) \
147
    $(full_classes_jar) \
148
    $(full_classes_proguard_jar) \
149
    $(built_dex_intermediate) \
Yohann Roussel's avatar
Yohann Roussel committed
150 151
    $(full_classes_jack) \
    $(noshrob_classes_jack) \
Yohann Roussel's avatar
Yohann Roussel committed
152
    $(jack_check_timestamp) \
153
    $(built_dex) \
154 155
    $(full_classes_stubs_jar)

Joe Onorato's avatar
Joe Onorato committed
156

157
LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
Joe Onorato's avatar
Joe Onorato committed
158

159 160
###############################################################
## .rs files: RenderScript sources to .java files and .bc files
161
## .fs files: Filterscript sources to .java files and .bc files
162
###############################################################
163
renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
164 165 166
# Because names of the java files from RenderScript are unknown until the
# .rs file(s) are compiled, we have to depend on a timestamp file.
RenderScript_file_stamp :=
Ying Wang's avatar
Ying Wang committed
167
rs_generated_res_dir :=
168
rs_compatibility_jni_libs :=
169 170 171
ifneq ($(renderscript_sources),)
renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
172
renderscript_intermediate.COMMON := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript
173

174
# Defaulting to an empty string uses the latest available platform SDK.
175
renderscript_target_api :=
176 177

ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
178
  renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
179
else
180 181
  ifneq (,$(LOCAL_SDK_VERSION))
    # Set target-api for LOCAL_SDK_VERSIONs other than current.
182
    ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
183 184 185
      renderscript_target_api := $(LOCAL_SDK_VERSION)
    endif
  endif  # LOCAL_SDK_VERSION is set
186
endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
187

188 189 190 191 192 193
# For 64-bit, we always have to upgrade to at least 21 for compat build.
ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
  ifeq ($(TARGET_IS_64_BIT),true)
    ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
      renderscript_target_api := 21
    endif
194 195 196
  endif
endif

197 198 199 200
ifeq ($(LOCAL_RENDERSCRIPT_CC),)
LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
endif

201 202 203 204 205
# Turn on all warnings and warnings as errors for RS compiles.
# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
renderscript_flags := -Wall -Werror
renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)

Ying Wang's avatar
Ying Wang committed
206
# prepend the RenderScript system include path
207
ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_VERSION))),)
208
# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
209
LOCAL_RENDERSCRIPT_INCLUDES := \
210 211
    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
212 213
    $(LOCAL_RENDERSCRIPT_INCLUDES)
else
214
LOCAL_RENDERSCRIPT_INCLUDES := \
215
    $(TOPDIR)external/clang/lib/Headers \
Alex Sakhartchouk's avatar
Alex Sakhartchouk committed
216
    $(TOPDIR)frameworks/rs/scriptc \
217
    $(LOCAL_RENDERSCRIPT_INCLUDES)
218 219
endif

220 221 222 223
ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
endif

Ying Wang's avatar
Ying Wang committed
224 225 226
bc_files := $(patsubst %.fs,%.bc, $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))))
bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files)))

Ying Wang's avatar
Ying Wang committed
227
$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
228
$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
229
$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
230 231 232
$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
# automatically found by the java compiling function transform-java-to-classes.jar.
233
$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
234
$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
Ying Wang's avatar
Ying Wang committed
235
$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
236
$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
237 238
	$(transform-renderscripts-to-java-and-bc)

Ying Wang's avatar
Ying Wang committed
239
# include the dependency files (.d/.P) generated by llvm-rs-cc.
240
$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
241

242
ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
243 244 245 246 247 248 249 250 251 252 253 254


ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
ifeq ($(TARGET_IS_64_BIT),true)
renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/
else
renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/
endif
else
renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/
endif

255
rs_generated_bc := $(addprefix \
256
    $(renderscript_intermediate.bc_folder), $(bc_files))
257

258
renderscript_intermediate := $(intermediates)/renderscript
259 260 261

# We don't need the .so files in bundled branches
# Prevent these from showing up on the device
262 263 264 265 266
# One exception is librsjni.so, which is needed for
# both native path and compat path.
rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
LOCAL_JNI_SHARED_LIBRARIES += librsjni

267
ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
268

269
rs_compatibility_jni_libs := $(addprefix \
270
    $(renderscript_intermediate)/librs., \
271 272 273 274
    $(patsubst %.bc,%.so, $(bc_files)))

$(rs_generated_bc) : $(RenderScript_file_stamp)

275
rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
276
LOCAL_JNI_SHARED_LIBRARIES += libRSSupport
277

278 279 280 281 282 283
rs_support_io_lib :=
# check if the target api level support USAGE_IO
ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),)
rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so
LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO
endif
284 285


286
$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
287
    $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt)
288
$(rs_compatibility_jni_libs): $(BCC_COMPAT)
289
$(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX)
290
$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
291
    $(renderscript_intermediate.bc_folder)%.bc
292 293 294 295
	$(transform-bc-to-so)

endif

296 297
endif

298 299
LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
# Make sure the generated resource will be added to the apk.
Ying Wang's avatar
Ying Wang committed
300 301
rs_generated_res_dir := $(renderscript_intermediate.COMMON)/res
LOCAL_RESOURCE_DIR := $(rs_generated_res_dir) $(LOCAL_RESOURCE_DIR)
302 303
endif

304 305 306 307 308 309 310 311 312 313 314 315

###########################################################
## AIDL: Compile .aidl files to .java
###########################################################
aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))

ifneq ($(strip $(aidl_sources)),)
aidl_java_sources := $(patsubst %.aidl,%.java,$(addprefix $(intermediates.COMMON)/src/, $(aidl_sources)))
aidl_sources := $(addprefix $(LOCAL_PATH)/, $(aidl_sources))

aidl_preprocess_import :=
ifdef LOCAL_SDK_VERSION
316
ifneq ($(filter current system_current test_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS)),)
317 318 319 320 321 322 323 324 325 326 327 328 329
  # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
  aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
else
  aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
endif # not current or system_current
else
# build against the platform.
LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
endif # LOCAL_SDK_VERSION
$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b $(addprefix -p,$(aidl_preprocess_import)) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))

$(aidl_java_sources): $(intermediates.COMMON)/src/%.java: \
        $(LOCAL_PATH)/%.aidl \
330
        $(LOCAL_MODULE_MAKEFILE_DEP) \
331 332 333 334
        $(LOCAL_ADDITIONAL_DEPENDENCIES) \
        $(AIDL) \
        $(aidl_preprocess_import)
	$(transform-aidl-to-java)
335 336
$(foreach java,$(aidl_java_sources), \
    $(call include-depfile,$(java:%.java=%.P),$(java)))
337 338 339 340 341 342 343

else
aidl_java_sources :=
endif

##########################################

344 345 346 347
# All of the rules after full_classes_compiled_jar are very unlikely
# to fail except for bugs in their respective tools.  If you would
# like to run these rules, add the "all" modifier goal to the make
# command line.
Ying Wang's avatar
Ying Wang committed
348
ifndef LOCAL_CHECKED_MODULE
349
ifdef full_classes_jar
Yohann Roussel's avatar
Yohann Roussel committed
350 351 352
ifdef LOCAL_JACK_ENABLED
LOCAL_CHECKED_MODULE := $(jack_check_timestamp)
else
Ying Wang's avatar
Ying Wang committed
353 354
LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
endif
355
endif
Yohann Roussel's avatar
Yohann Roussel committed
356
endif
357

358 359 360 361
#######################################
include $(BUILD_SYSTEM)/base_rules.mk
#######################################

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
###########################################################
## logtags: emit java source
###########################################################
ifneq ($(strip $(logtags_sources)),)

logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/src/, $(logtags_sources)))
logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))

$(logtags_java_sources): $(intermediates.COMMON)/src/%.java: $(LOCAL_PATH)/%.logtags $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
	$(transform-logtags-to-java)

else
logtags_java_sources :=
endif

377 378 379 380 381 382 383
##########################################
java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
                $(filter %.java,$(LOCAL_GENERATED_SOURCES))
all_java_sources := $(java_sources) $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))

include $(BUILD_SYSTEM)/java_common.mk

384 385 386 387 388
#######################################
# defines built_odex along with rule to install odex
include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
#######################################

389 390 391 392 393 394 395
# Make sure there's something to build.
ifdef full_classes_jar
ifndef need_compile_java
$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
endif
endif

Yohann Roussel's avatar
Yohann Roussel committed
396 397 398
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_MIN_SDK_VERSION := $(my_jack_min_sdk_version)
my_jack_min_sdk_version :=

399 400 401 402
# Since we're using intermediates.COMMON, make sure that it gets cleaned
# properly.
$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)

403
ifdef full_classes_jar
404

405 406 407 408 409 410 411 412 413
# Droiddoc isn't currently able to generate stubs for modules, so we're just
# allowing it to use the classes.jar as the "stubs" that would be use to link
# against, for the cases where someone needs the jar to link against.
# - Use the classes.jar instead of the handful of other intermediates that
#   we have, because it's the most processed, but still hasn't had dex run on
#   it, so it's closest to what's on the device.
# - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the
#   PRIVATE_ vars to be preserved.
$(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar)
Yohann Roussel's avatar
Yohann Roussel committed
414
$(full_classes_stubs_jar) : $(full_classes_jar) | $(ACP)
415 416 417 418
	@echo Copying $(PRIVATE_SOURCE_FILE)
	$(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@
ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)

419 420 421 422
# The layers file allows you to enforce a layering between java packages.
# Run build/tools/java-layers.py for more details.
layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
Ying Wang's avatar
Ying Wang committed
423
$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
424

425 426 427 428
ifdef LOCAL_RMTYPEDEFS
$(full_classes_compiled_jar): | $(RMTYPEDEFS)
endif

429 430 431 432
# Compile the java files to a .jar file.
# This intentionally depends on java_sources, not all_java_sources.
# Deps for generated source files must be handled separately,
# via deps on the target that generates the sources.
Ying Wang's avatar
Ying Wang committed
433
$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS)
434
$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
Jeff Brown's avatar
Jeff Brown committed
435
$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
436
$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
Ying Wang's avatar
Ying Wang committed
437
$(full_classes_compiled_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
438 439 440 441 442 443 444 445
$(full_classes_compiled_jar): \
        $(java_sources) \
        $(java_resource_sources) \
        $(full_java_lib_deps) \
        $(jar_manifest_file) \
        $(layers_file) \
        $(RenderScript_file_stamp) \
        $(proto_java_sources_file_stamp) \
446
        $(LOCAL_MODULE_MAKEFILE_DEP) \
447
        $(LOCAL_ADDITIONAL_DEPENDENCIES)
448 449
	$(transform-java-to-classes.jar)

450 451 452
# Run jarjar if necessary, otherwise just copy the file.
ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
453
$(full_classes_jarjar_jar): $(full_classes_compiled_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
454 455 456 457 458
	@echo JarJar: $@
	$(hide) java -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
else
$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP)
	@echo Copying: $@
Ying Wang's avatar
Ying Wang committed
459
	$(hide) $(ACP) -fp $< $@
460 461
endif

462 463
full_classes_jar_source := $(full_classes_jarjar_jar)
ifndef LOCAL_JACK_ENABLED
464
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
Sebastien Hertz's avatar
Sebastien Hertz committed
465
$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.emma.ignore
466
$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
467 468 469 470 471 472 473 474 475
# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER
# in Android.mk
ifdef LOCAL_EMMA_COVERAGE_FILTER
$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
else
# by default, avoid applying emma instrumentation onto emma classes itself,
# otherwise there will be exceptions thrown
$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
endif
476 477
# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
# $(full_classes_emma_jar)
478
$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(EMMA_JAR)
479
	$(transform-classes.jar-to-emma)
480 481
full_classes_jar_source := $(full_classes_emma_jar)
endif
482 483
endif

484
# Keep a copy of the jar just before proguard processing.
485
$(full_classes_jar): $(full_classes_jar_source) | $(ACP)
486
	@echo Copying: $@
Ying Wang's avatar
Ying Wang committed
487
	$(hide) $(ACP) -fp $< $@
488

489 490
$(call define-jar-to-toc-rule, $(full_classes_jar))

491
# Run proguard if necessary, otherwise just copy the file.
492
ifdef LOCAL_PROGUARD_ENABLED
493
ifneq ($(filter-out full custom nosystem obfuscation optimization shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
494 495 496
    $(warning while processing: $(LOCAL_MODULE))
    $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
endif
497
proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
498
jack_dictionary := $(intermediates.COMMON)/jack_dictionary
499 500 501 502 503 504 505 506 507 508

# Hack: see b/20667396
# When an app's LOCAL_SDK_VERSION is lower than the support library's LOCAL_SDK_VERSION,
# we artifically raises the "SDK version" "linked" by ProGuard, to
# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
my_support_library_sdk_raise :=
ifneq (,$(filter android-support-%,$(LOCAL_STATIC_JAVA_LIBRARIES)))
ifdef LOCAL_SDK_VERSION
ifdef TARGET_BUILD_APPS
509
ifeq (,$(filter current system_current test_current, $(LOCAL_SDK_VERSION)))
510
  my_support_library_sdk_raise := $(call java-lib-files, sdk_vcurrent)
511
endif
512 513 514
else
  # For platform build, we can't just raise to the "current" SDK,
  # that would break apps that use APIs removed from the current SDK.
515
  my_support_library_sdk_raise := $(call java-lib-files,$(TARGET_DEFAULT_JAVA_LIBRARIES))
516 517 518 519
endif
endif
endif

Yohann Roussel's avatar
Yohann Roussel committed
520
# jack already has the libraries in its classpath and doesn't support jars
521
legacy_proguard_flags := $(addprefix -libraryjars ,$(my_support_library_sdk_raise) $(full_shared_java_libs))
522 523 524 525 526

legacy_proguard_flags += -printmapping $(proguard_dictionary)
jack_proguard_flags := -printmapping $(jack_dictionary)

common_proguard_flags := -forceprocessing
527 528

ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),)
Yohann Roussel's avatar
Yohann Roussel committed
529
common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.flags
530
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
531 532 533
ifdef LOCAL_JACK_ENABLED
common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
else
Yohann Roussel's avatar
Yohann Roussel committed
534
common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags
535
endif # LOCAL_JACK_ENABLED
536
endif
537
# If this is a test package, add proguard keep flags for tests.
538
ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
Yohann Roussel's avatar
Yohann Roussel committed
539
common_proguard_flags += -include $(BUILD_SYSTEM)/proguard_tests.flags
540
ifeq ($(filter shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
Yohann Roussel's avatar
Yohann Roussel committed
541
common_proguard_flags += -dontshrink # don't shrink tests by default
542
endif # shrinktests
543
endif # test package
544 545
ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
# By default no obfuscation
Yohann Roussel's avatar
Yohann Roussel committed
546
common_proguard_flags += -dontobfuscate
547 548 549
endif  # No obfuscation
ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
# By default no optimization
Yohann Roussel's avatar
Yohann Roussel committed
550
common_proguard_flags += -dontoptimize
551 552 553 554 555 556
endif  # No optimization

ifdef LOCAL_INSTRUMENTATION_FOR
ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
# If no obfuscation, link in the instrmented package's classes.jar as a library.
# link_instr_classes_jar is defined in base_rule.mk
Yohann Roussel's avatar
Yohann Roussel committed
557 558
# jack already has this library in its classpath and doesn't support jars
legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
559 560 561 562
else # obfuscation
# If obfuscation is enabled, the main app must be obfuscated too.
# We need to run obfuscation using the main app's dictionary,
# and treat the main app's class.jar as injars instead of libraryjars.
Yohann Roussel's avatar
Yohann Roussel committed
563
legacy_proguard_flags := -injars  $(link_instr_classes_jar) \
564 565 566 567
    -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
    -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
    -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
    -verbose \
Yohann Roussel's avatar
Yohann Roussel committed
568
    $(legacy_proguard_flags)
569
ifdef LOCAL_JACK_ENABLED
570 571
jack_proguard_flags += -applymapping $(link_instr_intermediates_dir.COMMON)/jack_dictionary
full_jack_deps += $(link_instr_intermediates_dir.COMMON)/jack_dictionary
Yohann Roussel's avatar
Yohann Roussel committed
572
endif
573 574 575

# Sometimes (test + main app) uses different keep rules from the main app -
# apply the main app's dictionary anyway.
Yohann Roussel's avatar
Yohann Roussel committed
576
legacy_proguard_flags += -ignorewarnings
577 578 579 580 581 582 583

# Make sure we run Proguard on the main app first
$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar

endif # no obfuscation
endif # LOCAL_INSTRUMENTATION_FOR
endif  # LOCAL_PROGUARD_ENABLED is not nosystem
584

585 586 587
proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))

588 589 590 591 592 593
ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
else
extra_input_jar :=
endif
$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
Yohann Roussel's avatar
Yohann Roussel committed
594
$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
595
$(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(proguard_flag_files) | $(ACP) $(PROGUARD)
596 597
	$(call transform-jar-to-proguard)

598 599 600 601 602 603 604
else  # LOCAL_PROGUARD_ENABLED not defined
$(full_classes_proguard_jar) : $(full_classes_jar)
	@echo Copying: $@
	$(hide) $(ACP) -fp $< $@

endif # LOCAL_PROGUARD_ENABLED defined

605
ifndef LOCAL_JACK_ENABLED
606 607 608 609
# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
# will work even when intermediates != intermediates.COMMON.
$(built_dex_intermediate): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
610 611 612 613 614 615
# If you instrument class files that have local variable debug information in
# them emma does not correctly maintain the local variable table.
# This will cause an error when you try to convert the class files for Android.
# The workaround here is to build different dex file here based on emma switch
# then later copy into classes.dex. When emma is on, dx is run with --no-locals
# option to remove local variable information
616
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
617 618
$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
endif
619
endif # LOCAL_JACK_ENABLED is disabled
Yohann Roussel's avatar
Yohann Roussel committed
620

621 622
$(built_dex): $(built_dex_intermediate) | $(ACP)
	@echo Copying: $@
623 624 625
	$(hide) mkdir -p $(dir $@)
	$(hide) rm -f $(dir $@)/classes*.dex
	$(hide) $(ACP) -fp $(dir $<)/classes*.dex $(dir $@)
626 627 628 629 630
ifneq ($(GENERATE_DEX_DEBUG),)
	$(install-dex-debug)
endif

findbugs_xml := $(intermediates.COMMON)/findbugs.xml
631 632 633 634
$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
    $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
$(findbugs_xml) : $(full_classes_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
635 636
	@echo Findbugs: $@
	$(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
637
		$(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \
638
		$< \
639 640 641 642 643 644 645 646 647
		> $@

ALL_FINDBUGS_FILES += $(findbugs_xml)

findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
$(LOCAL_MODULE)-findbugs : $(findbugs_html)
$(findbugs_html) : $(findbugs_xml)
	@mkdir -p $(dir $@)
648
	@echo ConvertXmlToText: $@
Yuncheol Heo's avatar
Yuncheol Heo committed
649
	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
650 651 652 653
	> $@

$(LOCAL_MODULE)-findbugs : $(findbugs_html)

654
endif  # full_classes_jar is defined
Yohann Roussel's avatar
Yohann Roussel committed
655

656
ifdef LOCAL_JACK_ENABLED
Yohann Roussel's avatar
Yohann Roussel committed
657
$(LOCAL_INTERMEDIATE_TARGETS): \
658 659 660 661
	PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc
ifeq ($(LOCAL_JACK_ENABLED),incremental)
$(LOCAL_INTERMEDIATE_TARGETS): \
	PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-incremental
Yohann Roussel's avatar
Yohann Roussel committed
662 663
$(noshrob_classes_jack): PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-noshrob-incremental
$(jack_check_timestamp): PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-check-incremental
664 665 666
else
$(LOCAL_INTERMEDIATE_TARGETS): \
	PRIVATE_JACK_INCREMENTAL_DIR :=
Yohann Roussel's avatar
Yohann Roussel committed
667 668
$(noshrob_classes_jack): PRIVATE_JACK_INCREMENTAL_DIR :=
$(jack_check_timestamp): PRIVATE_JACK_INCREMENTAL_DIR :=
669
endif
Yohann Roussel's avatar
Yohann Roussel committed
670 671 672 673 674 675 676 677 678 679 680 681

ifdef full_classes_jar
ifdef LOCAL_PROGUARD_ENABLED

ifndef LOCAL_JACK_PROGUARD_FLAGS
    LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
endif
LOCAL_JACK_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
    $(error $(LOCAL_MODULE): Build with jack when LOCAL_TEST_MODULE_TO_PROGUARD_WITH is defined is not yet implemented)
endif

682 683 684 685 686 687 688
# $(jack_dictionary) is just by-product of $(built_dex_intermediate).
# The dummy command was added because, without it, make misses the fact the $(built_dex) also
# change $(jack_dictionary).
$(jack_dictionary): $(full_classes_jack)
	$(hide) touch $@

$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_PROGUARD_FLAGS := $(common_proguard_flags) $(jack_proguard_flags) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Roussel's avatar
Yohann Roussel committed
689 690 691 692
else  # LOCAL_PROGUARD_ENABLED not defined
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_PROGUARD_FLAGS :=
endif # LOCAL_PROGUARD_ENABLED defined

Ying Wang's avatar
Ying Wang committed
693
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_FLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JACK_FLAGS)
694
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION)
Yohann Roussel's avatar
Yohann Roussel committed
695

696
jack_all_deps := $(java_sources) $(java_resource_sources) $(full_jack_deps) \
Yohann Roussel's avatar
Yohann Roussel committed
697 698
        $(jar_manifest_file) $(layers_file) $(RenderScript_file_stamp) $(proguard_flag_files) \
        $(proto_java_sources_file_stamp) $(LOCAL_ADDITIONAL_DEPENDENCIES) $(LOCAL_JARJAR_RULES) \
699
        $(LOCAL_MODULE_MAKEFILE_DEP) $(JACK)
Yohann Roussel's avatar
Yohann Roussel committed
700

701
$(jack_check_timestamp): $(jack_all_deps) | setup-jack-server
Yohann Roussel's avatar
Yohann Roussel committed
702 703 704
	@echo Checking build with Jack: $@
	$(jack-check-java)

Yohann Roussel's avatar
Yohann Roussel committed
705
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
706
$(full_classes_jack): $(jack_all_deps) | setup-jack-server
Yohann Roussel's avatar
Yohann Roussel committed
707 708 709
	@echo Building with Jack: $@
	$(java-to-jack)

710 711 712 713 714
# Update timestamps of .toc files for static java libraries so
# dependents will be always rebuilt.
$(built_dex).toc: $(full_classes_jack)
	touch $@

Yohann Roussel's avatar
Yohann Roussel committed
715 716 717
else #LOCAL_IS_STATIC_JAVA_LIBRARY
$(built_dex_intermediate): PRIVATE_CLASSES_JACK := $(full_classes_jack)

718 719
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
$(built_dex_intermediate): PRIVATE_JACK_COVERAGE_OPTIONS := \
720
    -D jack.coverage=true \
721
    -D jack.coverage.metadata.file=$(intermediates.COMMON)/coverage.em \
722 723 724
    -D jack.coverage.jacoco.package=$(JACOCO_PACKAGE_NAME) \
    $(addprefix -D jack.coverage.jacoco.include=,$(LOCAL_JACK_COVERAGE_INCLUDE_FILTER)) \
    $(addprefix -D jack.coverage.jacoco.exclude=,$(LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))
725 726 727 728
else
$(built_dex_intermediate): PRIVATE_JACK_COVERAGE_OPTIONS :=
endif

729
$(built_dex_intermediate): $(jack_all_deps) | setup-jack-server
Yohann Roussel's avatar
Yohann Roussel committed
730 731 732
	@echo Building with Jack: $@
	$(jack-java-to-dex)

Ying Wang's avatar
Ying Wang committed
733 734 735
# $(full_classes_jack) is just by-product of $(built_dex_intermediate).
# The dummy command was added because, without it, make misses the fact the $(built_dex) also
# change $(full_classes_jack).
Yohann Roussel's avatar
Yohann Roussel committed
736
$(full_classes_jack): $(built_dex_intermediate)
Ying Wang's avatar
Ying Wang committed
737
	$(hide) touch $@
738

739 740
$(call define-dex-to-toc-rule, $(intermediates.COMMON))

Yohann Roussel's avatar
Yohann Roussel committed
741 742
endif #LOCAL_IS_STATIC_JAVA_LIBRARY

743
$(noshrob_classes_jack): PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-noshrob-rsc
Yohann Roussel's avatar
Yohann Roussel committed
744
$(noshrob_classes_jack): PRIVATE_JACK_PROGUARD_FLAGS :=
745
$(noshrob_classes_jack): $(jack_all_deps) | setup-jack-server
Yohann Roussel's avatar
Yohann Roussel committed
746 747 748
	@echo Building with Jack: $@
	$(java-to-jack)
endif  # full_classes_jar is defined
749
endif # LOCAL_JACK_ENABLED