summaryrefslogtreecommitdiff
path: root/tools/aapt2/optimize
AgeCommit message (Collapse)Author
2020-11-15Merge "Fix DominatorTree for locale and mcc/mnc config" am: 8f2f4e14de am: ↵Ryan Mitchell
caff40cad3 am: c9acec6545 am: 518d35c017 Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1481918 Change-Id: I78ffd81962fdfba38c46590e8b6ae76c582ab77b
2020-11-11Fix DominatorTree for locale and mcc/mnc configRyan Mitchell
De-duping of configurations with locales was disabled previously since there is not a good way to dedupe locales in a forwards compatible way (change SHA: e38567480be67ac83a8f8f090704bb0d49e2eed2). In b/171892595, since every locale is a root in the dominator tree, configs that do not specify locale qualifiers are dominated by the default config and their values are checked for compatiblity with the locale config values. b/171892595 took a while to detect because, this is only an issue at runtime when a resource has one config containing mnc/mcc without a locale, one config containing a locale, and the values for the configs differ. This is because mcc/mnc is the only qualifier with a greater precedence than locale. Make configurations with mcc/mnc and mcc unable to be dominated until locale deduping is fixed. Bug: 171892595 Bug: 62409213 Test: aapt2-tests Change-Id: Ia0a5e5d7a1650d070f5f2fcaf9a8469a8c7dabe6
2020-07-31Make aapt2 terminology more inclusiveRyan Mitchell
Update language to comply with Android's inclusive language guidance See https://source.android.com/setup/contribute/respectful-code for reference Bug: 162364131 Bug: 162536543 Test: aapt2_tests Change-Id: I4eef925d6319b40a395fc8d59a3f2912a02ca03b
2019-08-19Only check sibling config values to dedupeRyan Mitchell
Currently more config values are being kept than necessesary. For example, given config values for a string resource: Config: default Value: "keep" Config: ldrtl Value: "dedupe" Config: ldrtl-night Value: "dedupe" Config: land Value: "keep2" The ldrtl-night config value will fail to be removed despite being equivalent to the ldrtl value. This is because the value for the land configuration is not equivalent to the ldrtl-night value. Instead of checking that every compatible config value not related by dominance should have quivalent values, only check sibling config values within the dominator tree. Bug: 137230022 Test: aapt2_tests Change-Id: I965365d1a9433ae595eab48d82837ac102148334
2019-07-30ResourcePathShortener deterministically handles hash collisionsMohamed Heikal
ResourcePathShortener appends one digit at the end of colliding short file names to disambiguate them. This cl sorts the list of file paths so that colliding files always get the same disambiguating digit from one run to the next rather than possibly alternating. Test: make aapt2_tests Change-Id: I983a1448c21f2c79d7cdb1de232e7758c04fc256
2019-07-22Merge "Precalculate the required number of characters for path shortening"Mohamed Heikal
2019-07-18Precalculate the required number of characters for path shorteningMohamed Heikal
It does not make sense for aapt2 to calculate the optimal number of chars in the shortened path when it only depends on the number of resources rather than anything apk specific. This cl precalculates the number of chars and uses if conditions instead. Test: manual testing + aapt2_tests still passes. Change-Id: If2dc86952a6b6e01ce02dc42754c037d07d57325
2019-07-08Fix bug where aapt2 optimize obfuscated color-* resourcesMohamed Heikal
aapt2 optimize --enable-resource-path-shortening should ignore res/color resources since android uses the path while loading them. This cl fixes a bug where res/color-* (eg: res/color-v21) resource paths are shortened when they should not be. Test: make aapt2_tests Bug: b/75965637 Change-Id: Ibbc3fe4d2e6bd4f31765a5aa85980907dc013ecd
2019-06-26Allows features to link to other feature splits without namespacing.Udam Saini
Add uses-split dependencies to AppInfo. At link time, this is used and allows features to reference other features, before resource namespacing is implemented in Android Studio. bug:135681292 Test: Link_test, ReferenceLinker_test, and integration tests. Change-Id: Ifdf0067e7370552b6b9d4d6d4713d4484b6ea154
2019-04-26Fix bug where path shortening breaks ColorStateListsMohamed Heikal
Android resource loader uses the file path to check if a resource is a ColorStateList. Path shortening removed that part of the path and thus broke the resource loader of APKs optimized with path shortening. This cl skips path shortening for resources under "res/color/" Test: make aapt2_tests Bug: b/75965637 Change-Id: If94dfa398efd81522d4faed157afd35f6dabe856
2019-03-05Add --trace_folder to aapt2Fabien Sanglard
Add a tracing API and instrument key functions in order to profile aapt2 bottleneck. The API allows to generate systrace fragment files. Impact on performance is neglibible with each Trace requiring less than 1us and the final Flush operation at the end of a command requiring around 40us. Bug: None Test: None Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
2018-12-20Resource Path ObfuscationMohamed Heikal
This CL allows aapt2 to obfuscate resource paths within the output apk and move resources to shorter obfuscated paths. This reduces apk size when there is a large number of resources since the path metadata exists in 4 places in the apk. This CL adds two arguments to aapt2, one to enable resource path obfuscation and one to point to a path to output the path map to (for later debugging). Test: make aapt2_tests Bug: b/75965637 Change-Id: I9cacafe1d17800d673566b2d61b0b88f3fb8d60c
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-07-23Revert "AAPT2: Automatic Static Library Namespacing."Chris Warrington
This reverts commit 481f027ddc3e0ff0e1838a9375c1286e8ad70d70. Reason for revert: Not needed any more Bug: 111543815 Test: existing unit and integration tests Change-Id: I87b039192682636d81c2d33512495cb005c9504d
2018-07-13AAPT2: Fix long version code bugsRyan Mitchell
Refactoring areas in AAPT2 that use android:versionCode to also use abdroid:versionCodeMajor. Does not add versionCodeMajor command line flag yet. Bug: 109883459 Test: aapt2_tests Change-Id: I573fbea37491cf8c5742f9e385c66ee64c4e5166
2018-04-09Merge "AAPT2: Adds config support for manipulating resources"Mohamed Heikal
2018-04-06AAPT2: Adds config support for manipulating resourcesMohamed Heikal
aapt2 optimise command can now take a resources config file as an argument. The config has the name of each resource and a list of directives. Currently implemented is the "remove" directive which marks the resource for deletion. The obfuscation whitelist code and argument name was changed to prevent confusion. Test: make aapt2_tests Bug: b/27523794 Change-Id: I2d8e1985e5ea2286131c25231e2c411f3d9610ce
2018-03-18Merge "Writes the resource table proto out when writing a LoadedApk." into ↵Cory Smith
pi-dev am: 449be81065 am: 6a43bd634e Change-Id: I3e84028a1e74b28d2804d66971cf4610874ae349
2018-03-18Writes the resource table proto out when writing a LoadedApk.corysmith@google.com
Small fixes for consistancy to use constants instead of strings. Change-Id: I33439c376e1634b7957730ce16e241b0f5bb92f8 Fixes: 74594854 Test: Manual, tested against blaze test //javatests/com/google/devtools/build/android:UnitTests
2018-03-14AAPT2: Automatic Static Library Namespacing.Chris Warrington
Introduces a link flag --auto-namespace-static-lib for use when linking static libraries. When linking a static library with compiled sources that have references to resources in provided libraries without an explicit package name, the flag enables automatic inference of the package. If a resource is present in the package that is being compiled, that is used, otherwise the reference is rewritten to the highest precedence resource with matching name and type. Test: m out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests && \ $ANDROID_HOST_OUT/nativetest64/aapt2_tests/aapt2_tests Test: m frameworks/base/tools/aapt2/integration-tests Change-Id: I6c6017e054654d1f60782d0a428a7a2a47f8952b
2018-02-14AAPT2: Fix compatible-screens element in AndroidManifest.xmlShane Farmer
Fix an issue where the compatible-screens element was not being populated correctly. The previous version was missing the screenSize attribute which is mandatory. The attributes were also missing the resource ID from the framework library as these are a part of the public API. Change-Id: I2f594c2259831dbbd96c58db4ba55e8288d4231e Test: unit tests Test: manually split an APK and dumped with aapt
2017-12-19AAPT2: Sort artifacts based on the Play Store rules.Shane Farmer
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
2017-12-13AAPT2: Push more configuration code into the parserShane Farmer
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
2017-12-12AAPT2: Remove signatures from multi-APK artifacts.Shane Farmer
Remove signer files (.SF and public key) as well as the original manifest file from any output artifacts. Since the artifacts are not signed, we want to remove the original signature and manifest. The APK signer tool will add these back later. Updated the context wrapper to enable verbose mode to be cleared. This lets us have more specific log messages when splitting an APK as at this point the artifacts and filters are more interesting than the files removed. Test: Manually split an APK and verified the filles were removed while leaving the other META-INF entries. Test: Unit tests Change-Id: Ia59993b5570f802130c6e3ba42398a00821061ea
2017-12-05AAPT2: Allow output artifacts to be filtered.Shane Farmer
A new optional flag has been added to allow a list of artifacts that should be written as output to be provided. If the flag is provided, only artifacts that have an output name matching an entry in the list will be processed. Test: manually ran against an APK with multiple artifacts in the configuration and confirmed that only the specified artifacts were written. Test: Ran all unit tests. Change-Id: Ia32b19acf1b2ef3711abf13df08dc7b1aa0cf161
2017-11-30AAPT2: Specify the output APK in log messagesShane Farmer
Extend the context wrapper to allow it to also know the current artifact that is being generated and to use that as a source for diagnostics messages. Test: ran unit tests Test: manually ran optimize to split and APK and verified log messages Change-Id: I1d66dacb38db58d57d2fffaa19f5fdaff9f908df
2017-11-01AAPT2: Add convert commandAdam Lesinski
This command allows a developer to convert their proto APK (generated from the link phase using --proto-format) into a binary APK suitable for use on device. aapt2 convert -o output.apk input.apk Test: manual + make aapt2_tests Change-Id: I10a7c33bb4b57006d01fe00a8bf92f78e04e7e50
2017-10-04AAPT2: Move format related files under same directoryAdam Lesinski
Test: make aapt2_tests Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf
2017-10-03AAPT2: Set compatible-screens in manifest for multi-APKShane Farmer
If an artifact in a multi-apk set is for a scpecific set of screen densities then update the manifest to set the compatible-screens element to match. Test: ran unit tests Test: manually ran optimize command Change-Id: I07e90850ab2f4647a8623acbeaccbebbe81c3a6a
2017-10-03AAPT2: Update versionCode in multi-APKs.Shane Farmer
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
2017-10-03AAPT2: Set the minSdkVersion when generating multiple APKs.Shane Farmer
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
2017-08-31AAPT2: Multi APK generator by versionShane Farmer
- 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
2017-08-31AAPT2: Add flag to print multi APK artifact names.Shane Farmer
- 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
2017-08-24AAPT2: Fix multi APK outputShane Farmer
- Ensure that the output directory exists before generating APKs - Only use the file name (and not the path) for creating output file names Test: manually ran optimize command Change-Id: I5f5ecb5dcec4d17cdbca5709f2dd17e6d53df986
2017-08-16AAPT2: Add a APK filtering.Shane Farmer
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
2017-06-13AAPT2: Disable locale domination for dedupingAdam Lesinski
Locale deduping isn't straightforward, as parenting rules change between platform versions and the selection preference of a specific locale variant over the default configuration lead to incorrect results at runtime. Bug: 62409213 Test: make aapt2_tests Change-Id: Iec8f1cfba7ae43c847d163529891fdc15f3db826
2017-04-10AAPT2: Share split functionality between link and optimizeAdam Lesinski
Generating splits should be possible to do from the optimize command. This means that a lot of infrastructure around split APKs can be shared by both the optimize and link phase. Bug: 35925830 Change-Id: Ia88b9e4bff300a56353b2f7a4a2547c8eb43a299 Test: manual
2017-03-02AAPT2: Fix Plural::Equals() methodAdam Lesinski
Test: make aapt2_tests Bug: 35902437 Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-02-22AAPT2: Rename strip phase to optimizeAdam Lesinski
- Allow resource deduping, version collapsing, and sparse resource encoding. Test: manual Change-Id: Ia4aa892ab5b06ba1d5ea4a6efb51b00bc3a980c4