AAPT: Add --no-version-transitions flag

Add a new flag to disable versioning of Transition related XMLs.
Transition support library will use this to handle these XMLs on older
API levels.

Test: make libaapt_tests AaptTestAppOne
Bug: 34427868
Change-Id: I66e81cca049e71ef6704177b2ca21c9cdeaff78f
This commit is contained in:
Yuichi Araki
2017-01-18 20:42:17 +09:00
parent 9727f22fc0
commit 4d35cca96c
8 changed files with 105 additions and 2 deletions

View File

@@ -55,6 +55,7 @@ public:
mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
mAutoAddOverlay(false), mGenDependencies(false), mNoVersionVectors(false),
mNoVersionTransitions(false),
mCrunchedOutputDir(NULL), mProguardFile(NULL), mMainDexProguardFile(NULL),
mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
@@ -219,6 +220,8 @@ public:
void setBuildAppAsSharedLibrary(bool val) { mBuildAppAsSharedLibrary = val; }
void setNoVersionVectors(bool val) { mNoVersionVectors = val; }
bool getNoVersionVectors() const { return mNoVersionVectors; }
void setNoVersionTransitions(bool val) { mNoVersionTransitions = val; }
bool getNoVersionTransitions() const { return mNoVersionTransitions; }
/*
* Set and get the file specification.
@@ -299,6 +302,7 @@ private:
bool mAutoAddOverlay;
bool mGenDependencies;
bool mNoVersionVectors;
bool mNoVersionTransitions;
const char* mCrunchedOutputDir;
const char* mProguardFile;
const char* mMainDexProguardFile;

View File

@@ -223,6 +223,8 @@ void usage(void)
" localization\n"
" --no-version-vectors\n"
" Do not automatically generate versioned copies of vector XML resources.\n"
" --no-version-transitions\n"
" Do not automatically generate versioned copies of transition XML resources.\n"
" --private-symbols\n"
" Java package name to use when generating R.java for private resources.\n",
gDefaultIgnoreAssets);
@@ -704,6 +706,8 @@ int main(int argc, char* const argv[])
bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI);
} else if (strcmp(cp, "-no-version-vectors") == 0) {
bundle.setNoVersionVectors(true);
} else if (strcmp(cp, "-no-version-transitions") == 0) {
bundle.setNoVersionTransitions(true);
} else if (strcmp(cp, "-private-symbols") == 0) {
argc--;
argv++;

View File

@@ -4730,6 +4730,32 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle) {
return NO_ERROR;
}
const String16 kTransitionElements[] = {
String16("fade"),
String16("changeBounds"),
String16("slide"),
String16("explode"),
String16("changeImageTransform"),
String16("changeTransform"),
String16("changeClipBounds"),
String16("autoTransition"),
String16("recolor"),
String16("changeScroll"),
String16("transitionSet"),
String16("transition"),
String16("transitionManager"),
};
static bool IsTransitionElement(const String16& name) {
for (int i = 0, size = sizeof(kTransitionElements) / sizeof(kTransitionElements[0]);
i < size; ++i) {
if (name == kTransitionElements[i]) {
return true;
}
}
return false;
}
status_t ResourceTable::modifyForCompat(const Bundle* bundle,
const String16& resourceName,
const sp<AaptFile>& target,
@@ -4766,6 +4792,11 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle,
continue;
}
if (bundle->getNoVersionTransitions() && (IsTransitionElement(node->getElementName()))) {
// We were told not to version transition tags, so skip the children here.
continue;
}
const Vector<XMLNode::attribute_entry>& attrs = node->getAttributes();
for (size_t i = 0; i < attrs.size(); i++) {
const XMLNode::attribute_entry& attr = attrs[i];

View File

@@ -25,7 +25,7 @@ namespace aapt {
static const char* sMajorVersion = "2";
// Update minor version whenever a feature or flag is added.
static const char* sMinorVersion = "4";
static const char* sMinorVersion = "5";
int PrintVersion() {
std::cerr << "Android Asset Packaging Tool (aapt) " << sMajorVersion << "."

View File

@@ -24,5 +24,5 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src)
LOCAL_STATIC_ANDROID_LIBRARIES := \
AaptTestStaticLibOne \
AaptTestStaticLibTwo
LOCAL_AAPT_FLAGS := --no-version-vectors
LOCAL_AAPT_FLAGS := --no-version-vectors --no-version-transitions
include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 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.
-->
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="sequential">
<fade android:fadingMode="fade_out" />
<changeBounds />
<fade android:fadingMode="fade_in" />
</transitionSet>

View File

@@ -80,6 +80,7 @@ struct LinkOptions {
// Optimizations/features.
bool no_auto_version = false;
bool no_version_vectors = false;
bool no_version_transitions = false;
bool no_resource_deduping = false;
bool no_xml_namespaces = false;
bool do_not_compress_anything = false;
@@ -250,6 +251,7 @@ static std::unique_ptr<xml::XmlResource> LoadXml(const std::string& path,
struct ResourceFileFlattenerOptions {
bool no_auto_version = false;
bool no_version_vectors = false;
bool no_version_transitions = false;
bool no_xml_namespaces = false;
bool keep_raw_values = false;
bool do_not_compress_anything = false;
@@ -306,6 +308,23 @@ uint32_t ResourceFileFlattener::GetCompressionFlags(const StringPiece& str) {
return ArchiveEntry::kCompress;
}
static bool IsTransitionElement(const std::string& name) {
return
name == "fade" ||
name == "changeBounds" ||
name == "slide" ||
name == "explode" ||
name == "changeImageTransform" ||
name == "changeTransform" ||
name == "changeClipBounds" ||
name == "autoTransition" ||
name == "recolor" ||
name == "changeScroll" ||
name == "transitionSet" ||
name == "transition" ||
name == "transitionManager";
}
bool ResourceFileFlattener::LinkAndVersionXmlFile(
ResourceTable* table, FileOperation* file_op,
std::queue<FileOperation>* out_file_op_queue) {
@@ -345,6 +364,17 @@ bool ResourceFileFlattener::LinkAndVersionXmlFile(
}
}
}
if (options_.no_version_transitions) {
// Skip this if it is a transition resource.
xml::Element* el = xml::FindRootElement(doc);
if (el && el->namespace_uri.empty()) {
if (IsTransitionElement(el->name)) {
// We are NOT going to version this file.
file_op->skip_version = true;
return true;
}
}
}
const ConfigDescription& config = file_op->config;
@@ -1384,6 +1414,7 @@ class LinkCommand {
options_.extensions_to_not_compress;
file_flattener_options.no_auto_version = options_.no_auto_version;
file_flattener_options.no_version_vectors = options_.no_version_vectors;
file_flattener_options.no_version_transitions = options_.no_version_transitions;
file_flattener_options.no_xml_namespaces = options_.no_xml_namespaces;
file_flattener_options.update_proguard_spec =
static_cast<bool>(options_.generate_proguard_rules_path);
@@ -1863,6 +1894,11 @@ int Link(const std::vector<StringPiece>& args) {
"Use this only\n"
"when building with vector drawable support library",
&options.no_version_vectors)
.OptionalSwitch("--no-version-transitions",
"Disables automatic versioning of transition resources. "
"Use this only\n"
"when building with transition support library",
&options.no_version_transitions)
.OptionalSwitch("--no-resource-deduping",
"Disables automatic deduping of resources with\n"
"identical values across compatible configurations.",
@@ -2104,6 +2140,7 @@ int Link(const std::vector<StringPiece>& args) {
if (options.static_lib) {
options.no_auto_version = true;
options.no_version_vectors = true;
options.no_version_transitions = true;
}
LinkCommand cmd(&context, options);

View File

@@ -1,5 +1,10 @@
# Android Asset Packaging Tool 2.0 (AAPT2) release notes
## Version 2.5
### `aapt2 link ...`
- Transition XML versioning: Adds a new flag `--no-version-transitions` to disable automatic
versioning of Transition XML resources.
## Version 2.4
### `aapt2 link ...`
- Supports `<meta-data>` tags in `<manifest>`.