Require explicit ordering of groups in the configuration file to ensure
that the correct version code is set. Ordering based on a single ABI is
straight forward to ensure Play Store delivers the correct APK, but when
an APK needs more than one ABI things get messy quickly. This also goes
for screen density etc. The only thing that is easily sorted without
this attribute is android-sdk since an artifact can only reference a
single SDK.
Test: unit tests
Test: manually split an APK with update config.xml
Change-Id: I37a2b8b8a8409d6d6ff27c7142d4c8c8065a7a51
Sort output artifacts so that the updated versionCode manifest entry
will allow correct handling of updates from Play Store. The most
important dimension is Android SDK version. It is important that a split
based on min SDK version will allow a user to get a new APK if they
upgrade the OS on their device to support a new split.
ABI splits need to also be taken into consideration as it is possible
for a device to run in ARM emulation mode and installing an ARM APK over
a x86 APK could cause performance regressions.
The XML file format was updated to give each of the configuration groups
have their own section of the XML file. This allows the sort order to be
determined by a groups ordering. Artifacts can now be added to the
configuration file in an arbitrary order. Since this will be the common
case for developers, it will help reduce errors from inserting a new
artifact in the wrong spot.
The implementation follows the rules outlined at:
https://developer.android.com/google/play/publishing/multiple-apks.html
Test: Unit tests
Test: Manual process XML configuration
Change-Id: I0face862c6d6b9d3cd2d99088afe5b9491be0120
With ABI, screen density, and locale, it is possible to use a shorthand
notation when the group only has a single entry. The shorthand is to
leave the group empty and use a valid configuration for the group name.
Test: manually ran optimize command
Test: unit tests
Change-Id: If2d091e587474847c6c9e9be1a29196b261cc82d
When parsing is complete, we now have a list of output artifacts that
have their referential integrity validated. This means that once the
configuration file is parsed, the only errors that can occur are related
to APK processing, and not the configuration itself.
This reduces the number of errors that could cause a partial output of
APK artifacts. It simplifies the public API and reduces the complexity of
the code to generate multiple APKs.
Test: Ran unit tests
Test: manually ran the optimize command to ensure it still works
Change-Id: I3f2d885b207a84c958f5348a4baa6718598184a4
Ensure that the configured min max and target SDK versions of the
android-sdk configuration item are correct. This will prevent AAPT2
crashing when it tries to dereference the Android SDK version to update
the manifest.
The test for the latest development SDK version has also been made
future proof by using the SDK constants.
Test: unit tests
Test: manually split an APK
Change-Id: I1ffa90ba2d96cab0cbfa4bd75ef37a50d986852d
AAPT Container Format (.apc) is a simple container that
enumerates the various intermediate files that AAPT2 generates
during the compile phase.
The format is defined in formats.md.
For now, continue using the .flat extension for the container file,
and keep making use of the .flata zip for storing multiple files.
This will allow easier integration with existing build systems and allow
the evolution of the APC format to better handle arbitrarily large
files.
Test: make aapt2_tests
Change-Id: Id7216e5b76316bdd683f0fa4eaf2d2da273ba815
Set versionCode in the AndroidManifest.xml so each artifact has a unique
version code. This will allow the play store to serve up the correct
APKs.
The versionCode is determined by taking the versionCode from the input
APK and adding the configured version to that. If an artifact does not
have a version, the next version is used based on the order in the
configuration file. If the firs artifact does not have a version, it
starts at 1, so that all artifacts have a different version code to the
base APK.
Bug: 64972562
Test: unit tests
Test: manually optimized an APK into multiple APKs and confirmed versions:
aapt dump badging ${apk} | grep versionCode
Change-Id: Ie12b3e42bbd8ce9a2819712c2c56b24c0a901e6b
When generating multiple APKs from a configuration file, check to see if
we have filtered resource by minSdkVersion and update the manifest to
reflect this. We only want to inflate and modify the manifest file if
there is an update to be applied.
Bug: 37944703
Bug: 67005138
Test: Ran unit tests
Test: Manually split an APK and verified the manifest by dumping with
AAPT (both xmltree and badging).
Change-Id: I64a0e4889d7d9e57373369b044a091287b06cc35
- Added an additional axis for generating a multi-apk split by minimum
Android SDK version. This removes any resources that will not be used
for the desired minimum SDK version. If there are multiple resources
that would be valid for any version newer than the requested minimum,
then all would be kept so that the best match can be found.
- Added a context wrapper to set the appropriate Android SDK version for
each generated artifact.
- Split out the FilterTable method to allow it to be directly tested
without the need to mock the APK writing steps.
Test: Unit tests
Test: manually run optimize command
Change-Id: I7e6018df081af9ed5d9e8aaf40ed216c1275f138
- Added new flag that exits after printing the list of artifact names
that would be generated from the combination of the configuration file
and input APK.
- Cleaned up the code to generate the artifact names which also involved
adding some more test cases for corner cases.
Test: Unit tests
Test: Manually ran new command
Test: Manually ran old command
Change-Id: I8d30e7a4a070af26945b8f544a13f23bdf1ba169
In preparation for exporting an XML proto format for UAM to consume,
this change brings the XML DOM API more in line with other APIs that
do not make the Namespace a separate node.
Treating Namespace declarations as just properties of an Element
node makes the implementation of algorithms much simpler, as
the constraints that Namespace nodes have only one child
are now built in and traversing to find Element nodes
is much simpler.
Also made a bunch of quality of life improvements, like formatting and
comment style.
Test: make aapt2_tests
Change-Id: Ib97ff1c4252b7907e2cc1f13a448dc4ca3b809a4
Allow resource files to be removed from the final artifact based on the
density and locale configuration in the config file. The APK is split
along the density, locale and ABI axis. Each split is generated from the
original APK without modifying the original. The new resource table is
written back to the file system with unneeded assets etc removed.
Test: Unit tests
Test: Manually run optimize command against an APK and inspect results
Test: Installed split searchlite APK (after resigning) and ran on N6
Change-Id: If73597dcfd88c02d2616518585d0e25a5c6a84d1
Mingw64 was being difficult, so instead of defining a wmain entrypoint,
the command line parameters are parsed manually using built-in Windows
methods that support Unicode. The results are converted to UTF8 and
handled just like the rest of the linux/mac version of the code.
This also removes dependencies on std::istream in favour of a
FileInputStream which calls the appropriate unicode version of
open to read a file.
No speed regressions found on Linux or MacOS.
Bug: 62336414
Bug: 63830502
Test: manual
Change-Id: I597da51e33729ed1b98bf246e7e773337fd3fee8
Update the artifact name parser to ensure that duplicate placeholders
are treated as an error.
Also applied suggested changes from ag/2447777.
Test: ran unit tests
Change-Id: Iab8fd9d9b81aa3008177141256ecd16ef04b0c34
Add a helper method to convert a templated artifact name to file name
based on the values present in an Artifact struct. The Artifact
validates that all required template paramters are present.
Test: Unit tests
Change-Id: Id97ff606bb41c72a31c2d769104966be9cbca1a0
Make the Configuration struct name less ambiguous. Also ran clang-format
on the change since some lines were too long and this resulted in a
bigger diff than expected.
Test: built manually
Test: ran existing unit tests
Change-Id: I85e78041fa78d913d47a26c85ad48b05bf935a6a
Added a FilterChain that can apply multiple filter steps to an APK file
as it is being written to disk. The first filter applied is by ABI. If
a library in the APK does not match the filter it is skipped.
Added an AbiFilter that keeps files that are either not native libs or
are for the set of wanted ABIs
Test: ran unit tests locally
Test: ran against an APK with ARM and x68 libs and diffed the results
Change-Id: I3fb901d3de3513e85f2a2763a8e4487a28ed4881
Implement the todo left from last change to read the contents of the
configuration file from disk. Since this is an operation that may fail
the API was changed to take return a Maybe to indicate errors reading
the file.
Test: unit test for error condition
Test: ran aapt2 optimize with the new code path wired in
Change-Id: I93d532b4a57af9520231225eee4fc5f2b1a046b9
The XML file is parsed with the aapt::xml::XmlDom parser and actions are
used for the elements we are interested in. This means that there are
cases where a user could add aditional tags/elements to the document
that are technically invalid (acording to the schema) but are ignored by
the parser. This allows us to be more lenient which probably isn't a bad
thing.
Documents have the namespace stripped before processing as the
XmlActionExecutor ignores any elements with a namespace. The namespace
is validated before being removed.
The test cases are all based off the previous example XML file.
Test: Unit tests
Change-Id: I86d7e0dc6347ace3eaa60c1842d59f3cd0d4f749
The current iteration of the schema allows for both Split and Optimize
commands running off the same file. A split command is multiple optimize
command, and an optimize is a split with only a single artifact. To
combine the two, a single file with one or more artifacts can be passed
to either command. If multiple artifiacts are used for an optimize
command, the required artifact can be specified on the command line. A
configuration with only a single artifact can be used with either
command to get the same result.
Change-Id: Ie48eda6e2f9f8bf25d75ef7bcc3b3401a2d3e8eb
Bugs: 37847908
Test: xmllint --noout --schema aapt2.xsd example/config.xml