blob: 41bf710e8d00a5e85b15ff6285df666132e6757b [file] [log] [blame]
Colin Cross20299032018-05-09 13:29:51 -07001#
2# Copyright (C) 2018 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# Including this makefile will force AAPT2 on if FORCE_AAPT2==true,
18# rewriting some properties to convert standard AAPT usage to AAPT2.
19
20ifeq ($(FORCE_AAPT2),true)
Colin Crossd4432442018-05-15 15:25:20 -070021 ifeq ($(LOCAL_USE_AAPT2),)
Colin Cross20299032018-05-09 13:29:51 -070022 # Force AAPT2 on
23 LOCAL_USE_AAPT2 := true
24 # Move LOCAL_STATIC_JAVA_AAR_LIBRARIES to LOCAL_STATIC_ANDROID_LIBRARIES
25 LOCAL_STATIC_ANDROID_LIBRARIES := $(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
26 LOCAL_STATIC_JAVA_AAR_LIBRARIES :=
27 # Filter out support library resources
28 LOCAL_RESOURCE_DIR := $(filter-out \
29 prebuilts/sdk/current/% \
30 frameworks/support/%,\
31 $(LOCAL_RESOURCE_DIR))
32 # Filter out unnecessary aapt flags
33 LOCAL_AAPT_FLAGS := $(subst --extra-packages=,--extra-packages$(space), \
34 $(filter-out \
35 --extra-packages=android.support.% \
36 --extra-packages=androidx.% \
37 --auto-add-overlay,\
38 $(subst --extra-packages$(space),--extra-packages=,$(LOCAL_AAPT_FLAGS))))
39
40 # AAPT2 is pickier about missing resources. Support library may have references to resources
41 # added in current, so always treat LOCAL_SDK_VERSION as LOCAL_SDK_RES_VERSION := current.
42 ifdef LOCAL_SDK_VERSION
43 LOCAL_SDK_RES_VERSION := current
44 endif
45
46 ifeq (,$(strip $(LOCAL_MANIFEST_FILE)$(LOCAL_FULL_MANIFEST_FILE)))
47 ifeq (,$(wildcard $(LOCAL_PATH)/AndroidManifest.xml))
48 # work around missing manifests by creating a default one
49 $(call pretty-warning, Missing manifest file)
50 LOCAL_FULL_MANIFEST_FILE := $(call local-intermediates-dir,COMMON)/DefaultManifest.xml
51 $(call create-default-manifest-file,$(LOCAL_FULL_MANIFEST_FILE))
52 endif
53 endif
54 endif
55endif
56
57ifneq ($(LOCAL_USE_AAPT2),true)
58 ifneq ($(LOCAL_USE_AAPT2),false)
59 ifneq ($(LOCAL_USE_AAPT2),)
60 $(call pretty-error,Invalid value for LOCAL_USE_AAPT2: "$(LOCAL_USE_AAPT2)")
61 endif
62 endif
63endif