Loading tools/aapt2/cmd/Link.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -269,6 +269,7 @@ struct ResourceFileFlattenerOptions { bool keep_raw_values = false; bool do_not_compress_anything = false; bool update_proguard_spec = false; bool do_not_fail_on_missing_resources = false; OutputFormat output_format = OutputFormat::kApk; std::unordered_set<std::string> extensions_to_not_compress; Maybe<std::regex> regex_to_not_compress; Loading Loading @@ -435,7 +436,7 @@ std::vector<std::unique_ptr<xml::XmlResource>> ResourceFileFlattener::LinkAndVer xml::StripAndroidStudioAttributes(doc->root.get()); XmlReferenceLinker xml_linker; if (!xml_linker.Consume(context_, doc)) { if (!options_.do_not_fail_on_missing_resources && !xml_linker.Consume(context_, doc)) { return {}; } Loading Loading @@ -1674,6 +1675,7 @@ class Linker { file_flattener_options.update_proguard_spec = static_cast<bool>(options_.generate_proguard_rules_path); file_flattener_options.output_format = options_.output_format; file_flattener_options.do_not_fail_on_missing_resources = options_.merge_only; ResourceFileFlattener file_flattener(file_flattener_options, context_, keep_set); if (!file_flattener.Flatten(table, writer)) { Loading Loading @@ -1901,7 +1903,7 @@ class Linker { } ReferenceLinker linker; if (!linker.Consume(context_, &final_table_)) { if (!options_.merge_only && !linker.Consume(context_, &final_table_)) { context_->GetDiagnostics()->Error(DiagMessage() << "failed linking references"); return 1; } Loading Loading @@ -2053,7 +2055,7 @@ class Linker { manifest_xml->file.name.package = context_->GetCompilationPackage(); XmlReferenceLinker manifest_linker; if (manifest_linker.Consume(context_, manifest_xml.get())) { if (options_.merge_only || manifest_linker.Consume(context_, manifest_xml.get())) { if (options_.generate_proguard_rules_path && !proguard::CollectProguardRulesForManifest(manifest_xml.get(), &proguard_keep_set)) { error = true; Loading Loading @@ -2187,6 +2189,12 @@ int LinkCommand::Action(const std::vector<std::string>& args) { return 1; } if (options_.merge_only && !static_lib_) { context.GetDiagnostics()->Error( DiagMessage() << "the --merge-only flag can be only used when building a static library"); return 1; } // The default build type. context.SetPackageType(PackageType::kApp); context.SetPackageId(kAppPackageId); Loading tools/aapt2/cmd/Link.h +5 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ struct LinkOptions { // Static lib options. bool no_static_lib_packages = false; bool merge_only = false; // AndroidManifest.xml massaging options. ManifestFixerOptions manifest_fixer_options; Loading Loading @@ -285,6 +286,10 @@ class LinkCommand : public Command { AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", &trace_folder_); AddOptionalSwitch("--merge-only", "Only merge the resources, without verifying resource references. This flag\n" "should only be used together with the --static-lib flag.", &options_.merge_only); } int Action(const std::vector<std::string>& args) override; Loading tools/aapt2/integration-tests/MergeOnlyTest/Android.mk 0 → 100644 +2 −0 Original line number Diff line number Diff line LOCAL_PATH := $(call my-dir) include $(call all-makefiles-under,$(LOCAL_PATH)) tools/aapt2/integration-tests/MergeOnlyTest/App/Android.mk 0 → 100644 +29 −0 Original line number Diff line number Diff line // // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_USE_AAPT2 := true LOCAL_AAPT_NAMESPACES := true LOCAL_PACKAGE_NAME := AaptTestMergeOnly_App LOCAL_SDK_VERSION := current LOCAL_EXPORT_PACKAGE_RESOURCES := true LOCAL_MODULE_TAGS := tests LOCAL_STATIC_ANDROID_LIBRARIES := \ AaptTestMergeOnly_LeafLib \ AaptTestMergeOnly_LocalLib include $(BUILD_PACKAGE) No newline at end of file tools/aapt2/integration-tests/MergeOnlyTest/App/AndroidManifest.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.app"> <application android:label="@*com.local.lib:string/lib_string"/> </manifest> No newline at end of file Loading
tools/aapt2/cmd/Link.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -269,6 +269,7 @@ struct ResourceFileFlattenerOptions { bool keep_raw_values = false; bool do_not_compress_anything = false; bool update_proguard_spec = false; bool do_not_fail_on_missing_resources = false; OutputFormat output_format = OutputFormat::kApk; std::unordered_set<std::string> extensions_to_not_compress; Maybe<std::regex> regex_to_not_compress; Loading Loading @@ -435,7 +436,7 @@ std::vector<std::unique_ptr<xml::XmlResource>> ResourceFileFlattener::LinkAndVer xml::StripAndroidStudioAttributes(doc->root.get()); XmlReferenceLinker xml_linker; if (!xml_linker.Consume(context_, doc)) { if (!options_.do_not_fail_on_missing_resources && !xml_linker.Consume(context_, doc)) { return {}; } Loading Loading @@ -1674,6 +1675,7 @@ class Linker { file_flattener_options.update_proguard_spec = static_cast<bool>(options_.generate_proguard_rules_path); file_flattener_options.output_format = options_.output_format; file_flattener_options.do_not_fail_on_missing_resources = options_.merge_only; ResourceFileFlattener file_flattener(file_flattener_options, context_, keep_set); if (!file_flattener.Flatten(table, writer)) { Loading Loading @@ -1901,7 +1903,7 @@ class Linker { } ReferenceLinker linker; if (!linker.Consume(context_, &final_table_)) { if (!options_.merge_only && !linker.Consume(context_, &final_table_)) { context_->GetDiagnostics()->Error(DiagMessage() << "failed linking references"); return 1; } Loading Loading @@ -2053,7 +2055,7 @@ class Linker { manifest_xml->file.name.package = context_->GetCompilationPackage(); XmlReferenceLinker manifest_linker; if (manifest_linker.Consume(context_, manifest_xml.get())) { if (options_.merge_only || manifest_linker.Consume(context_, manifest_xml.get())) { if (options_.generate_proguard_rules_path && !proguard::CollectProguardRulesForManifest(manifest_xml.get(), &proguard_keep_set)) { error = true; Loading Loading @@ -2187,6 +2189,12 @@ int LinkCommand::Action(const std::vector<std::string>& args) { return 1; } if (options_.merge_only && !static_lib_) { context.GetDiagnostics()->Error( DiagMessage() << "the --merge-only flag can be only used when building a static library"); return 1; } // The default build type. context.SetPackageType(PackageType::kApp); context.SetPackageId(kAppPackageId); Loading
tools/aapt2/cmd/Link.h +5 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ struct LinkOptions { // Static lib options. bool no_static_lib_packages = false; bool merge_only = false; // AndroidManifest.xml massaging options. ManifestFixerOptions manifest_fixer_options; Loading Loading @@ -285,6 +286,10 @@ class LinkCommand : public Command { AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", &trace_folder_); AddOptionalSwitch("--merge-only", "Only merge the resources, without verifying resource references. This flag\n" "should only be used together with the --static-lib flag.", &options_.merge_only); } int Action(const std::vector<std::string>& args) override; Loading
tools/aapt2/integration-tests/MergeOnlyTest/Android.mk 0 → 100644 +2 −0 Original line number Diff line number Diff line LOCAL_PATH := $(call my-dir) include $(call all-makefiles-under,$(LOCAL_PATH))
tools/aapt2/integration-tests/MergeOnlyTest/App/Android.mk 0 → 100644 +29 −0 Original line number Diff line number Diff line // // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_USE_AAPT2 := true LOCAL_AAPT_NAMESPACES := true LOCAL_PACKAGE_NAME := AaptTestMergeOnly_App LOCAL_SDK_VERSION := current LOCAL_EXPORT_PACKAGE_RESOURCES := true LOCAL_MODULE_TAGS := tests LOCAL_STATIC_ANDROID_LIBRARIES := \ AaptTestMergeOnly_LeafLib \ AaptTestMergeOnly_LocalLib include $(BUILD_PACKAGE) No newline at end of file
tools/aapt2/integration-tests/MergeOnlyTest/App/AndroidManifest.xml 0 → 100644 +23 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.app"> <application android:label="@*com.local.lib:string/lib_string"/> </manifest> No newline at end of file