1## 2# Environment dependent variables 3## 4 5AAPT := aapt2 6ZIPALIGN := zipalign -f 4 7FRAMEWORK := ../../../../../out/target/common/obj/APPS/framework-res_intermediates/package-export.apk 8 9## 10# Project depenedent variables 11## 12 13LOCAL_PACKAGE := com.android.app 14LOCAL_RESOURCE_DIR := res 15LOCAL_LIBS := lib/out/package.apk 16LOCAL_OUT := out 17LOCAL_GEN := out/gen 18LOCAL_PROGUARD := out/proguard.rule 19 20## 21# AAPT2 custom rules. 22## 23 24PRIVATE_APK_UNALIGNED := $(LOCAL_OUT)/package-unaligned.apk 25PRIVATE_APK_ALIGNED := $(LOCAL_OUT)/package.apk 26 27# Eg: framework.apk, etc. 28PRIVATE_INCLUDES := $(FRAMEWORK) 29$(info PRIVATE_INCLUDES = $(PRIVATE_INCLUDES)) 30 31# Eg: gen/com/android/app/R.java 32PRIVATE_R_JAVA := $(LOCAL_GEN)/$(subst .,/,$(LOCAL_PACKAGE))/R.java 33$(info PRIVATE_R_JAVA = $(PRIVATE_R_JAVA)) 34 35# Eg: res/drawable/icon.png, res/values/styles.xml 36PRIVATE_RESOURCES := $(shell find $(LOCAL_RESOURCE_DIR) -mindepth 1 -maxdepth 2 -type f) 37$(info PRIVATE_RESOURCES = $(PRIVATE_RESOURCES)) 38 39# Eg: drawable, values, layouts 40PRIVATE_RESOURCE_TYPES := \ 41 $(patsubst $(LOCAL_RESOURCE_DIR)/%/,%,$(sort $(dir $(PRIVATE_RESOURCES)))) 42$(info PRIVATE_RESOURCE_TYPES = $(PRIVATE_RESOURCE_TYPES)) 43 44# Eg: out/values-v4.apk, out/drawable-xhdpi.apk 45PRIVATE_INTERMEDIATE_TABLES := $(patsubst %,$(LOCAL_OUT)/%.apk,$(PRIVATE_RESOURCE_TYPES)) 46$(info PRIVATE_INTERMEDIATE_TABLES = $(PRIVATE_INTERMEDIATE_TABLES)) 47 48# Generates rules for collect phase. 49# $1: Resource type (values-v4) 50# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml 51define make-collect-rule 52$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES)) 53 $(AAPT) compile -o $$@ $$^ 54endef 55 56# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml 57$(foreach d,$(PRIVATE_RESOURCE_TYPES),$(eval $(call make-collect-rule,$d))) 58 59# Link: out/package-unaligned.apk <- out/values-v4.apk out/drawable-v4.apk 60$(PRIVATE_APK_UNALIGNED): $(PRIVATE_INTERMEDIATE_TABLES) $(PRIVATE_INCLUDES) $(LOCAL_LIBS) AndroidManifest.xml 61 $(AAPT) link --manifest AndroidManifest.xml $(addprefix -I ,$(PRIVATE_INCLUDES)) --java $(LOCAL_GEN) -o $@ $(PRIVATE_INTERMEDIATE_TABLES) $(LOCAL_LIBS) --proguard $(LOCAL_PROGUARD) -v 62 63# R.java: gen/com/android/app/R.java <- out/resources.arsc 64# No action since R.java is generated when out/resources.arsc is. 65$(PRIVATE_R_JAVA): $(PRIVATE_APK_UNALIGNED) 66 67# Assemble: zip out/resources.arsc AndroidManifest.xml and res/**/* 68$(PRIVATE_APK_ALIGNED): $(PRIVATE_APK_UNALIGNED) 69 $(ZIPALIGN) $< $@ 70 71# Create the out directory if needed. 72dummy := $(shell test -d $(LOCAL_OUT) || mkdir -p $(LOCAL_OUT)) 73 74.PHONY: java 75java: $(PRIVATE_R_JAVA) 76 77.PHONY: assemble 78assemble: $(PRIVATE_APK_ALIGNED) 79 80.PHONY: all 81all: assemble java 82 83.DEFAULT_GOAL := all 84