31 Commits

Author SHA1 Message Date
Ryan Mitchell
4ea9075124 Make aapt2 terminology more inclusive
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
2020-07-31 21:03:54 +00:00
Brian Chang
dcef831e61 Improve how we exempt resources from getting their names collapsed.
Removed the --whitelist-path flag, which is poorly named and we can
already specify these resources with --resources-config-path.

Renamed TableFlattenerOptions.whitelisted_resources to keep_resources.
It holds ResourceName instead of std::string. This lets us include type
when specifying what gets exempted, for correctness.

Bug: 111115201
Test: make aapt2_tests
Change-Id: Ifa5df924b5e2265c32cdcf8ca7dfa4a3992a0468
2019-09-16 17:29:46 -07:00
Udam Saini
b228df32d9 Allows features to link to other feature splits without namespacing.
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-06-26 13:30:35 -07:00
Mohamed Heikal
c769403631 Resource Path Obfuscation
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-12-20 18:19:25 -05:00
Mårten Kongstad
24c9aa6541 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 06:50:22 -07:00
Chris Warrington
58e2fbf169 Revert "AAPT2: Automatic Static Library Namespacing."
This reverts commit 481f027ddc3e0ff0e1838a9375c1286e8ad70d70.

Reason for revert: Not needed any more

Bug: 111543815
Test: existing unit and integration tests
Change-Id: I87b039192682636d81c2d33512495cb005c9504d
2018-07-23 17:23:25 +01:00
Ryan Mitchell
833a1a6c4a AAPT2: Refactor flags into commands
Refactors the flag based command invocation into classes that make using
subcommands easier.

Test: manual tests of printing
Change-Id: Ic8df6af0be30db552e32150afebecbfeec7e1075
2018-07-13 14:26:06 -07:00
Mohamed Heikal
57ffac7f10 Merge "AAPT2: Adds config support for manipulating resources" 2018-04-09 14:57:04 +00:00
Mohamed Heikal
d3c5fb64e3 AAPT2: Adds config support for manipulating resources
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-04-06 15:03:23 -04:00
Chris Warrington
481f027ddc AAPT2: Automatic Static Library Namespacing.
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-03-14 15:05:39 +00:00
Shane Farmer
2c12241fa8 AAPT2: Get list of multi-APK artifacts without APK file
Allow the optimize command to produce a list of output artifact names
without needing to read the input APK from disk. This not only saves
disk reads for a file that will not be used, it also allows the list
of outputs to be generated without having an APK file yet.

Test: unit tests
Test: split an APK
Test: print list of outputs without an APK
Change-Id: I4e18e63f298a07f26ab0de2b2f0acb769bb535ba
2017-12-19 13:52:30 -08:00
Shane Farmer
cb6c3f9b88 AAPT2: Push more configuration code into the parser
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-13 12:28:39 -08:00
Shane Farmer
99ac3fdbd8 AAPT2: Remove unused command line option.
--target-abis is never used and the same functionality works with
onfiguration files.

Test: Unit tests
Change-Id: Ic890eb0f15fade82cd85ba34d653d6cea3b79fb2
Bugs: b/70571736
2017-12-12 16:55:31 -08:00
TreeHugger Robot
49639bf6cd Merge "AAPT2: Allow output artifacts to be filtered." 2017-12-05 20:36:47 +00:00
Shane Farmer
666de34a58 AAPT2: Allow output artifacts to be filtered.
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-12-05 10:52:48 -08:00
Luke Nicholson
b0643302c7 Enable obfuscation of resource names, with whitelisting support.
Test: Built aapt2, ran optimize on gmail apk with sample whitelist
config file, and flags enabled. Added two unit tests to TableFlattener
covering obfuscation logic.

Change-Id: Iad6329d75ff440121bf1a2cdf09c5f4bf4199d9d
2017-12-04 17:54:05 -08:00
Pierre Lecesne
d55bef78a5 AAPT2 - Convert command to copy all the files.
Test: Manual

Change-Id: I8705966cb34ff41eb362126a35956720147fae91
2017-11-13 21:07:34 +00:00
Adam Lesinski
8780eb6e49 AAPT2: Add convert command
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-11-01 10:58:28 -07:00
Adam Lesinski
0045116606 AAPT2: Define and Implement AAPT Container Format
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
2017-10-19 12:50:53 -07:00
Adam Lesinski
4670805ea4 AAPT2: Move format related files under same directory
Test: make aapt2_tests
Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf
2017-10-04 14:26:55 -07:00
Shane Farmer
3edd472643 AAPT2: Set the minSdkVersion when generating multiple APKs.
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-10-03 16:02:38 +00:00
Adam Lesinski
d3ffa844f5 AAPT2: Cleanup Visitors for XML and Values
Test: make aapt2_tests
Change-Id: Ib61f64c155a380115610edeaf2d65e60258a2426
2017-09-28 14:08:50 -07:00
Shane Farmer
efe45392c3 AAPT2: Multi APK generator by version
- 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-31 16:30:38 -07:00
Shane Farmer
9ecc0751e3 AAPT2: Add flag to print multi APK artifact names.
- 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-31 10:17:39 -07:00
Shane Farmer
0a5b201156 AAPT2: Add a APK filtering.
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-08-16 19:19:54 +00:00
Shane Farmer
280be34fa6 AAPT2: Update the name of the configuration struct.
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
2017-06-21 16:13:02 -07:00
Shane Farmer
5766943f55 AAPT2: Split APK by ABI.
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
2017-06-21 14:10:23 -07:00
Adam Lesinski
742888f0fd AAPT2: binary parser should be more lenient with files
Some APKs have file references that reference files that don't exist.

For now, just be lenient and ignore the files themselves.

Keep the actual reference until such a time as general resource
stripping is implemented.

Bug: 37749644
Test: manual
Change-Id: I773685acf41212405b71b064d64045fb4556dcfc
2017-04-28 15:34:52 -07:00
Adam Lesinski
b522f04bc2 AAPT2: Allow truncating of package names
ResTable_package header only allows 127 UTF-16 characters, so AAPT
would truncate the real package name to fit. AAPT2 would error-out
on any package name longer than 127 UTF-16 characters. This strictness
is not required except when building shared libraries, which use the
full package name as a way of identifying the runtime assigned
package ID to package name mapping.

Bug: 36940145
Test: make aapt2_tests
Change-Id: I7d2b7e50c7ab30c6a6c4f15d310e711f68e35091
2017-04-21 17:02:09 -07:00
Adam Lesinski
db091577ff AAPT2: Allow the ';' separator on Windows for split args
Bug: 36870463
Test: manual (wine)
Change-Id: I8a38545a3cac9354b41858e1840b197b60925c03
2017-04-13 16:07:35 -07:00
Adam Lesinski
d0f492db03 AAPT2: Share split functionality between link and optimize
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-04-10 11:59:18 -07:00