diff options
| author | 2018-06-11 14:13:37 +0200 | |
|---|---|---|
| committer | 2018-10-09 14:02:14 +0000 | |
| commit | f99eda450f172f13affa1c08ebea9c3be00ac4b6 (patch) | |
| tree | 5b7872322e5d57fb2aa8b7e66d0a81ecbb4d7e2a | |
| parent | 3f1f4fc11d2e19c4b297a97d21293d05ac3db622 (diff) | |
AAPT2: optionally keep resources without default value
Teach "aapt2 link" about a new flag --no-resource-removal. When given,
aapt2 will not filter out resources that lack default values. This is
useful mostly when building overlay packages that define resources for
non-default configurations, such as only for values-sv.
Test: manual: build package with resource only in values-vs, verify apk with aapt2 dump
Change-Id: Idc513bcb3f43bbff7f073163562c3dfccdb9bc9b
Merged-In: Idc513bcb3f43bbff7f073163562c3dfccdb9bc9b
5 files changed, 19 insertions, 4 deletions
diff --git a/core/tests/overlaytests/device/test-apps/AppOverlayOne/Android.mk b/core/tests/overlaytests/device/test-apps/AppOverlayOne/Android.mk index edad4b26314c..97a3d0078e26 100644 --- a/core/tests/overlaytests/device/test-apps/AppOverlayOne/Android.mk +++ b/core/tests/overlaytests/device/test-apps/AppOverlayOne/Android.mk @@ -20,4 +20,6 @@ LOCAL_PACKAGE_NAME := OverlayDeviceTests_AppOverlayOne LOCAL_SDK_VERSION := current LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_CERTIFICATE := platform +LOCAL_USE_AAPT2 := true +LOCAL_AAPT_FLAGS := --no-resource-removal include $(BUILD_PACKAGE) diff --git a/core/tests/overlaytests/device/test-apps/AppOverlayTwo/Android.mk b/core/tests/overlaytests/device/test-apps/AppOverlayTwo/Android.mk index 3fae8e19fc5b..a3470255997d 100644 --- a/core/tests/overlaytests/device/test-apps/AppOverlayTwo/Android.mk +++ b/core/tests/overlaytests/device/test-apps/AppOverlayTwo/Android.mk @@ -20,4 +20,6 @@ LOCAL_PACKAGE_NAME := OverlayDeviceTests_AppOverlayTwo LOCAL_SDK_VERSION := current LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_CERTIFICATE := platform +LOCAL_USE_AAPT2 := true +LOCAL_AAPT_FLAGS := --no-resource-removal include $(BUILD_PACKAGE) diff --git a/core/tests/overlaytests/device/test-apps/FrameworkOverlay/Android.mk b/core/tests/overlaytests/device/test-apps/FrameworkOverlay/Android.mk index c352c0550034..e4819e138eba 100644 --- a/core/tests/overlaytests/device/test-apps/FrameworkOverlay/Android.mk +++ b/core/tests/overlaytests/device/test-apps/FrameworkOverlay/Android.mk @@ -20,4 +20,6 @@ LOCAL_PACKAGE_NAME := OverlayDeviceTests_FrameworkOverlay LOCAL_SDK_VERSION := current LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_CERTIFICATE := platform +LOCAL_USE_AAPT2 := true +LOCAL_AAPT_FLAGS := --no-resource-removal include $(BUILD_PACKAGE) diff --git a/core/tests/overlaytests/host/test-apps/UpdateOverlay/Android.mk b/core/tests/overlaytests/host/test-apps/UpdateOverlay/Android.mk index ab3faf0b158a..8656781e31e5 100644 --- a/core/tests/overlaytests/host/test-apps/UpdateOverlay/Android.mk +++ b/core/tests/overlaytests/host/test-apps/UpdateOverlay/Android.mk @@ -21,6 +21,8 @@ LOCAL_PACKAGE_NAME := OverlayHostTests_UpdateOverlay LOCAL_SDK_VERSION := current LOCAL_COMPATIBILITY_SUITE := general-tests LOCAL_STATIC_JAVA_LIBRARIES := android-support-test +LOCAL_USE_AAPT2 := true +LOCAL_AAPT_FLAGS := --no-resource-removal include $(BUILD_PACKAGE) my_package_prefix := com.android.server.om.hosttest.framework_overlay diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp index db42e7cb3e02..670a2de3cfd2 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -105,6 +105,7 @@ struct LinkOptions { bool no_version_vectors = false; bool no_version_transitions = false; bool no_resource_deduping = false; + bool no_resource_removal = false; bool no_xml_namespaces = false; bool do_not_compress_anything = false; std::unordered_set<std::string> extensions_to_not_compress; @@ -1806,10 +1807,12 @@ class LinkCommand { // Before we process anything, remove the resources whose default values don't exist. // We want to force any references to these to fail the build. - if (!NoDefaultResourceRemover{}.Consume(context_, &final_table_)) { - context_->GetDiagnostics()->Error(DiagMessage() - << "failed removing resources with no defaults"); - return 1; + if (!options_.no_resource_removal) { + if (!NoDefaultResourceRemover{}.Consume(context_, &final_table_)) { + context_->GetDiagnostics()->Error(DiagMessage() + << "failed removing resources with no defaults"); + return 1; + } } ReferenceLinker linker; @@ -2084,6 +2087,10 @@ int Link(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) { "Disables automatic deduping of resources with\n" "identical values across compatible configurations.", &options.no_resource_deduping) + .OptionalSwitch("--no-resource-removal", + "Disables automatic removal of resources without defaults. Use this only\n" + "when building runtime resource overlay packages.", + &options.no_resource_removal) .OptionalSwitch("--enable-sparse-encoding", "Enables encoding sparse entries using a binary search tree.\n" "This decreases APK size at the cost of resource retrieval performance.", |