58 Commits

Author SHA1 Message Date
Orion Hodson
18f7afccb6 Merge "Add explicit dependencies on jni_headers" am: c0fe0ae29f am: 6963d8e1c8
Change-Id: I2fdf3826653466d65e3d63fa896d1ec23c5716cd
2020-04-16 10:58:50 +00:00
Orion Hodson
63f06b738d Add explicit dependencies on jni_headers
Preparation for removing implicit include paths for jni.h from soong.

Also remove unnecessary jni.h includes from PathParser.{h,cpp}.

Bug: 152482542
Test: lunch aosp_x86_64 && m checkbuild
Change-Id: Ib18afa3d2c93ed3ce69204286d5177991100fd7e
Exempt-From-Owner-Approval: build refactoring
2020-04-16 08:26:14 +00:00
Winson
62ac8b56a9 Refactor overlayable policy
To make it easier to add the actor policy in a follow up CL,
move most of the policy handling to a central location.

The strings and transformation between strings and flags is
now handled in libidmap2policies, with libandroidfw
containing the single source of policy flags.

This also extracts all the test resource IDs into an R.h
so they can be swapped without having to edit a dozen files
each time.

Bug: 130563563

Test: m aapt2_tests idmapt2_tests and run from host test output
Test: atest libandroidfw_tests

Change-Id: Ie533c9cebf938215df7586f00c38763ae467e606
2020-02-26 15:59:43 -08:00
Izabela Orlowska
f53b67cecf Include ResourcesInternal.proto in aapt2-protos.zip
Bug: 144080617
Test: N/A
Change-Id: I71e9cacb9ba7e82024278f888ee6b6a18b43ca64
2019-11-07 11:59:18 +00:00
Ryan Mitchell
22ead1c3b0 Remove lite optimization from protos
aapt2 does not require the lite runtime optimization to reduce binary
size. Removing the allows for the protos to be optimized for speed
instead of binary size and grants access to refelctive operations.

Test: aapt2_tests on linux and windows
Change-Id: Ie7ed9df4061e2eb60adbd300eb358d4c3f32c80c
2019-05-21 10:54:00 -07:00
Donald Chai
2ee7cc6ee9 [aapt2] Set use_version_lib.
This is needed by the build system to update soong_build_number.

On a local build, "aapt2 version" used to print:
  Android Asset Packaging Tool (aapt) 2.19-SOONG BUILD NUMBER PLACEHOLDER
Now it prints:
  Android Asset Packaging Tool (aapt) 2.19-eng.dchai.20190511.023434

Bug: 132476779
Bug: 123663089
Change-Id: I5bc5adc9f5b2a7a30bdc649e3c073868b55f17df
Tested: manual, see above
2019-05-11 20:38:43 +00:00
Ryan Mitchell
319fc02cb8 Build aapt2 statically on windows
Prebuilt script is no longer updating libwinpthread-1.dll. Link the
windows executable statically so aapt2 will no longer require the
dependency on the dll.

Bug: 131883685
Test: manual test of aapt2.exe on windows without libwinpthread-1.dll
Change-Id: If78a8ec3030003862c18e3967e4d8333fde7928a
2019-05-06 19:07:58 +00:00
Ryan Mitchell
34039b26f5 Add build number to aapt2 version
This changes adds the build id to the version printed by "aapt2
version". This change also adds a field to the ResourceTable proto that
specifies the fingerprints of tools used to build the table.

Bug: 123663089
Test: manual
Change-Id: Ifaf33c1e506b68e9f1d921fdbeddf36485e65790
2019-04-17 10:59:38 -07:00
Colin Cross
a8edeaa4ec Merge "Dist aapt2 protos" am: b602193169 am: 0783f2d300
am: 0fc50310f3

Change-Id: Ifd9668f3931ec4d276b79a6e5ece576860271de7
2019-03-20 17:59:14 -07:00
Colin Cross
0b28a92440 Dist aapt2 protos
Create aapt2-protos.zip containing the aapt2 proto interface and
dist it for SDK builds.

Bug: 128878015
Test: m PRODUCT-sdk_phone_armv7-win_sdk sdk_repo dist
Change-Id: I13c774c8a2262464dcc4731c999497f6d0dc9095
2019-03-18 22:19:46 -07:00
Fabien Sanglard
2d34e76dac Add --trace_folder to aapt2
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
2019-03-05 15:09:27 -08:00
TreeHugger Robot
275c3ec658 Merge "Option to exclude configs from AAPT2 Link" 2019-02-01 02:13:08 +00:00
Winson
3c918b8cee Option to exclude configs from AAPT2 Link
Adds --exclude-configs to remove matching configs from resulting APK. This matches on explicitness, so if the resource contains all the flags set by the option exactly, it will be removed, but not the other way around.

"--exclude-configs fr" with fr-land resource will remove.
"--exclude-configs fr-land" with fr resource will not remove.

Bug: 119678846

Test: aapt2_tests ResourceExcluder_test
Test: manually ran link on a test set of res

Change-Id: Ieccdecde4aea1fa0502abfd092dffa7da8f929ea
2019-01-28 11:06:33 -08:00
Winson
f54c9a1d72 De-duplicate entries written with AAPT2 convert
There was no check for whether we had already written a specific file path to the APK when using the convert command.

If the resources table points 2 resource IDs at the same file on disk, the convert command would write the file twice, creating two entries.

This holds a set of file paths already written and ignores duplicates.

Bug: 123271593

Test: Ran convert on linked bug's weird.apk
Test: aapt2_tests case for duplicate entries

Change-Id: Ia22515bf8e8297624aaadbf6a9e47159026c63e5
2019-01-24 16:10:16 -08:00
Mohamed Heikal
149b0d29c6 Merge "Resource Path Obfuscation" 2019-01-15 15:34:06 +00:00
Ryan Mitchell
81bae2d158 Statically link libc++ into aapt2
Bug: 121280559
Change-Id: Ide6513d5cf51b832ad2c4a15676db050856728df
Test: ldd aapt2 and manual testing
2019-01-04 22:27:51 +00:00
Ryan Mitchell
479fa39d65 Remove raw values from proto APK
Raw attribute values are not included in xml files when building binary
APKs but they are when building proto APKs. Remove raw attribute values
and create a new convert flag that (--keep-raw-values) that allows raw
value to be kept.

Also added flag to link to keep raw attribute values.

Bug: 115915884
Bug: 116700688
Test: aapt2_tests
Change-Id: Id50136b775b3f43d159ca06181282f6a7b8eaf40
2019-01-03 16:19:04 -08: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
5c541f6e36 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 09:56:09 -07: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
Ryan Mitchell
fc225b21c1 AAPT2: Added badging and permission
Added the remaining dump commands to aapt2.
aapt2 dump badging [apk]
aapt2 dump permissions [apk]

Bug: 73351292
Test: Diffing aapt and aapt2 output across apps from the Android tree
Change-Id: Idee820db410ad8d777d0d250c2657e7b83112a00
2018-09-18 13:17:01 -07: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
Ryan Mitchell
a086da2cd0 Merge "AAPT: Multiple period legacy support and errors" into pi-dev am: f845891031
am: 68dc7ca568

Change-Id: I9da94ea0e84ff3caf28597b1038ed6e4ac158280
2018-04-12 11:51:16 -07:00
y
d6b83299a6 AAPT: Multiple period legacy support and errors
AAPT would accept files with multiple periods in the filename as input.
This lead to cases explained in b/74999475. This change adds error
messages for files with multiple periods unless the legacy flag is
present. With the legacy flag present, AAPT2 will behave like AAPT
rather than throwing an error.

Test: Added tests to aapt2_tests
Bug: 73071563
Bug: 74999475
Change-Id: I28dfceeea7b39f8e4b9e6671e0fc8793cf388f52
2018-04-11 15:52:43 -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
Adam Lesinski
34a1687a67 AAPT2: Remove resources that define locales but no default values.
According to our docs:
https://developer.android.com/guide/topics/resources/localization.html#defaults-r-important

Some resources *require* that there is a default definition. So far,
the pain is felt when doing translations for strings that have been
renamed, etc.

This CL strips out resources that don't have a default value and define
a resource for a locale. This is conservative, but should be expanded
to other configuration properties moving forward.

Bug: 36572857
Test: make aapt2_tests
Change-Id: Ife94a1f8a2ee221f8532ffa856541a9c8c4e7143
2018-03-01 11:18:23 -08:00
Adam Lesinski
93190b79d1 AAPT2: Better debugging output
Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
2017-11-07 11:21:10 -08: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
Donald Chai
b8f078c9a0 AAPT2: Sanitize resource qualifiers before using in split names.
Fixes: 67960909
Test: UtilTest.SplitNamesAreSanitized
Change-Id: I9ba1b8430a00cc7ce981075a60388f275c41dbea
2017-10-18 23:58:42 -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
Adam Lesinski
8cdca1bd72 AAPT2: Cleanup proto classes/methods and add XML serialization
Test: make aapt2_tests
Change-Id: I01ac2285af6771a683533c033a59ae6cfe875d93
2017-09-28 20:43:22 -07:00
Adam Lesinski
b58c3ef023 AAPT2: Convert binary ResTable_config to proto
Test: make aapt2_tests
Change-Id: I8641f13ce41cd58ac8bc3da31c4e15a7b3f06092
2017-09-26 14:48:35 -07:00
Dan Willemsen
8487558120 Merge changes Ia3bcece1,Icd26dc1e am: ec462238f6 am: c201a6bb7d am: 9539d236e7
am: eb211c23d5

Change-Id: I0b4d324af3a1d7dad4648a9d0ffe0d8c44bee6a9
2017-09-09 20:03:39 +00:00
Dan Willemsen
eb211c23d5 Merge changes Ia3bcece1,Icd26dc1e am: ec462238f6 am: c201a6bb7d
am: 9539d236e7

Change-Id: I2a5c73a54004c1aa378d25776de0d2080544137d
2017-09-09 19:54:02 +00:00
Dan Willemsen
fa5923157f Rename aapt_defaults to aapt2_defaults am: 7544b9cbb9 am: 6737dc9448
am: 0b4a0272c7

Change-Id: Idf3f767e2a978a752b68e22114c2371f29eb1ce7
2017-09-09 19:42:52 +00:00
Dan Willemsen
0b4a0272c7 Rename aapt_defaults to aapt2_defaults am: 7544b9cbb9
am: 6737dc9448

Change-Id: I78debad7c68e37bd935b881ad791a771c8ee86c7
2017-09-09 19:33:53 +00:00
Dan Willemsen
c201a6bb7d Merge changes Ia3bcece1,Icd26dc1e
am: ec462238f6

Change-Id: Ied36c517ed7fa80dc85b07b1532821dc93628d40
2017-09-09 19:28:33 +00:00
Dan Willemsen
7544b9cbb9 Rename aapt_defaults to aapt2_defaults
So that tools/aapt/Android.bp can have aapt_defaults.

Test: m aapt2
Change-Id: I32e438efb3516d73b347e67297aa09bee91520b1
2017-09-08 23:11:49 -07:00
Dan Willemsen
85aee73e98 aapt: Always use our libz
Instead of using the system libz (-lz), include our copy as a static
library. This is safer in case the system version isn't compatible.

Also removes references to -ldl -lrt -lpthread, which are now implied.

Test: m -j
Test: out/host/linux-x86/nativetest64/libaapt_tests/libaapt_tests
Test: out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
Test: out/host/linux-x86/nativetest64/libsplit-select_tests/libsplit-select_tests
Change-Id: Icd26dc1e0d011e5b5f158e562640533c5ac34e33
2017-09-08 22:44:19 -07:00
Adam Lesinski
4ffea04064 AAPT2: Define intermediate compiled XML proto
This proto format is meant to encapsulate more information
that is specific to Android and allows for easier validation
and manipulation across tools.

Test: make aapt2_tests
Change-Id: I13bc34a460671fc0a36246be0d287a3d37d244d6
2017-08-23 11:54:38 -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
Adam Lesinski
efeb7af13b AAPT2: Fix windows unicode path issues
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
2017-08-03 17:33:52 -07:00
Adam Lesinski
66ea840038 AAPT2: Accept Java unicode identifiers
Test: make aapt2_tests
Change-Id: I75a0e52d43b1785001bfe120eea7484f7bb4682b
2017-07-07 13:23:55 -07:00
Adam Lesinski
549e437e14 AAPT2: Iterate over UTF-8 string by codepoints
Iterating over a UTF-8 string by codepoints ensures that
unicode characters do not get sliced. Otherwise the resulting
string could contain malformed characters.

Bug: 62839202
Test: make aapt2_tests
Change-Id: Ia0c44fbceb7dcfa11e77a1a77011da0f5466e342
2017-06-29 18:17:35 -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
90919978e7 DO NOT MERGE: AAPT2: Allow undefined resources (placeholders)
A resource defined like so:

<item type="drawable" name="foo" />

should be assigned the value @null.

The only exception is for <string> resources, which are given the
empty string value (since <string></string> is ambiguous). The decision
to use "" is based off the fact that old AAPT used to assign "" to all
undefined resources, even non-string ones.

Bug: 38425050
Test: make aapt2_tests
Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
2017-06-02 16:51:59 -07:00
Adam Lesinski
bab4ef56d7 AAPT2: Allow undefined resources (placeholders)
A resource defined like so:

<item type="drawable" name="foo" />

should be assigned the value @null.

The only exception is for <string> resources, which are given the
empty string value (since <string></string> is ambiguous). The decision
to use "" is based off the fact that old AAPT used to assign "" to all
undefined resources, even non-string ones.

Bug: 38425050
Test: make aapt2_tests
Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
2017-06-02 16:48:38 -07:00
Shane Farmer
74cdea34cd AAPT2: XML configuration file parser.
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
2017-05-31 16:18:31 -07:00