Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64587af8 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

AAPT2: Support building, linking, and merging static libraries

Android static libraries are like APKs but they contain much more debugging
and source information. We need to treat them differently in 3 ways:

1) When building a static library, we skip things like ID assignment and
   product/config stripping. Source information is emitted as well.
2) When building a static library and linking against another
   static library, we don't want to merge, we want to simply reference.
3) When building an app that uses static libraries, we want to merge
   the static library under the same package with or without mangling.

Bug:25958912
Change-Id: I425e032857936a3e83173c1edc2a6cdc6020b842
parent bd4b217a
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -13,15 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This tool is prebuilt if we're doing an app-only build.
ifeq ($(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)),)
LOCAL_PATH:= $(call my-dir)

# ==========================================================
# Setup some common variables for the different build
# targets here.
# ==========================================================
LOCAL_PATH:= $(call my-dir)

main := Main.cpp
sources := \
@@ -192,4 +189,6 @@ LOCAL_C_INCLUDES += $(protoIncludes)

include $(BUILD_HOST_EXECUTABLE)

endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK
ifeq ($(ONE_SHOT_MAKEFILE),)
include $(call all-makefiles-under,$(LOCAL_PATH))
endif
+9 −7
Original line number Diff line number Diff line
@@ -422,10 +422,6 @@ static bool compileFile(IAaptContext* context, const CompileOptions& options,
}

class CompileContext : public IAaptContext {
private:
    StdErrDiagnostics mDiagnostics;
    bool mVerbose = false;

public:
    void setVerbose(bool val) {
        mVerbose = val;
@@ -444,18 +440,24 @@ public:
       return nullptr;
    }

    StringPiece16 getCompilationPackage() override {
       return {};
    const std::u16string& getCompilationPackage() override {
        static std::u16string empty;
        return empty;
    }

    uint8_t getPackageId() override {
       return 0x0;
    }

    ISymbolTable* getExternalSymbols() override {
    SymbolTable* getExternalSymbols() override {
       abort();
       return nullptr;
    }

private:
    StdErrDiagnostics mDiagnostics;
    bool mVerbose = false;

};

/**
+0 −7
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.app">
    <application
        android:name=".ActivityMain">
    </application>
</manifest>

tools/aapt2/data/Makefile

deleted100644 → 0
+0 −61
Original line number Diff line number Diff line
##
# Environment dependent variables
##

AAPT := aapt2
ZIPALIGN := zipalign -f 4
FRAMEWORK := ../../../../../out/target/common/obj/APPS/framework-res_intermediates/package-export.apk

##
# Project depenedent variables
##

LOCAL_PACKAGE := com.android.app
LOCAL_RESOURCE_DIR := res
LOCAL_LIBS := lib/out/package.apk
LOCAL_OUT := out
LOCAL_GEN := out/gen
LOCAL_PROGUARD := out/proguard.rule

##
# AAPT2 custom rules.
##

PRIVATE_R_FILE := $(LOCAL_GEN)/$(subst .,/,$(LOCAL_PACKAGE))/R.java
$(info PRIVATE_R_FILE = $(PRIVATE_R_FILE))

# Eg: framework.apk, etc.
PRIVATE_INCLUDES := $(FRAMEWORK)
$(info PRIVATE_INCLUDES = $(PRIVATE_INCLUDES))

# Eg: res/drawable/icon.png, res/values/styles.xml
PRIVATE_RESOURCES := $(shell find $(LOCAL_RESOURCE_DIR) -mindepth 1 -maxdepth 2 -type f)
$(info PRIVATE_RESOURCES = $(PRIVATE_RESOURCES))

PRIVATE_RESOURCE_OBJECTS := $(subst /,_,$(patsubst $(LOCAL_RESOURCE_DIR)/%,%,$(filter $(LOCAL_RESOURCE_DIR)/values%,$(PRIVATE_RESOURCES))))
PRIVATE_RESOURCE_OBJECTS := $(addprefix $(LOCAL_OUT)/,$(PRIVATE_RESOURCE_OBJECTS:.xml=.arsc.flat))
$(info PRIVATE_RESOURCE_OBJECTS = $(PRIVATE_RESOURCE_OBJECTS))

PRIVATE_FILE_OBJECTS := $(subst /,_,$(patsubst $(LOCAL_RESOURCE_DIR)/%,%,$(filter-out $(LOCAL_RESOURCE_DIR)/values%,$(PRIVATE_RESOURCES))))
PRIVATE_FILE_OBJECTS := $(addprefix $(LOCAL_OUT)/,$(addsuffix .flat,$(PRIVATE_FILE_OBJECTS)))
$(info PRIVATE_FILE_OBJECTS = $(PRIVATE_FILE_OBJECTS))

.SECONDEXPANSION:

$(LOCAL_OUT)/%.arsc.flat: $(LOCAL_RESOURCE_DIR)/$$(subst _,/,%).xml
	$(AAPT) compile -o $(LOCAL_OUT) $<

$(LOCAL_OUT)/%.flat: $(LOCAL_RESOURCE_DIR)/$$(subst _,/,%)
	$(AAPT) compile -o $(LOCAL_OUT) $<

$(LOCAL_PROGUARD) $(LOCAL_OUT)/package.apk: AndroidManifest.xml
$(PRIVATE_R_FILE) $(LOCAL_PROGUARD) $(LOCAL_OUT)/package.apk: $(PRIVATE_FILE_OBJECTS) $(PRIVATE_RESOURCE_OBJECTS)
	$(AAPT) link -o $(LOCAL_OUT)/package.apk --manifest AndroidManifest.xml --java $(LOCAL_GEN) --proguard $(LOCAL_PROGUARD) -I $(PRIVATE_INCLUDES) $(filter-out AndroidManifest.xml,$^) -v

# Create the out directory if needed.
dummy := $(shell test -d $(LOCAL_OUT) || mkdir -p $(LOCAL_OUT))

.PHONY: all
all: $(LOCAL_OUT)/package.apk $(LOCAL_PROGUARD) $(PRIVATE_R_FILE)

.DEFAULT_GOAL := all
+0 −6
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.appcompat">

    <uses-feature android:name="bloooop" />
</manifest>
Loading