Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 1 | # |
| 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 | |
Colin Cross | 5b89ec4 | 2018-05-23 17:20:58 +0000 | [diff] [blame] | 20 | ifneq ($(FORCE_AAPT2),false) |
Colin Cross | d443244 | 2018-05-15 15:25:20 -0700 | [diff] [blame] | 21 | ifeq ($(LOCAL_USE_AAPT2),) |
Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 22 | # Force AAPT2 on |
| 23 | LOCAL_USE_AAPT2 := true |
Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 24 | # Filter out support library resources |
| 25 | LOCAL_RESOURCE_DIR := $(filter-out \ |
| 26 | prebuilts/sdk/current/% \ |
| 27 | frameworks/support/%,\ |
| 28 | $(LOCAL_RESOURCE_DIR)) |
| 29 | # Filter out unnecessary aapt flags |
Colin Cross | 282065a | 2018-05-17 07:13:43 -0700 | [diff] [blame] | 30 | ifneq (,$(filter --extra-packages,$(LOCAL_AAPT_FLAGS))) |
| 31 | LOCAL_AAPT_FLAGS := $(subst --extra-packages=,--extra-packages$(space), \ |
| 32 | $(filter-out \ |
| 33 | --extra-packages=android.support.% \ |
| 34 | --extra-packages=androidx.%, \ |
| 35 | $(subst --extra-packages$(space),--extra-packages=,$(LOCAL_AAPT_FLAGS)))) |
| 36 | ifeq (,$(filter --extra-packages,$(LOCAL_AAPT_FLAGS))) |
| 37 | LOCAL_AAPT_FLAGS := $(filter-out --auto-add-overlay,$(LOCAL_AAPT_FLAGS)) |
| 38 | endif |
| 39 | endif |
Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 40 | |
| 41 | # AAPT2 is pickier about missing resources. Support library may have references to resources |
| 42 | # added in current, so always treat LOCAL_SDK_VERSION as LOCAL_SDK_RES_VERSION := current. |
| 43 | ifdef LOCAL_SDK_VERSION |
| 44 | LOCAL_SDK_RES_VERSION := current |
| 45 | endif |
| 46 | |
| 47 | ifeq (,$(strip $(LOCAL_MANIFEST_FILE)$(LOCAL_FULL_MANIFEST_FILE))) |
| 48 | ifeq (,$(wildcard $(LOCAL_PATH)/AndroidManifest.xml)) |
| 49 | # work around missing manifests by creating a default one |
Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 50 | LOCAL_FULL_MANIFEST_FILE := $(call local-intermediates-dir,COMMON)/DefaultManifest.xml |
Colin Cross | d45079a | 2018-05-23 16:32:48 -0700 | [diff] [blame] | 51 | ifdef LOCAL_MIN_SDK_VERSION |
| 52 | my_manifest_min_sdk_version := $(LOCAL_MIN_SDK_VERSION) |
| 53 | else ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION))) |
| 54 | my_manifest_min_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)) |
| 55 | else |
| 56 | my_manifest_min_sdk_version := $(DEFAULT_APP_TARGET_SDK) |
| 57 | endif |
| 58 | $(call create-default-manifest-file,$(LOCAL_FULL_MANIFEST_FILE),$(my_manifest_min_sdk_version)) |
| 59 | my_manifest_min_sdk_version := |
Colin Cross | 2029903 | 2018-05-09 13:29:51 -0700 | [diff] [blame] | 60 | endif |
| 61 | endif |
| 62 | endif |
| 63 | endif |
| 64 | |
| 65 | ifneq ($(LOCAL_USE_AAPT2),true) |
| 66 | ifneq ($(LOCAL_USE_AAPT2),false) |
| 67 | ifneq ($(LOCAL_USE_AAPT2),) |
| 68 | $(call pretty-error,Invalid value for LOCAL_USE_AAPT2: "$(LOCAL_USE_AAPT2)") |
| 69 | endif |
| 70 | endif |
| 71 | endif |